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 wrap: on
line diff
--- a/IBBoard.Tests.csproj	Tue Apr 06 14:40:35 2010 +0000
+++ b/IBBoard.Tests.csproj	Tue Apr 06 15:43:08 2010 +0000
@@ -38,6 +38,8 @@
     <Compile Include="EnumToolsTests.cs" />
     <Compile Include="Lang\TranslationTest.cs" />
     <Compile Include="Lang\Mock\MockTranslatable.cs" />
+    <Compile Include="Lang\AbstractTranslationSetTest.cs" />
+    <Compile Include="Lang\ModifiableTranslationSetTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lang/AbstractTranslationSetTest.cs	Tue Apr 06 15:43:08 2010 +0000
@@ -0,0 +1,32 @@
+// This file (TranslationSetTest.cs) is a part of the IBBoard.Tests project and is copyright 2010 IBBoard
+// 
+// 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.
+
+using System;
+using NUnit.Framework;
+
+namespace IBBoard.Lang
+{
+	public abstract class AbstractTranslationSetTest
+	{
+		
+		[Test()]
+		public void TestTranslationSetReturnForMissingValue()
+		{
+			AbstractTranslationSet translations = GetTranslationSet();
+			Assert.IsNull(translations["missing"]);
+		}
+		
+		[Test()]
+		public void TestTranslationSetSettingAndRetrieval()
+		{
+			AbstractTranslationSet translations = GetTranslationSetWithFixedValue();
+			Assert.AreEqual(GetFixedValueTranslation(), translations[GetFixedValueKey()]);
+		}
+		
+		protected abstract AbstractTranslationSet GetTranslationSet();
+		protected abstract AbstractTranslationSet GetTranslationSetWithFixedValue();
+		protected abstract string GetFixedValueKey();
+		protected abstract string GetFixedValueTranslation();
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lang/ModifiableTranslationSetTest.cs	Tue Apr 06 15:43:08 2010 +0000
@@ -0,0 +1,37 @@
+// This file (ModifiableTranslationSetTest.cs) is a part of the IBBoard.Tests project and is copyright 2010 IBBoard
+// 
+// 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.
+
+using System;
+using NUnit.Framework;
+
+namespace IBBoard.Lang
+{
+	[TestFixture()]
+	public class ModifiableTranslationSetTest : AbstractTranslationSetTest
+	{
+		private const string TEST_ID = "testString";
+		
+		protected override string GetFixedValueKey()
+		{
+			return TEST_ID;
+		}
+		
+		protected override string GetFixedValueTranslation()
+		{
+			return "new string";
+		}
+		
+		protected override AbstractTranslationSet GetTranslationSet()
+		{
+			return new ModifiableTranslationSet("en");
+		}
+		
+		protected override AbstractTranslationSet GetTranslationSetWithFixedValue()
+		{
+			ModifiableTranslationSet translations = new ModifiableTranslationSet("en");
+			translations[GetFixedValueKey()] = GetFixedValueTranslation();
+			return translations;
+		}
+	}
+}
--- a/Lang/TranslationTest.cs	Tue Apr 06 14:40:35 2010 +0000
+++ b/Lang/TranslationTest.cs	Tue Apr 06 15:43:08 2010 +0000
@@ -64,5 +64,11 @@
 			Translation.Translate(translatable);
 			Assert.AreEqual("Test String", translatable.Text);
 		}
+		
+		[Test()]
+		public void TestResetDoesNotCauseErrors()
+		{
+			Assert.AreEqual("++ Missing Translation missingID ++", Translation.GetTranslation("missingID"));
+		}
 	}
 }