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 diff
     1.1 --- a/Lang/AbstractTranslationSetTest.cs	Wed Apr 07 19:36:08 2010 +0000
     1.2 +++ b/Lang/AbstractTranslationSetTest.cs	Fri Apr 09 15:12:47 2010 +0000
     1.3 @@ -49,6 +49,25 @@
     1.4  		}
     1.5  		
     1.6  		[Test()]
     1.7 +		[ExpectedException(typeof(TranslationLoadException), ExpectedMessage = "Translations contained an inheritence loop")]
     1.8 +		public void TestTranslationsThrowExceptionWithDirectLoop()
     1.9 +		{
    1.10 +			AbstractTranslationSet loopTranslations = GetTranslationSetWithDirectLoop();
    1.11 +			String trans = loopTranslations["missing"];
    1.12 +			Assert.Fail("Exception not thrown: " + trans);
    1.13 +		}
    1.14 +		
    1.15 +		[Test()]
    1.16 +		[ExpectedException(typeof(TranslationLoadException), ExpectedMessage = "Translations contained an inheritence loop")]
    1.17 +		public void TestTranslationsThrowExceptionWithIndirectLoop()
    1.18 +		{
    1.19 +			AbstractTranslationSet loopTranslations = GetTranslationSetWithIndirectLoop();
    1.20 +			String trans = loopTranslations["missing"];
    1.21 +			Assert.Fail("Exception not thrown: " + trans);
    1.22 +		}
    1.23 +			
    1.24 +		
    1.25 +		[Test()]
    1.26  		public void TestEquality()
    1.27  		{
    1.28  			Assert.AreEqual(GetTranslationSet("en"), GetTranslationSet("en"));
    1.29 @@ -69,5 +88,7 @@
    1.30  		protected abstract AbstractTranslationSet GetTranslationSet(string language);		
    1.31  		protected abstract AbstractTranslationSet GetTranslationSetWithInheritance(string language, string parentLanguage);
    1.32  		protected abstract AbstractTranslationSet GetTranslationSetWithFixedValue();
    1.33 +		protected abstract AbstractTranslationSet GetTranslationSetWithDirectLoop();
    1.34 +		protected abstract AbstractTranslationSet GetTranslationSetWithIndirectLoop();
    1.35  	}
    1.36  }
     2.1 --- a/Lang/ModifiableTranslationSetTest.cs	Wed Apr 07 19:36:08 2010 +0000
     2.2 +++ b/Lang/ModifiableTranslationSetTest.cs	Fri Apr 09 15:12:47 2010 +0000
     2.3 @@ -26,10 +26,30 @@
     2.4  		}
     2.5  		
     2.6  		protected override AbstractTranslationSet GetTranslationSetWithFixedValue()
     2.7 -		{			
     2.8 +		{
     2.9  			ModifiableTranslationSet translations = new ModifiableTranslationSet("en");
    2.10  			translations.SetTranslation(TEST_KEY, TEST_VALUE);
    2.11  			return translations;
    2.12  		}
    2.13 +		
    2.14 +		protected override AbstractTranslationSet GetTranslationSetWithDirectLoop()
    2.15 +		{
    2.16 +			ModifiableTranslationSet translations = new ModifiableTranslationSet("en-US");
    2.17 +			ModifiableTranslationSet parentTranslations = new ModifiableTranslationSet("en");
    2.18 +			translations.SetParentTranslations(parentTranslations);
    2.19 +			parentTranslations.SetParentTranslations(translations);
    2.20 +			return translations;
    2.21 +		}
    2.22 +		
    2.23 +		protected override AbstractTranslationSet GetTranslationSetWithIndirectLoop()
    2.24 +		{
    2.25 +			ModifiableTranslationSet translations = new ModifiableTranslationSet("it");
    2.26 +			ModifiableTranslationSet parentTranslations = new ModifiableTranslationSet("en-US");
    2.27 +			ModifiableTranslationSet parentParentTranslations = new ModifiableTranslationSet("en");
    2.28 +			translations.SetParentTranslations(parentTranslations);
    2.29 +			parentTranslations.SetParentTranslations(parentParentTranslations);
    2.30 +			parentParentTranslations.SetParentTranslations(translations);
    2.31 +			return translations;
    2.32 +		}
    2.33  	}
    2.34  }