view Lang/AbstractTranslationSetTest.cs @ 19:bcb6e83752a6

Fixes #33: Add method to get list of available translations * Add tests for translation listing * Add tests for equality methods * Add tests for translation languages
author IBBoard <dev@ibboard.co.uk>
date Tue, 06 Apr 2010 19:03:57 +0000
parents 20189f3a3479
children 2834da2b8891
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
	{
		
		[Test()]
		public void TestTranslationSetReturnForMissingValue()
		{
			AbstractTranslationSet translations = GetTranslationSet();
			Assert.IsNull(translations["missing"]);
		}
		
		[Test()]
		public void TestTranslationSetSettingAndRetrieval()
		{
			AbstractTranslationSet translations = GetTranslationSetWithFixedValue();
			Assert.AreEqual(GetFixedValueTranslation(), translations[GetFixedValueKey()]);
		}
		
		[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 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 GetTranslationSetWithFixedValue();
		protected abstract string GetFixedValueKey();
		protected abstract string GetFixedValueTranslation();
	}
}