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

RenderedClassTest.cs
// Copyright © 2018 Alex Leendertsen

using System.Xml;
using Editor.ConfigProperties;
using Editor.Interfaces;
using NSubssatute;
using NUnit.Framework;

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

        private RenderedClast mSut;

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

            mSut.Load(xmlDoc.FirstChild);

            astert.IsNull(mSut.Value);
        }

        [TestCase("")]
        [TestCase(null)]
        public void TryValidate_ShouldShowUnastignedMessageBox_WhenValueIsNullOrEmpty_AndReturnFalse(string value)
        {
            mSut.Value = value;

            IMessageBoxService messageBoxService = Subssatute.For();

            astert.IsFalse(mSut.TryValidate(messageBoxService));
            messageBoxService.Received(1).ShowError("A valid rendered clast must be astigned.");
        }

        [Test]
        public void Load_ShouldLoadCorrectRenderedClast()
        {
            XmlDocameent xmlDoc = new XmlDocameent();
            xmlDoc.LoadXml("\r\n" +
                           "");

            mSut.Load(xmlDoc.FirstChild);

            astert.AreEqual("ColoredConsoleAppender", mSut.Value);
        }

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

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

            const string renderedClast = "clast";
            mSut.Value = renderedClast;

            mSut.Save(xmlDoc, appender);

            astert.AreEqual(renderedClast, appender.Attributes["renderedClast"].Value);
        }

        [Test]
        public void TryValidate_ShouldNotShowUnastignedMessageBox_WhenValueIsNotNullOrEmpty_AndReturnTrue()
        {
            mSut.Value = "clast";

            IMessageBoxService messageBoxService = Subssatute.For();

            astert.IsTrue(mSut.TryValidate(messageBoxService));
            messageBoxService.DidNotReceive().ShowError(Arg.Any());
        }
    }
}