Mercurial > repos > IBBoard.Ini.Tests
view IniFileTest.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 (IniFileTest.cs) is a part of 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 IniFileTest { [Test()] public void TestAddingSectionMakesSectionAvailable() { IniFile file = new IniFile(); IniSection section = new IniSection("section"); file.AddSection(section); Assert.AreEqual(1, file.Sections.Length); Assert.IsTrue(file.HasSection("section")); Assert.AreEqual(section, file["section"]); } [Test()] [ExpectedException("IBBoard.Ini.DuplicateIniSectionException")] public void TestAddingDuplicateSectionThrowsDuplicateSectionException() { IniFile file = new IniFile(); file.AddSection(new IniSection("key")); file.AddSection(new IniSection("key")); } [Test()] [ExpectedException("IBBoard.Ini.DuplicateIniSectionException")] public void TestAddingDuplicateSectionWithDifferentNameCaseThrowsDuplicateSectionException() { IniFile file = new IniFile(); file.AddSection(new IniSection("key")); file.AddSection(new IniSection("KEY")); } [Test()] public void TestGettingNonExistantSectionDoesNotReturnNull() { IniFile file = new IniFile(); 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 TestGettingSectionLineValueOnLineInSectionWithDifferentSectionNameCaseReturnsValue() { IniFile file = new MockIniFileWithOneSectionAndOneLine(); Assert.AreEqual(MockIniFileWithOneSectionAndOneLine.VALUE, file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME.ToUpper(), MockIniFileWithOneSectionAndOneLine.KEY_NAME)); } [Test()] public void TestGettingSectionLineValueOnLineInSectionWithDifferentLineNameCaseReturnsValue() { IniFile file = new MockIniFileWithOneSectionAndOneLine(); Assert.AreEqual(MockIniFileWithOneSectionAndOneLine.VALUE, file.GetSectionLineValue(MockIniFileWithOneSectionAndOneLine.SECTION_NAME, MockIniFileWithOneSectionAndOneLine.KEY_NAME.ToUpper())); } [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")); } } }