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 wrap: on
line diff
--- a/Lang/TranslationLanguageTest.cs	Tue Apr 06 19:03:57 2010 +0000
+++ b/Lang/TranslationLanguageTest.cs	Wed Apr 07 14:57:28 2010 +0000
@@ -13,12 +13,12 @@
 		[Test()]
 		public void TestTranslationSetName()
 		{
-			AbstractTranslationSet translationLang = new TranslationLanguage("en");
-			Assert.AreEqual("English", translationLang.LanguageName);
+			TranslationLanguage translationLang = new TranslationLanguage("en");
+			Assert.AreEqual("English", translationLang.Name);
 			translationLang = new TranslationLanguage("it");
-			Assert.AreEqual("italiano", translationLang.LanguageName);
+			Assert.AreEqual("italiano", translationLang.Name);
 			translationLang = new TranslationLanguage("zz");
-			Assert.AreEqual("Unknown (zz)", translationLang.LanguageName);
+			Assert.AreEqual("Unknown (zz)", translationLang.Name);
 		}
 		
 		[Test()]
--- a/Lang/TranslationTest.cs	Tue Apr 06 19:03:57 2010 +0000
+++ b/Lang/TranslationTest.cs	Wed Apr 07 14:57:28 2010 +0000
@@ -79,5 +79,50 @@
 			Assert.That(Translation.GetLanguages().Contains(new TranslationLanguage("en")));
 			Assert.That(Translation.GetLanguages().Contains(new TranslationLanguage("it")));
 		}
+		
+		[Test()]
+		public void TestTranslationChangedEventFiresOnChange()
+		{
+			Translation.InitialiseTranslations(TEST_DATA_PATH);
+			MethodFireObject obj = new MethodFireObject();
+			Translation.TranslationChanged+= obj.Method;
+			Translation.LoadTranslation("en");
+			Assert.IsTrue(obj.methodFired);
+			obj.methodFired = false;
+			Translation.LoadTranslation("it");
+			Assert.IsTrue(obj.methodFired);
+		}
+		
+		[Test()]
+		public void TestTranslationChangedEventNotFiredOnChangeToSameValue()
+		{
+			Translation.InitialiseTranslations(TEST_DATA_PATH);
+			Translation.LoadTranslation("en");
+			MethodFireObject obj = new MethodFireObject();
+			Translation.TranslationChanged+= obj.Method;
+			Translation.LoadTranslation("en");
+			Assert.IsFalse(obj.methodFired);
+		}
+		
+		[Test()]
+		public void TestTranslationChangedEventFiredOnReset()
+		{
+			Translation.InitialiseTranslations(TEST_DATA_PATH);
+			Translation.LoadTranslation("en");
+			MethodFireObject obj = new MethodFireObject();
+			Translation.TranslationChanged+= obj.Method;
+			Translation.Reset();
+			Assert.IsTrue(obj.methodFired);
+		}
+		
+		private class MethodFireObject
+		{
+			public bool methodFired = false;
+			
+			public void Method()
+			{
+				methodFired = true;
+			}
+		}
 	}
 }