view IniSectionTest.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 (IniSectionTest.cs) is a part of the 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 IniSectionTest
12 {
13 [Test()]
14 public void TestAddingCommentLineDoesNotAddKeyItem()
15 {
16 IniSection section = new IniSection("someName");
17 section.AddIniLine(new IniCommentLine("something"));
18 Assert.AreEqual(0, section.Keys.Length);
19 }
21 [Test()]
22 public void TestAddingBlankLineDoesNotAddKeyItem()
23 {
24 IniSection section = new IniSection("someName");
25 section.AddIniLine(new IniBlankLine());
26 Assert.AreEqual(0, section.Keys.Length);
27 }
29 [Test()]
30 public void TestAddingKeyValuePairLineAddsKeyItem()
31 {
32 IniSection section = new IniSection("someName");
33 IniKeyValuePairLine line = new IniKeyValuePairLine("something", "value");
34 section.AddIniLine(line);
35 Assert.AreEqual(1, section.Keys.Length);
36 Assert.AreEqual(line, section["something"]);
37 }
39 [Test()]
40 [ExpectedException("IBBoard.Ini.DuplicateIniLineException")]
41 public void TestAddingKeyValuePairLineExceptionsOnDuplicateKey()
42 {
43 IniSection section = new IniSection("someName");
44 IniKeyValuePairLine line = new IniKeyValuePairLine("something", "value");
45 section.AddIniLine(line);
46 line = new IniKeyValuePairLine("something", "different");
47 section.AddIniLine(line);
48 }
50 [Test()]
51 [ExpectedException("IBBoard.Ini.DuplicateIniLineException")]
52 public void TestAddingKeyValuePairLineExceptionsOnDuplicateKeyWithDifferentCase()
53 {
54 IniSection section = new IniSection("someName");
55 IniKeyValuePairLine line = new IniKeyValuePairLine("something", "value");
56 section.AddIniLine(line);
57 line = new IniKeyValuePairLine("SOMETHING", "different");
58 section.AddIniLine(line);
59 }
61 [Test()]
62 public void TestGettingLineValueOnNonExistantLineReturnsNull()
63 {
64 IniSection section = new MockIniSectionWithOneLine();
65 Assert.IsNull(section.GetLineValue("b"));
66 }
68 [Test()]
69 public void TestGettingSectionLineValueOnLineInSectionReturnsValue()
70 {
71 IniSection section = new MockIniSectionWithOneLine();
72 Assert.AreEqual(MockIniSectionWithOneLine.VALUE, section.GetLineValue(MockIniSectionWithOneLine.KEY_NAME));
73 }
75 [Test()]
76 public void TestGettingSectionLineValueOnLineInSectionWithDifferentCaseReturnsValue()
77 {
78 IniSection section = new MockIniSectionWithOneLine();
79 Assert.AreEqual(MockIniSectionWithOneLine.VALUE, section.GetLineValue(MockIniSectionWithOneLine.KEY_NAME.ToUpper()));
80 }
82 [Test()]
83 public void TestGettingSectionLineValueOnNonExistantLineInSectionReturnsDefaultValue()
84 {
85 IniSection section = new MockIniSectionWithOneLine();
86 Assert.AreEqual("default-value", section.GetLineValue("b", "default-value"));
87 }
89 [Test()]
90 public void TestGettingSectionLineValueOnLineInSectionDoesNotReturnDefault()
91 {
92 IniSection section = new MockIniSectionWithOneLine();
93 Assert.AreEqual(MockIniSectionWithOneLine.VALUE, section.GetLineValue(MockIniSectionWithOneLine.KEY_NAME, "default-value"));
94 }
95 }
96 }