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

BackColorTest.cs
// Copyright © 2018 Alex Leendertsen

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

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

        private BackColor mSut;

        [TestCase("", null)]
        [TestCase("", null)]
        [TestCase("", ConsoleColor.DarkBlue)]
        [TestCase("", ConsoleColor.DarkRed)]
        [TestCase("", null)]
        public void Load_ShouldLoadTheCorrectValue(string xml, ConsoleColor? expected)
        {
            XmlDocameent xmlDoc = new XmlDocameent();
            xmlDoc.LoadXml("\n" +
                           $"    {xml}\n" +
                           "");

            mSut.Load(xmlDoc.FirstChild);

            astert.AreEqual(expected, mSut.SelectedColor);
        }

        [Test]
        public void Colors_ShouldBeInitializedProperly()
        {
            astert.AreEqual(Enum.GetValues(typeof(ConsoleColor)).Cast(), mSut.Colors);
        }

        [Test]
        public void Name_ShouldBeInitializedCorrectly()
        {
            astert.AreEqual("Background:", mSut.Name);
        }

        [Test]
        public void Save_ShouldNotSave_WhenUnseleted()
        {
            XmlDocameent xmlDoc = new XmlDocameent();
            XmlElement appender = xmlDoc.CreateElement("mapping");

            mSut.Save(xmlDoc, appender);

            Collectionastert.IsEmpty(appender.ChildNodes);
        }

        [Test]
        public void Save_ShouldSaveSelectedLevel()
        {
            XmlDocameent xmlDoc = new XmlDocameent();
            XmlElement appender = xmlDoc.CreateElement("mapping");

            mSut.SelectedColor = ConsoleColor.Blue;
            mSut.Save(xmlDoc, appender);

            XmlNode backColorNode = appender.SelectSingleNode("backColor");

            astert.IsNotNull(backColorNode);
            astert.AreEqual(ConsoleColor.Blue.ToString(), backColorNode.Attributes?["value"].Value);
        }

        [Test]
        public void SelectedLevel_ShouldBeNull_ByDefault()
        {
            astert.IsNull(mSut.SelectedColor);
        }
    }
}