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 62221475c572
children
line wrap: on
line source

// This file (IniSectionTest.cs) is a part of the IBBoard.Ini.Tests library 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;
using NUnit.Framework;

namespace IBBoard.Ini
{
	[TestFixture()]
	public class IniSectionTest
	{
		[Test()]
		public void TestAddingCommentLineDoesNotAddKeyItem()
		{
			IniSection section = new IniSection("someName");
			section.AddIniLine(new IniCommentLine("something"));
			Assert.AreEqual(0, section.Keys.Length);
		}
		
		[Test()]
		public void TestAddingBlankLineDoesNotAddKeyItem()
		{
			IniSection section = new IniSection("someName");
			section.AddIniLine(new IniBlankLine());
			Assert.AreEqual(0, section.Keys.Length);
		}
		
		[Test()]
		public void TestAddingKeyValuePairLineAddsKeyItem()
		{
			IniSection section = new IniSection("someName");
			IniKeyValuePairLine line = new IniKeyValuePairLine("something", "value");
			section.AddIniLine(line);
			Assert.AreEqual(1, section.Keys.Length);
			Assert.AreEqual(line, section["something"]);
		}
		
		[Test()]
		[ExpectedException("IBBoard.Ini.DuplicateIniLineException")]
		public void TestAddingKeyValuePairLineExceptionsOnDuplicateKey()
		{
			IniSection section = new IniSection("someName");
			IniKeyValuePairLine line = new IniKeyValuePairLine("something", "value");
			section.AddIniLine(line);
			line = new IniKeyValuePairLine("something", "different");
			section.AddIniLine(line);
		}
		
		[Test()]
		[ExpectedException("IBBoard.Ini.DuplicateIniLineException")]
		public void TestAddingKeyValuePairLineExceptionsOnDuplicateKeyWithDifferentCase()
		{
			IniSection section = new IniSection("someName");
			IniKeyValuePairLine line = new IniKeyValuePairLine("something", "value");
			section.AddIniLine(line);
			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 TestGettingSectionLineValueOnLineInSectionWithDifferentCaseReturnsValue()
		{
			IniSection section = new MockIniSectionWithOneLine();
			Assert.AreEqual(MockIniSectionWithOneLine.VALUE, section.GetLineValue(MockIniSectionWithOneLine.KEY_NAME.ToUpper()));
		}
		
		[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"));
		}
	}
}