changeset 23:acf828df8c0b

Re #32: Add staged loading of translations * Add tests for new XML translation set
author IBBoard <dev@ibboard.co.uk>
date Fri, 09 Apr 2010 19:35:35 +0000
parents e9bad86c1360
children 948317c89fad
files IBBoard.Tests.csproj Lang/XmlTranslationSetTest.cs
diffstat 2 files changed, 67 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/IBBoard.Tests.csproj	Fri Apr 09 15:12:47 2010 +0000
     1.2 +++ b/IBBoard.Tests.csproj	Fri Apr 09 19:35:35 2010 +0000
     1.3 @@ -42,6 +42,7 @@
     1.4      <Compile Include="Lang\ModifiableTranslationSetTest.cs" />
     1.5      <Compile Include="Lang\TranslationXmlLoaderTest.cs" />
     1.6      <Compile Include="Lang\TranslationLanguageTest.cs" />
     1.7 +    <Compile Include="Lang\XmlTranslationSet.cs" />
     1.8    </ItemGroup>
     1.9    <ItemGroup>
    1.10      <Reference Include="System" />
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Lang/XmlTranslationSetTest.cs	Fri Apr 09 19:35:35 2010 +0000
     2.3 @@ -0,0 +1,66 @@
     2.4 +//  This file (XmlTranslationSet.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 System.Xml;
    2.10 +using NUnit.Framework;
    2.11 +
    2.12 +namespace IBBoard.Lang
    2.13 +{
    2.14 +	[TestFixture()]
    2.15 +	public class XmlTranslationSetTest : AbstractTranslationSetTest
    2.16 +	{
    2.17 +		protected override AbstractTranslationSet GetTranslationSet(string language)
    2.18 +		{
    2.19 +			return new XmlTranslationSet(language);
    2.20 +		}
    2.21 +		
    2.22 +		protected override AbstractTranslationSet GetTranslationSetWithFixedValue()
    2.23 +		{
    2.24 +			XmlTranslationSet translationSet = new XmlTranslationSet("en");
    2.25 +			XmlDocument doc = new XmlDocument();
    2.26 +			doc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><translations xmlns=\"http://ibboard.co.uk/translation\" lang=\"en\"><translation id=\""+TEST_KEY+"\">"+TEST_VALUE+"</translation></translations>");
    2.27 +			translationSet.SetSourceXml(doc);
    2.28 +			return translationSet;
    2.29 +		}
    2.30 +
    2.31 +		protected override AbstractTranslationSet GetTranslationSetWithInheritance(string language, string parentLanguage)
    2.32 +		{
    2.33 +			XmlTranslationSet translationSet = new XmlTranslationSet(language);
    2.34 +			XmlDocument doc = new XmlDocument();
    2.35 +			doc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><translations xmlns=\"http://ibboard.co.uk/translation\" lang=\""+language+"\" extends=\""+parentLanguage+"\"><translation id=\""+TEST_KEY+"\">"+TEST_VALUE+"</translation></translations>");
    2.36 +			translationSet.SetSourceXml(doc);
    2.37 +			translationSet.SetParentLanguage(parentLanguage);
    2.38 +			ModifiableTranslationSet parentTranslationSet = new ModifiableTranslationSet(parentLanguage);
    2.39 +			parentTranslationSet.SetTranslation(INHERITED_KEY, INHERITED_VALUE);
    2.40 +			Translation.AddTranslationSet(parentTranslationSet);
    2.41 +			return translationSet;
    2.42 +		}
    2.43 +		
    2.44 +		protected override AbstractTranslationSet GetTranslationSetWithDirectLoop()
    2.45 +		{
    2.46 +			XmlTranslationSet translations = new XmlTranslationSet("en-US");
    2.47 +			XmlTranslationSet parentTranslations = new XmlTranslationSet("en");
    2.48 +			translations.SetParentLanguage("en");
    2.49 +			parentTranslations.SetParentLanguage("en-US");
    2.50 +			Translation.AddTranslationSet(translations);
    2.51 +			Translation.AddTranslationSet(parentTranslations);
    2.52 +			return translations;
    2.53 +		}
    2.54 +		
    2.55 +		protected override AbstractTranslationSet GetTranslationSetWithIndirectLoop()
    2.56 +		{
    2.57 +			XmlTranslationSet translations = new XmlTranslationSet("it");
    2.58 +			XmlTranslationSet parentTranslations = new XmlTranslationSet("en-US");
    2.59 +			XmlTranslationSet parentParentTranslations = new XmlTranslationSet("en");
    2.60 +			translations.SetParentLanguage("en-US");
    2.61 +			parentTranslations.SetParentLanguage("en");
    2.62 +			parentParentTranslations.SetParentLanguage("it");
    2.63 +			Translation.AddTranslationSet(translations);
    2.64 +			Translation.AddTranslationSet(parentTranslations);
    2.65 +			Translation.AddTranslationSet(parentParentTranslations);
    2.66 +			return translations;
    2.67 +		}
    2.68 +	}
    2.69 +}