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 diff
     1.1 --- a/IBBoard.Ini.Tests.csproj	Tue Feb 17 15:28:21 2009 +0000
     1.2 +++ b/IBBoard.Ini.Tests.csproj	Sat Feb 21 10:57:23 2009 +0000
     1.3 @@ -41,6 +41,8 @@
     1.4      <Compile Include="IniSectionParserTest.cs" />
     1.5      <Compile Include="IniSectionTest.cs" />
     1.6      <Compile Include="IniFileTest.cs" />
     1.7 +    <Compile Include="MockIniFileWithOneSectionAndOneLine.cs" />
     1.8 +    <Compile Include="MockIniSectionWithOneLine.cs" />
     1.9    </ItemGroup>
    1.10    <ItemGroup>
    1.11      <Folder Include="TestData/" />
     2.1 --- a/IniFileTest.cs	Tue Feb 17 15:28:21 2009 +0000
     2.2 +++ b/IniFileTest.cs	Sat Feb 21 10:57:23 2009 +0000
     2.3 @@ -34,7 +34,51 @@
     2.4  		public void TestGettingNonExistantSectionDoesNotReturnNull()
     2.5  		{
     2.6  			IniFile file = new IniFile();
     2.7 -			Assert.IsNotNull(file["non-existant-section"]);
     2.8 +			IniSection section = file["non-existant-section"];
     2.9 +			Assert.IsNotNull(section);
    2.10 +			Assert.IsInstanceOfType(typeof(NonExistantIniSection), section);
    2.11 +		}
    2.12 +		
    2.13 +		[Test()]
    2.14 +		public void TestGettingSectionLineValueOnNonExistantSectionReturnsNull()
    2.15 +		{
    2.16 +			IniFile file = new IniFile();
    2.17 +			Assert.IsNull(file.GetSectionLineValue("a", "b"));
    2.18 +		}
    2.19 +		
    2.20 +		[Test()]
    2.21 +		public void TestGettingSectionLineValueOnNonExistantLineInSectionReturnsNull()
    2.22 +		{
    2.23 +			IniFile file = new MockIniFileWithOneSectionAndOneLine();
    2.24 +			Assert.IsNull(file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME, "b"));
    2.25 +		}
    2.26 +		
    2.27 +		[Test()]
    2.28 +		public void TestGettingSectionLineValueOnLineInSectionReturnsValue()
    2.29 +		{
    2.30 +			IniFile file = new MockIniFileWithOneSectionAndOneLine();
    2.31 +			Assert.AreEqual(MockIniFileWithOneSectionAndOneLine.VALUE, file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME, MockIniFileWithOneSectionAndOneLine.KEY_NAME));
    2.32 +		}
    2.33 +		
    2.34 +		[Test()]
    2.35 +		public void TestGettingSectionLineValueOnNonExistantSectionReturnsDefaultValue()
    2.36 +		{
    2.37 +			IniFile file = new IniFile();
    2.38 +			Assert.AreEqual("default-value", file.GetSectionLineValue("a", "b", "default-value"));
    2.39 +		}
    2.40 +		
    2.41 +		[Test()]
    2.42 +		public void TestGettingSectionLineValueOnNonExistantLineInSectionReturnsDefaultValue()
    2.43 +		{
    2.44 +			IniFile file = new MockIniFileWithOneSectionAndOneLine();
    2.45 +			Assert.AreEqual("default-value", file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME, "b", "default-value"));
    2.46 +		}
    2.47 +		
    2.48 +		[Test()]
    2.49 +		public void TestGettingSectionLineValueOnLineInSectionDoesNotReturnDefault()
    2.50 +		{
    2.51 +			IniFile file = new MockIniFileWithOneSectionAndOneLine();
    2.52 +			Assert.AreEqual(MockIniFileWithOneSectionAndOneLine.VALUE, file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME, MockIniFileWithOneSectionAndOneLine.KEY_NAME, "default-value"));
    2.53  		}
    2.54  	}
    2.55  }
     3.1 --- a/IniSectionTest.cs	Tue Feb 17 15:28:21 2009 +0000
     3.2 +++ b/IniSectionTest.cs	Sat Feb 21 10:57:23 2009 +0000
     3.3 @@ -46,5 +46,33 @@
     3.4  			line = new IniKeyValuePairLine("something", "different");
     3.5  			section.AddIniLine(line);
     3.6  		}
     3.7 +		
     3.8 +		[Test()]
     3.9 +		public void TestGettingLineValueOnNonExistantLineReturnsNull()
    3.10 +		{
    3.11 +			IniSection section = new MockIniSectionWithOneLine();
    3.12 +			Assert.IsNull(section.GetLineValue("b"));
    3.13 +		}
    3.14 +		
    3.15 +		[Test()]
    3.16 +		public void TestGettingSectionLineValueOnLineInSectionReturnsValue()
    3.17 +		{
    3.18 +			IniSection section = new MockIniSectionWithOneLine();
    3.19 +			Assert.AreEqual(MockIniSectionWithOneLine.VALUE, section.GetLineValue(MockIniSectionWithOneLine.KEY_NAME));
    3.20 +		}
    3.21 +		
    3.22 +		[Test()]
    3.23 +		public void TestGettingSectionLineValueOnNonExistantLineInSectionReturnsDefaultValue()
    3.24 +		{
    3.25 +			IniSection section = new MockIniSectionWithOneLine();
    3.26 +			Assert.AreEqual("default-value", section.GetLineValue("b", "default-value"));
    3.27 +		}
    3.28 +		
    3.29 +		[Test()]
    3.30 +		public void TestGettingSectionLineValueOnLineInSectionDoesNotReturnDefault()
    3.31 +		{
    3.32 +			IniSection section = new MockIniSectionWithOneLine();
    3.33 +			Assert.AreEqual(MockIniSectionWithOneLine.VALUE, section.GetLineValue(MockIniSectionWithOneLine.KEY_NAME, "default-value"));
    3.34 +		}
    3.35  	}
    3.36  }
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/MockIniFileWithOneSectionAndOneLine.cs	Sat Feb 21 10:57:23 2009 +0000
     4.3 @@ -0,0 +1,21 @@
     4.4 +//  This file (MockIniFileWithOneSectionAndOneLine.cs) is a part of IBBoard.Ini.Tests project and is copyright 2009 IBBoard
     4.5 +// 
     4.6 +//  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.
     4.7 +// 
     4.8 +
     4.9 +using System;
    4.10 +
    4.11 +namespace IBBoard.Ini
    4.12 +{
    4.13 +	public class MockIniFileWithOneSectionAndOneLine : IniFile
    4.14 +	{
    4.15 +		public static readonly string SECTION_NAME = MockIniSectionWithOneLine.SECTION_NAME;
    4.16 +		public static readonly string KEY_NAME = MockIniSectionWithOneLine.KEY_NAME;
    4.17 +		public static readonly string VALUE = MockIniSectionWithOneLine.VALUE;
    4.18 +		
    4.19 +		public MockIniFileWithOneSectionAndOneLine()
    4.20 +		{
    4.21 +			AddSection(new MockIniSectionWithOneLine());
    4.22 +		}
    4.23 +	}
    4.24 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/MockIniSectionWithOneLine.cs	Sat Feb 21 10:57:23 2009 +0000
     5.3 @@ -0,0 +1,21 @@
     5.4 +//  This file (MockIniSectionWithOneLine.cs) is a part of [PROJECT NAME] and is copyright 2009 IBBoard
     5.5 +// 
     5.6 +//  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.7 +// 
     5.8 +
     5.9 +using System;
    5.10 +
    5.11 +namespace IBBoard.Ini
    5.12 +{
    5.13 +	public class MockIniSectionWithOneLine : IniSection
    5.14 +	{		
    5.15 +		public static readonly string SECTION_NAME = "section";
    5.16 +		public static readonly string KEY_NAME = "key";
    5.17 +		public static readonly string VALUE = "value";
    5.18 +		
    5.19 +		public MockIniSectionWithOneLine() : base(SECTION_NAME)
    5.20 +		{
    5.21 +			AddIniLine(new IniKeyValuePairLine(KEY_NAME, VALUE));
    5.22 +		}
    5.23 +	}
    5.24 +}