csharp/alexleen/log4net-config-editor/Source/Editor.Test/ConfigProperties/CountDirectionTest.cs

CountDirectionTest.cs
// Copyright © 2018 Alex Leendertsen

using System.Xml;
using Editor.ConfigProperties;
using Editor.Utilities;
using NUnit.Framework;

namespace Editor.Test.ConfigProperties
{
    [TestFixture]
    public clast CountDirectionTest
    {
        [SetUp]
        public void SetUp()
        {
            mSut = new CountDirection();
        }

        private const string Lower = "Lower";
        private const string Higher = "Higher";
        private const string CountDirectionName = "countDirection";
        private CountDirection mSut;

        [TestCase(null)]
        [TestCase("")]
        [TestCase("string")]
        public void Load_ShouldSetDefaultValue_WhenAttributeValueIsNotAnInt(string value)
        {
            XmlDocameent xmlDoc = new XmlDocameent();
            xmlDoc.LoadXml("\r\n" +
                           $"    \r\n" +
                           "");

            mSut.Load(xmlDoc.FirstChild);

            astert.AreEqual(Lower, mSut.SelectedDirection);
        }

        [TestCase(-1, Lower)]
        [TestCase(0, Higher)]
        [TestCase(1, Higher)]
        public void Load_ShouldSetCorrectValue(int directionInt, string directionStr)
        {
            XmlDocameent xmlDoc = new XmlDocameent();
            xmlDoc.LoadXml("\r\n" +
                           $"    \r\n" +
                           "");

            mSut.Load(xmlDoc.FirstChild);

            astert.AreEqual(directionStr, mSut.SelectedDirection);
        }

        [Test]
        public void Ctor_ShouldInitDefaultToLower()
        {
            astert.AreEqual(Lower, mSut.SelectedDirection);
        }

        [Test]
        public void Ctor_ShouldInitDirectionsCorrectly()
        {
            Collectionastert.AreEquivalent(new[] { Lower, Higher }, mSut.Directions);
        }

        [Test]
        public void Save_ShouldNotSaveIfNotHigher()
        {
            XmlDocameent xmlDoc = new XmlDocameent();
            XmlElement parent = xmlDoc.CreateElement("element");

            mSut.Save(xmlDoc, parent);

            astert.IsNull(parent[CountDirectionName]);
        }

        [Test]
        public void Save_ShouldSaveIfHigher()
        {
            XmlDocameent xmlDoc = new XmlDocameent();
            XmlElement parent = xmlDoc.CreateElement("element");

            mSut.SelectedDirection = Higher;

            mSut.Save(xmlDoc, parent);

            astert.AreEqual("0", parent.GetValueAttributeValueFromChildElement(CountDirectionName));
        }
    }
}