view Lang/TranslationTest.cs @ 14:15cf2fe2a627

Re #30: Improve Translations API * Add translations tests and test data * Add reset method to translations * Fix translations where API documentation (contract) didn't match behaviour
author IBBoard <dev@ibboard.co.uk>
date Tue, 06 Apr 2010 14:40:35 +0000
parents
children e3e4f7a92f8b
line wrap: on
line source

// This file (TranslationTest.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;
using IBBoard.Lang.Mock;

namespace IBBoard.Lang
{
	[TestFixture()]
	public class TranslationTest
	{
		private const string TEST_ID = "testString";
		private const string TEST_DATA_PATH = "test-data";
		
		[SetUp()]
		public void Setup()
		{
			Translation.Reset();
		}
		
		[Test()]
		public void TestMissingTranslationGivesMissingMessage()
		{
			Assert.AreEqual("++ Missing Translation missingID ++", Translation.GetTranslation("missingID"));
			Assert.AreEqual("++ Missing Translation missingID ++", Translation.GetTranslation("missingID", false));
			string defaultMessage = "default message";
			Assert.AreEqual(defaultMessage, Translation.GetTranslation("missingID", defaultMessage));
			Assert.IsNull(Translation.GetTranslation("missingID", true));
		}
		
		[Test()]
		public void TestInitialiseTranslations()
		{
			Assert.AreEqual("++ Missing Translation "+TEST_ID+" ++", Translation.GetTranslation(TEST_ID));
			Translation.InitialiseTranslations(TEST_DATA_PATH, "en");
			Assert.AreEqual("Test String", Translation.GetTranslation(TEST_ID));
			Assert.AreEqual("en", Translation.GetTranslationLanguage());
			Translation.InitialiseTranslations(TEST_DATA_PATH, "it");
			Assert.AreEqual("Fakius Romanius", Translation.GetTranslation(TEST_ID));
			Assert.AreEqual("it", Translation.GetTranslationLanguage());
		}	
		
		[Test()]
		public void TestLoadTranslations()
		{
			Assert.AreEqual("++ Missing Translation "+TEST_ID+" ++", Translation.GetTranslation(TEST_ID));
			Translation.InitialiseTranslations(TEST_DATA_PATH, "en");
			Assert.AreEqual("Test String", Translation.GetTranslation(TEST_ID));
			Assert.AreEqual("en", Translation.GetTranslationLanguage());
			Translation.LoadTranslation("it");
			Assert.AreEqual("Fakius Romanius", Translation.GetTranslation(TEST_ID));
			Assert.AreEqual("it", Translation.GetTranslationLanguage());
		}
		
		[Test()]
		public void TestITranslationTranslation()
		{
			MockTranslatable translatable = new MockTranslatable(TEST_ID);
			Translation.Translate(translatable);
			Assert.AreEqual("++ Missing Translation "+TEST_ID+" ++", translatable.Text);
			Translation.InitialiseTranslations(TEST_DATA_PATH, "en");
			Translation.Translate(translatable);
			Assert.AreEqual("Test String", translatable.Text);
		}
	}
}