Mercurial > repos > IBBoard.Tests
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 |
rev | line source |
---|---|
14 | 1 // This file (TranslationTest.cs) is a part of the IBBoard.Tests project and is copyright 2010 IBBoard |
2 // | |
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. | |
4 | |
5 using System; | |
6 using NUnit.Framework; | |
7 using IBBoard.Lang.Mock; | |
8 | |
9 namespace IBBoard.Lang | |
10 { | |
11 [TestFixture()] | |
12 public class TranslationTest | |
13 { | |
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 | 16 |
17 [SetUp()] | |
18 public void Setup() | |
19 { | |
20 Translation.Reset(); | |
21 } | |
22 | |
23 [Test()] | |
24 public void TestMissingTranslationGivesMissingMessage() | |
25 { | |
26 Assert.AreEqual("++ Missing Translation missingID ++", Translation.GetTranslation("missingID")); | |
27 Assert.AreEqual("++ Missing Translation missingID ++", Translation.GetTranslation("missingID", false)); | |
28 string defaultMessage = "default message"; | |
29 Assert.AreEqual(defaultMessage, Translation.GetTranslation("missingID", defaultMessage)); | |
30 Assert.IsNull(Translation.GetTranslation("missingID", true)); | |
31 } | |
32 | |
33 [Test()] | |
34 public void TestInitialiseTranslations() | |
35 { | |
36 Assert.AreEqual("++ Missing Translation "+TEST_ID+" ++", Translation.GetTranslation(TEST_ID)); | |
37 Translation.InitialiseTranslations(TEST_DATA_PATH, "en"); | |
38 Assert.AreEqual("Test String", Translation.GetTranslation(TEST_ID)); | |
39 Assert.AreEqual("en", Translation.GetTranslationLanguage()); | |
40 Translation.InitialiseTranslations(TEST_DATA_PATH, "it"); | |
41 Assert.AreEqual("Fakius Romanius", Translation.GetTranslation(TEST_ID)); | |
42 Assert.AreEqual("it", Translation.GetTranslationLanguage()); | |
43 } | |
44 | |
45 [Test()] | |
46 public void TestLoadTranslations() | |
47 { | |
48 Assert.AreEqual("++ Missing Translation "+TEST_ID+" ++", Translation.GetTranslation(TEST_ID)); | |
49 Translation.InitialiseTranslations(TEST_DATA_PATH, "en"); | |
50 Assert.AreEqual("Test String", Translation.GetTranslation(TEST_ID)); | |
51 Assert.AreEqual("en", Translation.GetTranslationLanguage()); | |
52 Translation.LoadTranslation("it"); | |
53 Assert.AreEqual("Fakius Romanius", Translation.GetTranslation(TEST_ID)); | |
54 Assert.AreEqual("it", Translation.GetTranslationLanguage()); | |
55 } | |
56 | |
57 [Test()] | |
58 public void TestITranslationTranslation() | |
59 { | |
60 MockTranslatable translatable = new MockTranslatable(TEST_ID); | |
61 Translation.Translate(translatable); | |
62 Assert.AreEqual("++ Missing Translation "+TEST_ID+" ++", translatable.Text); | |
63 Translation.InitialiseTranslations(TEST_DATA_PATH, "en"); | |
64 Translation.Translate(translatable); | |
65 Assert.AreEqual("Test String", translatable.Text); | |
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 | 127 } |
128 } |