view Lang/AbstractTranslationSetTest.cs @ 21:2834da2b8891

Re #35: Add multi-level cascading of translations * Add tests of "parent language" property * Move some test values to constants instead of abstract methods Also: * Fix warning about tests not being executable because they're on an abstract class by not marking abstract class as a test fixture
author IBBoard <dev@ibboard.co.uk>
date Wed, 07 Apr 2010 19:36:08 +0000
parents bcb6e83752a6
children e9bad86c1360
line source
1 // This file (TranslationSetTest.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.
5 using System;
6 using NUnit.Framework;
8 namespace IBBoard.Lang
9 {
10 public abstract class AbstractTranslationSetTest
11 {
12 protected const string TEST_KEY = "testKey";
13 protected const string TEST_VALUE = "testTranslationValue";
14 protected const string INHERITED_KEY = "inherited";
15 protected const string INHERITED_VALUE = "Inherited Translation";
17 [Test()]
18 public void TestTranslationSetReturnForMissingValue()
19 {
20 AbstractTranslationSet translations = GetTranslationSet();
21 Assert.IsNull(translations["missing"]);
22 }
24 [Test()]
25 public void TestTranslationSetSettingAndRetrieval()
26 {
27 AbstractTranslationSet translations = GetTranslationSetWithFixedValue();
28 Assert.AreEqual(TEST_VALUE, translations[TEST_KEY]);
29 }
31 [Test()]
32 public void TestTranslationSetName()
33 {
34 AbstractTranslationSet translations = GetTranslationSet("en");
35 Assert.AreEqual("English", translations.LanguageName);
36 translations = GetTranslationSet("it");
37 Assert.AreEqual("italiano", translations.LanguageName);
38 translations = GetTranslationSet("zz");
39 Assert.AreEqual("Unknown (zz)", translations.LanguageName);
40 }
42 [Test()]
43 public void TestTranslationInheritence()
44 {
45 AbstractTranslationSet translations = GetTranslationSetWithInheritance("it", "en");
46 Assert.AreEqual("en", translations.ParentLanguage.Code);
47 Assert.AreEqual(TEST_VALUE, translations[TEST_KEY]);
48 Assert.AreEqual(INHERITED_VALUE, translations[INHERITED_KEY]);
49 }
51 [Test()]
52 public void TestEquality()
53 {
54 Assert.AreEqual(GetTranslationSet("en"), GetTranslationSet("en"));
55 Assert.AreNotEqual(GetTranslationSet("en"), GetTranslationSet("it"));
56 }
58 [Test()]
59 public void TestHashCodes()
60 {
61 Assert.AreEqual(GetTranslationSet("en").GetHashCode(), GetTranslationSet("en").GetHashCode());
62 }
64 protected virtual AbstractTranslationSet GetTranslationSet()
65 {
66 return GetTranslationSet("en");
67 }
69 protected abstract AbstractTranslationSet GetTranslationSet(string language);
70 protected abstract AbstractTranslationSet GetTranslationSetWithInheritance(string language, string parentLanguage);
71 protected abstract AbstractTranslationSet GetTranslationSetWithFixedValue();
72 }
73 }