Mercurial > repos > IBBoard.Tests
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 wrap: on
line diff
--- a/IBBoard.Tests.csproj Fri Apr 09 15:12:47 2010 +0000 +++ b/IBBoard.Tests.csproj Fri Apr 09 19:35:35 2010 +0000 @@ -42,6 +42,7 @@ <Compile Include="Lang\ModifiableTranslationSetTest.cs" /> <Compile Include="Lang\TranslationXmlLoaderTest.cs" /> <Compile Include="Lang\TranslationLanguageTest.cs" /> + <Compile Include="Lang\XmlTranslationSet.cs" /> </ItemGroup> <ItemGroup> <Reference Include="System" />
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lang/XmlTranslationSetTest.cs Fri Apr 09 19:35:35 2010 +0000 @@ -0,0 +1,66 @@ +// This file (XmlTranslationSet.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 System.Xml; +using NUnit.Framework; + +namespace IBBoard.Lang +{ + [TestFixture()] + public class XmlTranslationSetTest : AbstractTranslationSetTest + { + protected override AbstractTranslationSet GetTranslationSet(string language) + { + return new XmlTranslationSet(language); + } + + protected override AbstractTranslationSet GetTranslationSetWithFixedValue() + { + XmlTranslationSet translationSet = new XmlTranslationSet("en"); + XmlDocument doc = new XmlDocument(); + 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>"); + translationSet.SetSourceXml(doc); + return translationSet; + } + + protected override AbstractTranslationSet GetTranslationSetWithInheritance(string language, string parentLanguage) + { + XmlTranslationSet translationSet = new XmlTranslationSet(language); + XmlDocument doc = new XmlDocument(); + 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>"); + translationSet.SetSourceXml(doc); + translationSet.SetParentLanguage(parentLanguage); + ModifiableTranslationSet parentTranslationSet = new ModifiableTranslationSet(parentLanguage); + parentTranslationSet.SetTranslation(INHERITED_KEY, INHERITED_VALUE); + Translation.AddTranslationSet(parentTranslationSet); + return translationSet; + } + + protected override AbstractTranslationSet GetTranslationSetWithDirectLoop() + { + XmlTranslationSet translations = new XmlTranslationSet("en-US"); + XmlTranslationSet parentTranslations = new XmlTranslationSet("en"); + translations.SetParentLanguage("en"); + parentTranslations.SetParentLanguage("en-US"); + Translation.AddTranslationSet(translations); + Translation.AddTranslationSet(parentTranslations); + return translations; + } + + protected override AbstractTranslationSet GetTranslationSetWithIndirectLoop() + { + XmlTranslationSet translations = new XmlTranslationSet("it"); + XmlTranslationSet parentTranslations = new XmlTranslationSet("en-US"); + XmlTranslationSet parentParentTranslations = new XmlTranslationSet("en"); + translations.SetParentLanguage("en-US"); + parentTranslations.SetParentLanguage("en"); + parentParentTranslations.SetParentLanguage("it"); + Translation.AddTranslationSet(translations); + Translation.AddTranslationSet(parentTranslations); + Translation.AddTranslationSet(parentParentTranslations); + return translations; + } + } +}