view IniFileTest.cs @ 12:0be17f8102ed

* Fix unit test paths
author IBBoard <dev@ibboard.co.uk>
date Wed, 07 Nov 2012 20:22:20 +0000
parents eac501db18e7
children
line source
1 // This file (IniFileTest.cs) is a part of IBBoard.Ini.Tests library and is copyright 2009 IBBoard.
2 //
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
5 using System;
6 using NUnit.Framework;
8 namespace IBBoard.Ini
9 {
10 [TestFixture()]
11 public class IniFileTest
12 {
13 [Test()]
14 public void TestAddingSectionMakesSectionAvailable()
15 {
16 IniFile file = new IniFile();
17 IniSection section = new IniSection("section");
18 file.AddSection(section);
19 Assert.AreEqual(1, file.Sections.Length);
20 Assert.IsTrue(file.HasSection("section"));
21 Assert.AreEqual(section, file["section"]);
22 }
24 [Test()]
25 [ExpectedException("IBBoard.Ini.DuplicateIniSectionException")]
26 public void TestAddingDuplicateSectionThrowsDuplicateSectionException()
27 {
28 IniFile file = new IniFile();
29 file.AddSection(new IniSection("key"));
30 file.AddSection(new IniSection("key"));
31 }
33 [Test()]
34 [ExpectedException("IBBoard.Ini.DuplicateIniSectionException")]
35 public void TestAddingDuplicateSectionWithDifferentNameCaseThrowsDuplicateSectionException()
36 {
37 IniFile file = new IniFile();
38 file.AddSection(new IniSection("key"));
39 file.AddSection(new IniSection("KEY"));
40 }
42 [Test()]
43 public void TestGettingNonExistantSectionDoesNotReturnNull()
44 {
45 IniFile file = new IniFile();
46 IniSection section = file["non-existant-section"];
47 Assert.IsNotNull(section);
48 Assert.IsInstanceOfType(typeof(NonExistantIniSection), section);
49 }
51 [Test()]
52 public void TestGettingSectionLineValueOnNonExistantSectionReturnsNull()
53 {
54 IniFile file = new IniFile();
55 Assert.IsNull(file.GetSectionLineValue("a", "b"));
56 }
58 [Test()]
59 public void TestGettingSectionLineValueOnNonExistantLineInSectionReturnsNull()
60 {
61 IniFile file = new MockIniFileWithOneSectionAndOneLine();
62 Assert.IsNull(file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME, "b"));
63 }
65 [Test()]
66 public void TestGettingSectionLineValueOnLineInSectionReturnsValue()
67 {
68 IniFile file = new MockIniFileWithOneSectionAndOneLine();
69 Assert.AreEqual(MockIniFileWithOneSectionAndOneLine.VALUE, file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME, MockIniFileWithOneSectionAndOneLine.KEY_NAME));
70 }
72 [Test()]
73 public void TestGettingSectionLineValueOnLineInSectionWithDifferentSectionNameCaseReturnsValue()
74 {
75 IniFile file = new MockIniFileWithOneSectionAndOneLine();
76 Assert.AreEqual(MockIniFileWithOneSectionAndOneLine.VALUE, file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME.ToUpper(), MockIniFileWithOneSectionAndOneLine.KEY_NAME));
77 }
79 [Test()]
80 public void TestGettingSectionLineValueOnLineInSectionWithDifferentLineNameCaseReturnsValue()
81 {
82 IniFile file = new MockIniFileWithOneSectionAndOneLine();
83 Assert.AreEqual(MockIniFileWithOneSectionAndOneLine.VALUE, file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME, MockIniFileWithOneSectionAndOneLine.KEY_NAME.ToUpper()));
84 }
86 [Test()]
87 public void TestGettingSectionLineValueOnNonExistantSectionReturnsDefaultValue()
88 {
89 IniFile file = new IniFile();
90 Assert.AreEqual("default-value", file.GetSectionLineValue("a", "b", "default-value"));
91 }
93 [Test()]
94 public void TestGettingSectionLineValueOnNonExistantLineInSectionReturnsDefaultValue()
95 {
96 IniFile file = new MockIniFileWithOneSectionAndOneLine();
97 Assert.AreEqual("default-value", file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME, "b", "default-value"));
98 }
100 [Test()]
101 public void TestGettingSectionLineValueOnLineInSectionDoesNotReturnDefault()
102 {
103 IniFile file = new MockIniFileWithOneSectionAndOneLine();
104 Assert.AreEqual(MockIniFileWithOneSectionAndOneLine.VALUE, file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME, MockIniFileWithOneSectionAndOneLine.KEY_NAME, "default-value"));
105 }
106 }
107 }