view Lang/AbstractTranslationSetTest.cs @ 45:7502653a71a0

* Update tests - we now fix Microsoft's lack of capitalisation in language names * Change to not passing schema location to TranslationXmlLoader * Remove schema from test data
author IBBoard <dev@ibboard.co.uk>
date Sun, 24 Jun 2012 15:50:45 +0100
parents 31fdc90f3556
children
line wrap: on
line source

// 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 LGPL, 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
	{
		protected const string TEST_KEY = "testKey";
		protected const string TEST_VALUE = "testTranslationValue";
		protected const string INHERITED_KEY = "inherited";
		protected const string INHERITED_VALUE = "Inherited Translation";
		
		[Test()]
		public void TestTranslationSetReturnForMissingValue()
		{
			AbstractTranslationSet translations = GetTranslationSet();
			Assert.IsNull(translations["missing"]);
		}
		
		[Test()]
		public void TestTranslationSetSettingAndRetrieval()
		{
			AbstractTranslationSet translations = GetTranslationSetWithFixedValue();
			Assert.AreEqual(TEST_VALUE, translations[TEST_KEY]);
		}
		
		[Test()]
		public void TestTranslationSetName()
		{
			AbstractTranslationSet translations = GetTranslationSet("en");
			Assert.AreEqual("English", translations.LanguageName);
			translations = GetTranslationSet("it");
			Assert.AreEqual("Italiano", translations.LanguageName);
			translations = GetTranslationSet("zz");
			Assert.AreEqual("Unknown (zz)", translations.LanguageName);
		}
		
		[Test()]
		public void TestTranslationInheritence()
		{
			AbstractTranslationSet translations = GetTranslationSetWithInheritance("it", "en");
			Assert.AreEqual("en", translations.ParentLanguage.Code);
			Assert.AreEqual(TEST_VALUE, translations[TEST_KEY]);
			Assert.AreEqual(INHERITED_VALUE, translations[INHERITED_KEY]);
		}
		
		[Test()]
		[ExpectedException(typeof(TranslationLoadException), ExpectedMessage = "Translations contained an inheritence loop")]
		public void TestTranslationsThrowExceptionWithDirectLoop()
		{
			AbstractTranslationSet loopTranslations = GetTranslationSetWithDirectLoop();
			String trans = loopTranslations["missing"];
			Assert.Fail("Exception not thrown: " + trans);
		}
		
		[Test()]
		[ExpectedException(typeof(TranslationLoadException), ExpectedMessage = "Translations contained an inheritence loop")]
		public void TestTranslationsThrowExceptionWithIndirectLoop()
		{
			AbstractTranslationSet loopTranslations = GetTranslationSetWithIndirectLoop();
			String trans = loopTranslations["missing"];
			Assert.Fail("Exception not thrown: " + trans);
		}
			
		
		[Test()]
		public void TestEquality()
		{
			Assert.AreEqual(GetTranslationSet("en"), GetTranslationSet("en"));
			Assert.AreNotEqual(GetTranslationSet("en"), GetTranslationSet("it"));
		}

		[Test()]
		public void TestHashCodes()
		{
			Assert.AreEqual(GetTranslationSet("en").GetHashCode(), GetTranslationSet("en").GetHashCode());
		}

		protected virtual AbstractTranslationSet GetTranslationSet()
		{
			return GetTranslationSet("en");
		}
		
		protected abstract AbstractTranslationSet GetTranslationSet(string language);		
		protected abstract AbstractTranslationSet GetTranslationSetWithInheritance(string language, string parentLanguage);
		protected abstract AbstractTranslationSet GetTranslationSetWithFixedValue();
		protected abstract AbstractTranslationSet GetTranslationSetWithDirectLoop();
		protected abstract AbstractTranslationSet GetTranslationSetWithIndirectLoop();
	}
}