Mercurial > repos > IBBoard.Tests
annotate Lang/AbstractTranslationSetTest.cs @ 45:7502653a71a0
* Update tests - we now fix Microsoft's lack of capitalisation in language names
* Change to not passing schema location to TranslationXmlLoader
* Remove schema from test data
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 24 Jun 2012 15:50:45 +0100 |
parents | 31fdc90f3556 |
children |
rev | line source |
---|---|
15
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (TranslationSetTest.cs) is a part of the IBBoard.Tests project and is copyright 2010 IBBoard |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
28
31fdc90f3556
* Fix license comments at top of files
IBBoard <dev@ibboard.co.uk>
parents:
22
diff
changeset
|
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU LGPL, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
15
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System; |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using NUnit.Framework; |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 namespace IBBoard.Lang |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 { |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 public abstract class AbstractTranslationSetTest |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 { |
21
2834da2b8891
Re #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
12 protected const string TEST_KEY = "testKey"; |
2834da2b8891
Re #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
13 protected const string TEST_VALUE = "testTranslationValue"; |
2834da2b8891
Re #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
14 protected const string INHERITED_KEY = "inherited"; |
2834da2b8891
Re #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
15 protected const string INHERITED_VALUE = "Inherited Translation"; |
15
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 [Test()] |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 public void TestTranslationSetReturnForMissingValue() |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 { |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 AbstractTranslationSet translations = GetTranslationSet(); |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 Assert.IsNull(translations["missing"]); |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 } |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 [Test()] |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 public void TestTranslationSetSettingAndRetrieval() |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 { |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 AbstractTranslationSet translations = GetTranslationSetWithFixedValue(); |
21
2834da2b8891
Re #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
28 Assert.AreEqual(TEST_VALUE, translations[TEST_KEY]); |
15
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 } |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 |
18
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
31 [Test()] |
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
32 public void TestTranslationSetName() |
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
33 { |
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
34 AbstractTranslationSet translations = GetTranslationSet("en"); |
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
35 Assert.AreEqual("English", translations.LanguageName); |
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
36 translations = GetTranslationSet("it"); |
45
7502653a71a0
* Update tests - we now fix Microsoft's lack of capitalisation in language names
IBBoard <dev@ibboard.co.uk>
parents:
28
diff
changeset
|
37 Assert.AreEqual("Italiano", translations.LanguageName); |
18
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
38 translations = GetTranslationSet("zz"); |
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
39 Assert.AreEqual("Unknown (zz)", translations.LanguageName); |
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
40 } |
19
bcb6e83752a6
Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
41 |
bcb6e83752a6
Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
42 [Test()] |
21
2834da2b8891
Re #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
43 public void TestTranslationInheritence() |
2834da2b8891
Re #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
44 { |
2834da2b8891
Re #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
45 AbstractTranslationSet translations = GetTranslationSetWithInheritance("it", "en"); |
2834da2b8891
Re #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
46 Assert.AreEqual("en", translations.ParentLanguage.Code); |
2834da2b8891
Re #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
47 Assert.AreEqual(TEST_VALUE, translations[TEST_KEY]); |
2834da2b8891
Re #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
48 Assert.AreEqual(INHERITED_VALUE, translations[INHERITED_KEY]); |
2834da2b8891
Re #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
49 } |
2834da2b8891
Re #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
50 |
2834da2b8891
Re #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
51 [Test()] |
22
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
52 [ExpectedException(typeof(TranslationLoadException), ExpectedMessage = "Translations contained an inheritence loop")] |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
53 public void TestTranslationsThrowExceptionWithDirectLoop() |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
54 { |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
55 AbstractTranslationSet loopTranslations = GetTranslationSetWithDirectLoop(); |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
56 String trans = loopTranslations["missing"]; |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
57 Assert.Fail("Exception not thrown: " + trans); |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
58 } |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
59 |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
60 [Test()] |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
61 [ExpectedException(typeof(TranslationLoadException), ExpectedMessage = "Translations contained an inheritence loop")] |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
62 public void TestTranslationsThrowExceptionWithIndirectLoop() |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
63 { |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
64 AbstractTranslationSet loopTranslations = GetTranslationSetWithIndirectLoop(); |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
65 String trans = loopTranslations["missing"]; |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
66 Assert.Fail("Exception not thrown: " + trans); |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
67 } |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
68 |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
69 |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
70 [Test()] |
19
bcb6e83752a6
Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
71 public void TestEquality() |
bcb6e83752a6
Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
72 { |
bcb6e83752a6
Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
73 Assert.AreEqual(GetTranslationSet("en"), GetTranslationSet("en")); |
bcb6e83752a6
Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
74 Assert.AreNotEqual(GetTranslationSet("en"), GetTranslationSet("it")); |
bcb6e83752a6
Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
75 } |
bcb6e83752a6
Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
76 |
bcb6e83752a6
Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
77 [Test()] |
bcb6e83752a6
Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
78 public void TestHashCodes() |
bcb6e83752a6
Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
79 { |
bcb6e83752a6
Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
80 Assert.AreEqual(GetTranslationSet("en").GetHashCode(), GetTranslationSet("en").GetHashCode()); |
bcb6e83752a6
Fixes #33: Add method to get list of available translations
IBBoard <dev@ibboard.co.uk>
parents:
18
diff
changeset
|
81 } |
18
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
82 |
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
83 protected virtual AbstractTranslationSet GetTranslationSet() |
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
84 { |
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
85 return GetTranslationSet("en"); |
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
86 } |
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
87 |
20189f3a3479
Re #34: Get name for translation
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
88 protected abstract AbstractTranslationSet GetTranslationSet(string language); |
21
2834da2b8891
Re #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
19
diff
changeset
|
89 protected abstract AbstractTranslationSet GetTranslationSetWithInheritance(string language, string parentLanguage); |
15
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
90 protected abstract AbstractTranslationSet GetTranslationSetWithFixedValue(); |
22
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
91 protected abstract AbstractTranslationSet GetTranslationSetWithDirectLoop(); |
e9bad86c1360
Fixes #35: Add multi-level cascading of translations
IBBoard <dev@ibboard.co.uk>
parents:
21
diff
changeset
|
92 protected abstract AbstractTranslationSet GetTranslationSetWithIndirectLoop(); |
15
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
93 } |
e3e4f7a92f8b
Re #31: Break out Translations for language to own class
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
94 } |