view IniFileReaderTest.cs @ 0:ada654b0648c

Re #7 - add IBBoard.Ini test\n * Add initial tests
author IBBoard <dev@ibboard.co.uk>
date Mon, 12 Jan 2009 20:41:45 +0000
parents
children c2a0d074b3b5
line wrap: on
line source

// This file (IniFileReaderTest.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. Please see COPYING.LGPL for more information and the full license.

using System;
using System.IO;
using NUnit.Framework;

namespace IBBoard.Ini
{
	[TestFixture()]
	public class IniFileReaderTest
	{
		[Test()]
		public void TestIniFileReaderReturnsEmptyObjectForEmptyIniText()
		{
			IniFile file = IniFileReader.ReadFile("");
			Assert.AreEqual(0, file.Sections.Length);
		}

		
		[Test()]
		public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniText()
		{
			IniFile file = IniFileReader.ReadFile("[ASection]");
			Assert.AreEqual(1, file.Sections.Length);
			Assert.IsTrue(file.HasSection("ASection"));
			Assert.IsNotNull(file["ASection"]);
			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
		}
		
		[Test()]
		public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniTextWithContent()
		{
			IniFile file = IniFileReader.ReadFile("[ASection]\nsomething=fibble");
			Assert.AreEqual(1, file.Sections.Length);
			Assert.IsTrue(file.HasSection("ASection"));
			Assert.IsNotNull(file["ASection"]);
			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
		}
		
		[Test()]
		public void TestIniFileReaderContainsExpectedSectionForTwoSectionIniTextWithContent()
		{
			IniFile file = IniFileReader.ReadFile("[ASection]\nsomething=fibble\n[BSection]\nsomethingElse=fibble");
			Assert.AreEqual(2, file.Sections.Length);
			Assert.IsTrue(file.HasSection("ASection"));
			Assert.IsNotNull(file["ASection"]);
			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
			Assert.IsTrue(file.HasSection("BSection"));
			Assert.IsNotNull(file["BSection"]);
			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["BSection"]);
		}
		
		[Test()]
		public void TestIniFileReaderReturnsEmptyObjectForEmptyIniFile()
		{
			IniFile file = IniFileReader.ReadFile(new FileInfo("EmptyFile.ini"));
			Assert.AreEqual(0, file.Sections.Length);
		}

		
		[Test()]
		public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniFile()
		{
			IniFile file = IniFileReader.ReadFile(new FileInfo("SingleSectionSingleLine.ini"));
			Assert.AreEqual(1, file.Sections.Length);
			Assert.IsTrue(file.HasSection("ASection"));
			Assert.IsNotNull(file["ASection"]);
			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
		}
		
		[Test()]
		public void TestIniFileReaderContainsExpectedSectionForSingleSectionIniFileWithContent()
		{
			IniFile file = IniFileReader.ReadFile(new FileInfo("SingleSectionWithContent.ini"));
			Assert.AreEqual(1, file.Sections.Length);
			Assert.IsTrue(file.HasSection("ASection"));
			Assert.IsNotNull(file["ASection"]);
			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
		}
		
		[Test()]
		public void TestIniFileReaderContainsExpectedSectionForTwoSectionIniFileWithContent()
		{
			IniFile file = IniFileReader.ReadFile(new FileInfo("DoubleSectionWithContent.ini"));
			Assert.AreEqual(2, file.Sections.Length);
			Assert.IsTrue(file.HasSection("ASection"));
			Assert.IsNotNull(file["ASection"]);
			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["ASection"]);
			Assert.IsTrue(file.HasSection("BSection"));
			Assert.IsNotNull(file["BSection"]);
			Assert.IsNotInstanceOfType(typeof(NonExistantIniSection), file["BSection"]);
		}
	}
}