changeset 22:e9bad86c1360

Fixes #35: Add multi-level cascading of translations * Add tests to check for handling of looping
author IBBoard <dev@ibboard.co.uk>
date Fri, 09 Apr 2010 15:12:47 +0000
parents 2834da2b8891
children acf828df8c0b
files Lang/AbstractTranslationSetTest.cs Lang/ModifiableTranslationSetTest.cs
diffstat 2 files changed, 42 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Lang/AbstractTranslationSetTest.cs	Wed Apr 07 19:36:08 2010 +0000
+++ b/Lang/AbstractTranslationSetTest.cs	Fri Apr 09 15:12:47 2010 +0000
@@ -49,6 +49,25 @@
 		}
 		
 		[Test()]
+		[ExpectedException(typeof(TranslationLoadException), ExpectedMessage = "Translations contained an inheritence loop")]
+		public void TestTranslationsThrowExceptionWithDirectLoop()
+		{
+			AbstractTranslationSet loopTranslations = GetTranslationSetWithDirectLoop();
+			String trans = loopTranslations["missing"];
+			Assert.Fail("Exception not thrown: " + trans);
+		}
+		
+		[Test()]
+		[ExpectedException(typeof(TranslationLoadException), ExpectedMessage = "Translations contained an inheritence loop")]
+		public void TestTranslationsThrowExceptionWithIndirectLoop()
+		{
+			AbstractTranslationSet loopTranslations = GetTranslationSetWithIndirectLoop();
+			String trans = loopTranslations["missing"];
+			Assert.Fail("Exception not thrown: " + trans);
+		}
+			
+		
+		[Test()]
 		public void TestEquality()
 		{
 			Assert.AreEqual(GetTranslationSet("en"), GetTranslationSet("en"));
@@ -69,5 +88,7 @@
 		protected abstract AbstractTranslationSet GetTranslationSet(string language);		
 		protected abstract AbstractTranslationSet GetTranslationSetWithInheritance(string language, string parentLanguage);
 		protected abstract AbstractTranslationSet GetTranslationSetWithFixedValue();
+		protected abstract AbstractTranslationSet GetTranslationSetWithDirectLoop();
+		protected abstract AbstractTranslationSet GetTranslationSetWithIndirectLoop();
 	}
 }
--- a/Lang/ModifiableTranslationSetTest.cs	Wed Apr 07 19:36:08 2010 +0000
+++ b/Lang/ModifiableTranslationSetTest.cs	Fri Apr 09 15:12:47 2010 +0000
@@ -26,10 +26,30 @@
 		}
 		
 		protected override AbstractTranslationSet GetTranslationSetWithFixedValue()
-		{			
+		{
 			ModifiableTranslationSet translations = new ModifiableTranslationSet("en");
 			translations.SetTranslation(TEST_KEY, TEST_VALUE);
 			return translations;
 		}
+		
+		protected override AbstractTranslationSet GetTranslationSetWithDirectLoop()
+		{
+			ModifiableTranslationSet translations = new ModifiableTranslationSet("en-US");
+			ModifiableTranslationSet parentTranslations = new ModifiableTranslationSet("en");
+			translations.SetParentTranslations(parentTranslations);
+			parentTranslations.SetParentTranslations(translations);
+			return translations;
+		}
+		
+		protected override AbstractTranslationSet GetTranslationSetWithIndirectLoop()
+		{
+			ModifiableTranslationSet translations = new ModifiableTranslationSet("it");
+			ModifiableTranslationSet parentTranslations = new ModifiableTranslationSet("en-US");
+			ModifiableTranslationSet parentParentTranslations = new ModifiableTranslationSet("en");
+			translations.SetParentTranslations(parentTranslations);
+			parentTranslations.SetParentTranslations(parentParentTranslations);
+			parentParentTranslations.SetParentTranslations(translations);
+			return translations;
+		}
 	}
 }