Mercurial > repos > IBBoard.Ini.Tests
changeset 9:eac501db18e7
Re #11 - Add getter methods to IniFile and IniSection
* Add mock classes for IniFile and IniSection
* Add tests for new getter methods
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 21 Feb 2009 10:57:23 +0000 |
parents | 7b039f226032 |
children | 62221475c572 |
files | IBBoard.Ini.Tests.csproj IniFileTest.cs IniSectionTest.cs MockIniFileWithOneSectionAndOneLine.cs MockIniSectionWithOneLine.cs |
diffstat | 5 files changed, 117 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ <Compile Include="IniSectionParserTest.cs" /> <Compile Include="IniSectionTest.cs" /> <Compile Include="IniFileTest.cs" /> + <Compile Include="MockIniFileWithOneSectionAndOneLine.cs" /> + <Compile Include="MockIniSectionWithOneLine.cs" /> </ItemGroup> <ItemGroup> <Folder Include="TestData/" />
--- 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")); } } }
--- 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")); + } } }
--- /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()); + } + } +}
--- /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)); + } + } +}