view Lang/TranslationTest.cs @ 15:e3e4f7a92f8b

Re #31: Break out Translations for language to own class * Add tests for translation sets Re #30: Improve Translations API * Add more tests
author IBBoard <dev@ibboard.co.uk>
date Tue, 06 Apr 2010 15:43:08 +0000
parents 15cf2fe2a627
children bcb6e83752a6
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);
		}
		
		[Test()]
		public void TestResetDoesNotCauseErrors()
		{
			Assert.AreEqual("++ Missing Translation missingID ++", Translation.GetTranslation("missingID"));
		}
	}
}