changeset 24:948317c89fad

Re #32: Add staged loading of translations * Separate out test data by purpose * Add test of loading inherited XML
author IBBoard <dev@ibboard.co.uk>
date Fri, 09 Apr 2010 19:51:50 +0000
parents acf828df8c0b
children 8a350c00797e
files IBBoard.Tests.csproj Lang/TranslationTest.cs Lang/TranslationXmlLoaderTest.cs test-data/TranslationTests/schemas/translation.xsd test-data/TranslationTests/translations/en.translation test-data/TranslationTests/translations/it.translation test-data/XmlLoaderTests/translations/en-GB.translation test-data/XmlLoaderTests/translations/en.translation test-data/schemas/translation.xsd test-data/translations/en.translation test-data/translations/it.translation
diffstat 11 files changed, 69 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/IBBoard.Tests.csproj	Fri Apr 09 19:35:35 2010 +0000
+++ b/IBBoard.Tests.csproj	Fri Apr 09 19:51:50 2010 +0000
@@ -42,7 +42,7 @@
     <Compile Include="Lang\ModifiableTranslationSetTest.cs" />
     <Compile Include="Lang\TranslationXmlLoaderTest.cs" />
     <Compile Include="Lang\TranslationLanguageTest.cs" />
-    <Compile Include="Lang\XmlTranslationSet.cs" />
+    <Compile Include="Lang\XmlTranslationSetTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
@@ -57,9 +57,10 @@
     <Folder Include="Xml\" />
     <Folder Include="Lang\" />
     <Folder Include="test-data\" />
-    <Folder Include="test-data\translations\" />
-    <Folder Include="test-data\schemas\" />
     <Folder Include="Lang\Mock\" />
+    <Folder Include="test-data\TranslationTests\" />
+    <Folder Include="test-data\XmlLoaderTests\" />
+    <Folder Include="test-data\XmlLoaderTests\translations\" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\IBBoard\IBBoard.csproj">
@@ -77,15 +78,27 @@
     </MonoDevelop>
   </ProjectExtensions>
   <ItemGroup>
-    <None Include="test-data\translations\en.translation">
+    <None Include="test-data\TranslationTests\schemas\translation.xsd">
+      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="test-data\TranslationTests\translations\en.translation">
       <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
-    <None Include="test-data\translations\it.translation">
+    <None Include="test-data\TranslationTests\translations\it.translation">
       <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
-    <None Include="test-data\schemas\translation.xsd">
+    <None Include="test-data\XmlLoaderTests\translations\en.translation">
+      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="test-data\XmlLoaderTests\schemas\translation.xsd">
+      <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="test-data\XmlLoaderTests\translations\en-GB.translation">
       <Gettext-ScanForTranslations>false</Gettext-ScanForTranslations>
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
--- a/Lang/TranslationTest.cs	Fri Apr 09 19:35:35 2010 +0000
+++ b/Lang/TranslationTest.cs	Fri Apr 09 19:51:50 2010 +0000
@@ -12,7 +12,7 @@
 	public class TranslationTest
 	{
 		private const string TEST_ID = "testString";
-		private const string TEST_DATA_PATH = "test-data";
+		private const string TEST_DATA_PATH = "test-data/TranslationTests";
 		
 		[SetUp()]
 		public void Setup()
--- a/Lang/TranslationXmlLoaderTest.cs	Fri Apr 09 19:35:35 2010 +0000
+++ b/Lang/TranslationXmlLoaderTest.cs	Fri Apr 09 19:51:50 2010 +0000
@@ -13,10 +13,22 @@
 		[Test()]
 		public void TestLoadOfSimpleXml()
 		{
-			TranslationXmlLoader loader = new TranslationXmlLoader("test-data/schemas/translation.xsd");
-			AbstractTranslationSet translations = loader.LoadTranslations("test-data/translations/en.translation");
+			TranslationXmlLoader loader = new TranslationXmlLoader("test-data/XmlLoaderTests/schemas/translation.xsd");
+			AbstractTranslationSet translations = loader.LoadTranslations("test-data/XmlLoaderTests/translations/en.translation");
 			Assert.AreEqual("en", translations.LanguageCode);
 			Assert.AreEqual("Test String", translations["testString"]);			
 		}
+		
+		[Test()]
+		public void TestLoadOfInheritingXml()
+		{
+			ModifiableTranslationSet parentTranslations = new ModifiableTranslationSet("en");
+			Translation.AddTranslationSet(parentTranslations);
+			TranslationXmlLoader loader = new TranslationXmlLoader("test-data/XmlLoaderTests/schemas/translation.xsd");
+			AbstractTranslationSet translations = loader.LoadTranslations("test-data/XmlLoaderTests/translations/en-GB.translation");
+			Assert.AreEqual("en-GB", translations.LanguageCode);
+			Assert.AreEqual("British Test String", translations["testString"]);
+			Assert.AreEqual(parentTranslations.Language, translations.ParentLanguage);
+		}
 	}
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/TranslationTests/schemas/translation.xsd	Fri Apr 09 19:51:50 2010 +0000
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ibboard.co.uk/translation" xmlns="http://ibboard.co.uk/translation" elementFormDefault="qualified">
+<xs:complexType name="translationtype">
+    <xs:simpleContent>
+      <xs:extension base="xs:string">
+        <xs:attribute name="id" type="xs:ID" />
+      </xs:extension>
+    </xs:simpleContent>
+</xs:complexType>
+<xs:element name="translations">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element name="translation" minOccurs="0" maxOccurs="unbounded" type="translationtype"/>
+    </xs:sequence>
+    <xs:attribute name="lang" type="xs:string" use="required"/>
+    <xs:attribute name="extends" type="xs:string" default=""/>
+  </xs:complexType>
+</xs:element>
+</xs:schema>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/TranslationTests/translations/en.translation	Fri Apr 09 19:51:50 2010 +0000
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<translations xmlns="http://ibboard.co.uk/translation" lang="en">
+	<translation id="testString">Test String</translation>
+</translations>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/TranslationTests/translations/it.translation	Fri Apr 09 19:51:50 2010 +0000
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<translations xmlns="http://ibboard.co.uk/translation" lang="it">
+	<translation id="testString">Fakius Romanius</translation>
+</translations>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/XmlLoaderTests/translations/en-GB.translation	Fri Apr 09 19:51:50 2010 +0000
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<translations xmlns="http://ibboard.co.uk/translation" lang="en-GB" extends="en">
+	<translation id="testString">British Test String</translation>
+</translations>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/XmlLoaderTests/translations/en.translation	Fri Apr 09 19:51:50 2010 +0000
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<translations xmlns="http://ibboard.co.uk/translation" lang="en">
+	<translation id="testString">Test String</translation>
+</translations>
\ No newline at end of file
--- a/test-data/schemas/translation.xsd	Fri Apr 09 19:35:35 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-<?xml version="1.0"?>
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ibboard.co.uk/translation" xmlns="http://ibboard.co.uk/translation" elementFormDefault="qualified">
-<xs:complexType name="translationtype">
-    <xs:simpleContent>
-      <xs:extension base="xs:string">
-        <xs:attribute name="id" type="xs:ID" />
-      </xs:extension>
-    </xs:simpleContent>
-</xs:complexType>
-<xs:element name="translations">
-  <xs:complexType>
-    <xs:sequence>
-      <xs:element name="translation" minOccurs="0" maxOccurs="unbounded" type="translationtype"/>
-    </xs:sequence>
-    <xs:attribute name="lang" type="xs:string" use="required"/>
-  </xs:complexType>
-</xs:element>
-</xs:schema>
\ No newline at end of file
--- a/test-data/translations/en.translation	Fri Apr 09 19:35:35 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<translations xmlns="http://ibboard.co.uk/translation" lang="en">
-	<translation id="testString">Test String</translation>
-</translations>
\ No newline at end of file
--- a/test-data/translations/it.translation	Fri Apr 09 19:35:35 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<translations xmlns="http://ibboard.co.uk/translation" lang="it">
-	<translation id="testString">Fakius Romanius</translation>
-</translations>
\ No newline at end of file