changeset 20:b3bc581a8433

Fixes #37: Add event to indicate change of translation * Add tests for new event Also: * Fix copy-and-paste errors in translation language tests that previous builds didn't complain about
author IBBoard <dev@ibboard.co.uk>
date Wed, 07 Apr 2010 14:57:28 +0000
parents bcb6e83752a6
children 2834da2b8891
files Lang/TranslationLanguageTest.cs Lang/TranslationTest.cs
diffstat 2 files changed, 49 insertions(+), 4 deletions(-) [+]
line diff
     1.1 --- a/Lang/TranslationLanguageTest.cs	Tue Apr 06 19:03:57 2010 +0000
     1.2 +++ b/Lang/TranslationLanguageTest.cs	Wed Apr 07 14:57:28 2010 +0000
     1.3 @@ -13,12 +13,12 @@
     1.4  		[Test()]
     1.5  		public void TestTranslationSetName()
     1.6  		{
     1.7 -			AbstractTranslationSet translationLang = new TranslationLanguage("en");
     1.8 -			Assert.AreEqual("English", translationLang.LanguageName);
     1.9 +			TranslationLanguage translationLang = new TranslationLanguage("en");
    1.10 +			Assert.AreEqual("English", translationLang.Name);
    1.11  			translationLang = new TranslationLanguage("it");
    1.12 -			Assert.AreEqual("italiano", translationLang.LanguageName);
    1.13 +			Assert.AreEqual("italiano", translationLang.Name);
    1.14  			translationLang = new TranslationLanguage("zz");
    1.15 -			Assert.AreEqual("Unknown (zz)", translationLang.LanguageName);
    1.16 +			Assert.AreEqual("Unknown (zz)", translationLang.Name);
    1.17  		}
    1.18  		
    1.19  		[Test()]
     2.1 --- a/Lang/TranslationTest.cs	Tue Apr 06 19:03:57 2010 +0000
     2.2 +++ b/Lang/TranslationTest.cs	Wed Apr 07 14:57:28 2010 +0000
     2.3 @@ -79,5 +79,50 @@
     2.4  			Assert.That(Translation.GetLanguages().Contains(new TranslationLanguage("en")));
     2.5  			Assert.That(Translation.GetLanguages().Contains(new TranslationLanguage("it")));
     2.6  		}
     2.7 +		
     2.8 +		[Test()]
     2.9 +		public void TestTranslationChangedEventFiresOnChange()
    2.10 +		{
    2.11 +			Translation.InitialiseTranslations(TEST_DATA_PATH);
    2.12 +			MethodFireObject obj = new MethodFireObject();
    2.13 +			Translation.TranslationChanged+= obj.Method;
    2.14 +			Translation.LoadTranslation("en");
    2.15 +			Assert.IsTrue(obj.methodFired);
    2.16 +			obj.methodFired = false;
    2.17 +			Translation.LoadTranslation("it");
    2.18 +			Assert.IsTrue(obj.methodFired);
    2.19 +		}
    2.20 +		
    2.21 +		[Test()]
    2.22 +		public void TestTranslationChangedEventNotFiredOnChangeToSameValue()
    2.23 +		{
    2.24 +			Translation.InitialiseTranslations(TEST_DATA_PATH);
    2.25 +			Translation.LoadTranslation("en");
    2.26 +			MethodFireObject obj = new MethodFireObject();
    2.27 +			Translation.TranslationChanged+= obj.Method;
    2.28 +			Translation.LoadTranslation("en");
    2.29 +			Assert.IsFalse(obj.methodFired);
    2.30 +		}
    2.31 +		
    2.32 +		[Test()]
    2.33 +		public void TestTranslationChangedEventFiredOnReset()
    2.34 +		{
    2.35 +			Translation.InitialiseTranslations(TEST_DATA_PATH);
    2.36 +			Translation.LoadTranslation("en");
    2.37 +			MethodFireObject obj = new MethodFireObject();
    2.38 +			Translation.TranslationChanged+= obj.Method;
    2.39 +			Translation.Reset();
    2.40 +			Assert.IsTrue(obj.methodFired);
    2.41 +		}
    2.42 +		
    2.43 +		private class MethodFireObject
    2.44 +		{
    2.45 +			public bool methodFired = false;
    2.46 +			
    2.47 +			public void Method()
    2.48 +			{
    2.49 +				methodFired = true;
    2.50 +			}
    2.51 +		}
    2.52  	}
    2.53  }