annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (TranslationTest.cs) is a part of the IBBoard.Tests project and is copyright 2010 IBBoard
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // 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.
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using NUnit.Framework;
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using IBBoard.Lang.Mock;
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 namespace IBBoard.Lang
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 {
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 [TestFixture()]
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 public class TranslationTest
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 {
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 private const string TEST_ID = "testString";
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 private const string TEST_DATA_PATH = "test-data";
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 [SetUp()]
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 public void Setup()
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 {
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 Translation.Reset();
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 }
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 [Test()]
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 public void TestMissingTranslationGivesMissingMessage()
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 {
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 Assert.AreEqual("++ Missing Translation missingID ++", Translation.GetTranslation("missingID"));
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 Assert.AreEqual("++ Missing Translation missingID ++", Translation.GetTranslation("missingID", false));
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 string defaultMessage = "default message";
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 Assert.AreEqual(defaultMessage, Translation.GetTranslation("missingID", defaultMessage));
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 Assert.IsNull(Translation.GetTranslation("missingID", true));
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 }
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 [Test()]
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 public void TestInitialiseTranslations()
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 {
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 Assert.AreEqual("++ Missing Translation "+TEST_ID+" ++", Translation.GetTranslation(TEST_ID));
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 Translation.InitialiseTranslations(TEST_DATA_PATH, "en");
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 Assert.AreEqual("Test String", Translation.GetTranslation(TEST_ID));
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 Assert.AreEqual("en", Translation.GetTranslationLanguage());
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 Translation.InitialiseTranslations(TEST_DATA_PATH, "it");
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 Assert.AreEqual("Fakius Romanius", Translation.GetTranslation(TEST_ID));
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 Assert.AreEqual("it", Translation.GetTranslationLanguage());
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 }
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 [Test()]
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 public void TestLoadTranslations()
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 {
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 Assert.AreEqual("++ Missing Translation "+TEST_ID+" ++", Translation.GetTranslation(TEST_ID));
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 Translation.InitialiseTranslations(TEST_DATA_PATH, "en");
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 Assert.AreEqual("Test String", Translation.GetTranslation(TEST_ID));
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 Assert.AreEqual("en", Translation.GetTranslationLanguage());
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 Translation.LoadTranslation("it");
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 Assert.AreEqual("Fakius Romanius", Translation.GetTranslation(TEST_ID));
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 Assert.AreEqual("it", Translation.GetTranslationLanguage());
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 }
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 [Test()]
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 public void TestITranslationTranslation()
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 {
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 MockTranslatable translatable = new MockTranslatable(TEST_ID);
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 Translation.Translate(translatable);
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 Assert.AreEqual("++ Missing Translation "+TEST_ID+" ++", translatable.Text);
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 Translation.InitialiseTranslations(TEST_DATA_PATH, "en");
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 Translation.Translate(translatable);
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 Assert.AreEqual("Test String", translatable.Text);
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 }
15
e3e4f7a92f8b Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
67
e3e4f7a92f8b Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
68 [Test()]
e3e4f7a92f8b Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
69 public void TestResetDoesNotCauseErrors()
e3e4f7a92f8b Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
70 {
e3e4f7a92f8b Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
71 Assert.AreEqual("++ Missing Translation missingID ++", Translation.GetTranslation("missingID"));
e3e4f7a92f8b Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents: 14
diff changeset
72 }
14
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 }
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 }