changeset 15:e3e4f7a92f8b

Re #31: Break out Translations for language to own class * Add tests for translation sets Re #30: Improve Translations API * Add more tests
author IBBoard <dev@ibboard.co.uk>
date Tue, 06 Apr 2010 15:43:08 +0000
parents 15cf2fe2a627
children c21d27a9cae5
files IBBoard.Tests.csproj Lang/AbstractTranslationSetTest.cs Lang/ModifiableTranslationSetTest.cs Lang/TranslationTest.cs
diffstat 4 files changed, 77 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/IBBoard.Tests.csproj	Tue Apr 06 14:40:35 2010 +0000
     1.2 +++ b/IBBoard.Tests.csproj	Tue Apr 06 15:43:08 2010 +0000
     1.3 @@ -38,6 +38,8 @@
     1.4      <Compile Include="EnumToolsTests.cs" />
     1.5      <Compile Include="Lang\TranslationTest.cs" />
     1.6      <Compile Include="Lang\Mock\MockTranslatable.cs" />
     1.7 +    <Compile Include="Lang\AbstractTranslationSetTest.cs" />
     1.8 +    <Compile Include="Lang\ModifiableTranslationSetTest.cs" />
     1.9    </ItemGroup>
    1.10    <ItemGroup>
    1.11      <Reference Include="System" />
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Lang/AbstractTranslationSetTest.cs	Tue Apr 06 15:43:08 2010 +0000
     2.3 @@ -0,0 +1,32 @@
     2.4 +// This file (TranslationSetTest.cs) is a part of the IBBoard.Tests project and is copyright 2010 IBBoard
     2.5 +// 
     2.6 +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
     2.7 +
     2.8 +using System;
     2.9 +using NUnit.Framework;
    2.10 +
    2.11 +namespace IBBoard.Lang
    2.12 +{
    2.13 +	public abstract class AbstractTranslationSetTest
    2.14 +	{
    2.15 +		
    2.16 +		[Test()]
    2.17 +		public void TestTranslationSetReturnForMissingValue()
    2.18 +		{
    2.19 +			AbstractTranslationSet translations = GetTranslationSet();
    2.20 +			Assert.IsNull(translations["missing"]);
    2.21 +		}
    2.22 +		
    2.23 +		[Test()]
    2.24 +		public void TestTranslationSetSettingAndRetrieval()
    2.25 +		{
    2.26 +			AbstractTranslationSet translations = GetTranslationSetWithFixedValue();
    2.27 +			Assert.AreEqual(GetFixedValueTranslation(), translations[GetFixedValueKey()]);
    2.28 +		}
    2.29 +		
    2.30 +		protected abstract AbstractTranslationSet GetTranslationSet();
    2.31 +		protected abstract AbstractTranslationSet GetTranslationSetWithFixedValue();
    2.32 +		protected abstract string GetFixedValueKey();
    2.33 +		protected abstract string GetFixedValueTranslation();
    2.34 +	}
    2.35 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/Lang/ModifiableTranslationSetTest.cs	Tue Apr 06 15:43:08 2010 +0000
     3.3 @@ -0,0 +1,37 @@
     3.4 +// This file (ModifiableTranslationSetTest.cs) is a part of the IBBoard.Tests project and is copyright 2010 IBBoard
     3.5 +// 
     3.6 +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
     3.7 +
     3.8 +using System;
     3.9 +using NUnit.Framework;
    3.10 +
    3.11 +namespace IBBoard.Lang
    3.12 +{
    3.13 +	[TestFixture()]
    3.14 +	public class ModifiableTranslationSetTest : AbstractTranslationSetTest
    3.15 +	{
    3.16 +		private const string TEST_ID = "testString";
    3.17 +		
    3.18 +		protected override string GetFixedValueKey()
    3.19 +		{
    3.20 +			return TEST_ID;
    3.21 +		}
    3.22 +		
    3.23 +		protected override string GetFixedValueTranslation()
    3.24 +		{
    3.25 +			return "new string";
    3.26 +		}
    3.27 +		
    3.28 +		protected override AbstractTranslationSet GetTranslationSet()
    3.29 +		{
    3.30 +			return new ModifiableTranslationSet("en");
    3.31 +		}
    3.32 +		
    3.33 +		protected override AbstractTranslationSet GetTranslationSetWithFixedValue()
    3.34 +		{
    3.35 +			ModifiableTranslationSet translations = new ModifiableTranslationSet("en");
    3.36 +			translations[GetFixedValueKey()] = GetFixedValueTranslation();
    3.37 +			return translations;
    3.38 +		}
    3.39 +	}
    3.40 +}
     4.1 --- a/Lang/TranslationTest.cs	Tue Apr 06 14:40:35 2010 +0000
     4.2 +++ b/Lang/TranslationTest.cs	Tue Apr 06 15:43:08 2010 +0000
     4.3 @@ -64,5 +64,11 @@
     4.4  			Translation.Translate(translatable);
     4.5  			Assert.AreEqual("Test String", translatable.Text);
     4.6  		}
     4.7 +		
     4.8 +		[Test()]
     4.9 +		public void TestResetDoesNotCauseErrors()
    4.10 +		{
    4.11 +			Assert.AreEqual("++ Missing Translation missingID ++", Translation.GetTranslation("missingID"));
    4.12 +		}
    4.13  	}
    4.14  }