annotate Lang/TranslationTest.cs @ 25:8a350c00797e

Fixes #32 (Add staged loading of translations) and fixes #30 (Improve Translations API): * Update tests to work with new method on XmlTranslationSet
author IBBoard <dev@ibboard.co.uk>
date Sat, 10 Apr 2010 19:06:29 +0000
parents 948317c89fad
children 31fdc90f3556
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";
24
948317c89fad Re #32: Add staged loading of translations
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
15 private const string TEST_DATA_PATH = "test-data/TranslationTests";
14
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 }
19
bcb6e83752a6 Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
73
bcb6e83752a6 Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
74 [Test()]
bcb6e83752a6 Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
75 public void TestLoadedListOfLanguageNames()
bcb6e83752a6 Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
76 {
bcb6e83752a6 Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
77 Translation.InitialiseTranslations(TEST_DATA_PATH);
bcb6e83752a6 Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
78 Assert.AreEqual(2, Translation.GetLanguages().Count);
bcb6e83752a6 Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
79 Assert.That(Translation.GetLanguages().Contains(new TranslationLanguage("en")));
bcb6e83752a6 Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
80 Assert.That(Translation.GetLanguages().Contains(new TranslationLanguage("it")));
bcb6e83752a6 Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
81 }
20
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
82
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
83 [Test()]
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
84 public void TestTranslationChangedEventFiresOnChange()
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
85 {
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
86 Translation.InitialiseTranslations(TEST_DATA_PATH);
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
87 MethodFireObject obj = new MethodFireObject();
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
88 Translation.TranslationChanged+= obj.Method;
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
89 Translation.LoadTranslation("en");
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
90 Assert.IsTrue(obj.methodFired);
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
91 obj.methodFired = false;
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
92 Translation.LoadTranslation("it");
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
93 Assert.IsTrue(obj.methodFired);
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
94 }
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
95
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
96 [Test()]
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
97 public void TestTranslationChangedEventNotFiredOnChangeToSameValue()
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
98 {
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
99 Translation.InitialiseTranslations(TEST_DATA_PATH);
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
100 Translation.LoadTranslation("en");
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
101 MethodFireObject obj = new MethodFireObject();
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
102 Translation.TranslationChanged+= obj.Method;
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
103 Translation.LoadTranslation("en");
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
104 Assert.IsFalse(obj.methodFired);
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
105 }
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
106
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
107 [Test()]
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
108 public void TestTranslationChangedEventFiredOnReset()
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
109 {
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
110 Translation.InitialiseTranslations(TEST_DATA_PATH);
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
111 Translation.LoadTranslation("en");
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
112 MethodFireObject obj = new MethodFireObject();
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
113 Translation.TranslationChanged+= obj.Method;
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
114 Translation.Reset();
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
115 Assert.IsTrue(obj.methodFired);
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
116 }
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
117
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
118 private class MethodFireObject
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
119 {
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
120 public bool methodFired = false;
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
121
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
122 public void Method()
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
123 {
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
124 methodFired = true;
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
125 }
b3bc581a8433 Fixes #37: Add event to indicate change of translation
IBBoard <dev@ibboard.co.uk>
parents: 19
diff changeset
126 }
14
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
127 }
15cf2fe2a627 Re #30: Improve Translations API
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
128 }