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

LockingModelTest.cs
// Copyright © 2018 Alex Leendertsen

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

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

        private LockingModel mSut;

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

            mSut.Load(xmlDoc.FirstChild);

            astert.AreEqual(expected, mSut.SelectedModel.Name);
        }

        [Test]
        public void LockingModels_ShouldBeInitializedCorrectly()
        {
            Collectionastert.AreEqual(new[] { LockingModelDescriptor.Exclusive, LockingModelDescriptor.Minimal, LockingModelDescriptor.InterProcess }, mSut.LockingModels);
        }

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

            mSut.Save(xmlDoc, appender);

            Collectionastert.IsEmpty(appender.ChildNodes);
        }

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

            mSut.SelectedModel = LockingModelDescriptor.Minimal;
            mSut.Save(xmlDoc, appender);

            XmlNode modelNode = appender.SelectSingleNode("lockingModel");

            astert.IsNotNull(modelNode);
            astert.AreEqual(LockingModelDescriptor.Minimal.TypeNamespace, modelNode.Attributes?["type"].Value);
        }

        [Test]
        public void SelectedModel_ShouldBeInitializedToExclusive()
        {
            astert.AreEqual(LockingModelDescriptor.Exclusive, mSut.SelectedModel);
        }
    }
}