# HG changeset patch # User IBBoard # Date 1235213843 0 # Node ID eac501db18e7c60a87d5a563258f3cf6098cd3e4 # Parent 7b039f226032bc63ac8a00fdbd8dca773e628ac0 Re #11 - Add getter methods to IniFile and IniSection * Add mock classes for IniFile and IniSection * Add tests for new getter methods diff -r 7b039f226032 -r eac501db18e7 IBBoard.Ini.Tests.csproj --- a/IBBoard.Ini.Tests.csproj Tue Feb 17 15:28:21 2009 +0000 +++ b/IBBoard.Ini.Tests.csproj Sat Feb 21 10:57:23 2009 +0000 @@ -41,6 +41,8 @@ + + diff -r 7b039f226032 -r eac501db18e7 IniFileTest.cs --- a/IniFileTest.cs Tue Feb 17 15:28:21 2009 +0000 +++ b/IniFileTest.cs Sat Feb 21 10:57:23 2009 +0000 @@ -34,7 +34,51 @@ public void TestGettingNonExistantSectionDoesNotReturnNull() { IniFile file = new IniFile(); - Assert.IsNotNull(file["non-existant-section"]); + IniSection section = file["non-existant-section"]; + Assert.IsNotNull(section); + Assert.IsInstanceOfType(typeof(NonExistantIniSection), section); + } + + [Test()] + public void TestGettingSectionLineValueOnNonExistantSectionReturnsNull() + { + IniFile file = new IniFile(); + Assert.IsNull(file.GetSectionLineValue("a", "b")); + } + + [Test()] + public void TestGettingSectionLineValueOnNonExistantLineInSectionReturnsNull() + { + IniFile file = new MockIniFileWithOneSectionAndOneLine(); + Assert.IsNull(file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME, "b")); + } + + [Test()] + public void TestGettingSectionLineValueOnLineInSectionReturnsValue() + { + IniFile file = new MockIniFileWithOneSectionAndOneLine(); + Assert.AreEqual(MockIniFileWithOneSectionAndOneLine.VALUE, file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME, MockIniFileWithOneSectionAndOneLine.KEY_NAME)); + } + + [Test()] + public void TestGettingSectionLineValueOnNonExistantSectionReturnsDefaultValue() + { + IniFile file = new IniFile(); + Assert.AreEqual("default-value", file.GetSectionLineValue("a", "b", "default-value")); + } + + [Test()] + public void TestGettingSectionLineValueOnNonExistantLineInSectionReturnsDefaultValue() + { + IniFile file = new MockIniFileWithOneSectionAndOneLine(); + Assert.AreEqual("default-value", file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME, "b", "default-value")); + } + + [Test()] + public void TestGettingSectionLineValueOnLineInSectionDoesNotReturnDefault() + { + IniFile file = new MockIniFileWithOneSectionAndOneLine(); + Assert.AreEqual(MockIniFileWithOneSectionAndOneLine.VALUE, file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME, MockIniFileWithOneSectionAndOneLine.KEY_NAME, "default-value")); } } } diff -r 7b039f226032 -r eac501db18e7 IniSectionTest.cs --- a/IniSectionTest.cs Tue Feb 17 15:28:21 2009 +0000 +++ b/IniSectionTest.cs Sat Feb 21 10:57:23 2009 +0000 @@ -46,5 +46,33 @@ line = new IniKeyValuePairLine("something", "different"); section.AddIniLine(line); } + + [Test()] + public void TestGettingLineValueOnNonExistantLineReturnsNull() + { + IniSection section = new MockIniSectionWithOneLine(); + Assert.IsNull(section.GetLineValue("b")); + } + + [Test()] + public void TestGettingSectionLineValueOnLineInSectionReturnsValue() + { + IniSection section = new MockIniSectionWithOneLine(); + Assert.AreEqual(MockIniSectionWithOneLine.VALUE, section.GetLineValue(MockIniSectionWithOneLine.KEY_NAME)); + } + + [Test()] + public void TestGettingSectionLineValueOnNonExistantLineInSectionReturnsDefaultValue() + { + IniSection section = new MockIniSectionWithOneLine(); + Assert.AreEqual("default-value", section.GetLineValue("b", "default-value")); + } + + [Test()] + public void TestGettingSectionLineValueOnLineInSectionDoesNotReturnDefault() + { + IniSection section = new MockIniSectionWithOneLine(); + Assert.AreEqual(MockIniSectionWithOneLine.VALUE, section.GetLineValue(MockIniSectionWithOneLine.KEY_NAME, "default-value")); + } } } diff -r 7b039f226032 -r eac501db18e7 MockIniFileWithOneSectionAndOneLine.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MockIniFileWithOneSectionAndOneLine.cs Sat Feb 21 10:57:23 2009 +0000 @@ -0,0 +1,21 @@ +// This file (MockIniFileWithOneSectionAndOneLine.cs) is a part of IBBoard.Ini.Tests project and is copyright 2009 IBBoard +// +// 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. +// + +using System; + +namespace IBBoard.Ini +{ + public class MockIniFileWithOneSectionAndOneLine : IniFile + { + public static readonly string SECTION_NAME = MockIniSectionWithOneLine.SECTION_NAME; + public static readonly string KEY_NAME = MockIniSectionWithOneLine.KEY_NAME; + public static readonly string VALUE = MockIniSectionWithOneLine.VALUE; + + public MockIniFileWithOneSectionAndOneLine() + { + AddSection(new MockIniSectionWithOneLine()); + } + } +} diff -r 7b039f226032 -r eac501db18e7 MockIniSectionWithOneLine.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MockIniSectionWithOneLine.cs Sat Feb 21 10:57:23 2009 +0000 @@ -0,0 +1,21 @@ +// This file (MockIniSectionWithOneLine.cs) is a part of [PROJECT NAME] and is copyright 2009 IBBoard +// +// 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. +// + +using System; + +namespace IBBoard.Ini +{ + public class MockIniSectionWithOneLine : IniSection + { + public static readonly string SECTION_NAME = "section"; + public static readonly string KEY_NAME = "key"; + public static readonly string VALUE = "value"; + + public MockIniSectionWithOneLine() : base(SECTION_NAME) + { + AddIniLine(new IniKeyValuePairLine(KEY_NAME, VALUE)); + } + } +}