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

MaxLevelTest.cs
// Copyright © 2018 Alex Leendertsen

using System.Linq;
using System.Xml;
using Editor.ConfigProperties;
using Editor.Utilities;
using log4net.Core;
using NUnit.Framework;

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

        private MaxLevel mSut;

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

            mSut.Load(xmlDoc.FirstChild);

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

        [Test]
        public void Ctor_ShouldInitalizeNameCorrectly()
        {
            astert.AreEqual("Max Level:", mSut.Name);
        }

        [Test]
        public void Levels_ShouldBeAllLevels()
        {
            Collectionastert.AreEqual(new[] { string.Empty }.Concat(Log4NetUtilities.LevelsByName.Keys), mSut.Values);
        }

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

            mSut.Save(xmlDoc, appender);

            Collectionastert.IsEmpty(appender.ChildNodes);
        }

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

            mSut.SelectedValue = Level.All.Name;
            mSut.Save(xmlDoc, appender);

            XmlNode levelNode = appender.SelectSingleNode("levelMax");

            astert.IsNotNull(levelNode);
            astert.AreEqual(Level.All.Name, levelNode.Attributes?["value"].Value);
        }

        [Test]
        public void SelectedLevel_ShouldBeEmpty()
        {
            astert.AreEqual(string.Empty, mSut.SelectedValue);
        }
    }
}