view Lang/AbstractTranslationSetTest.cs @ 21:2834da2b8891

Re #35: Add multi-level cascading of translations * Add tests of "parent language" property * Move some test values to constants instead of abstract methods Also: * Fix warning about tests not being executable because they're on an abstract class by not marking abstract class as a test fixture
author IBBoard <dev@ibboard.co.uk>
date Wed, 07 Apr 2010 19:36:08 +0000
parents bcb6e83752a6
children e9bad86c1360
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 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
	{
		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()]
		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();
	}
}