ConfigProperties
ThresholdTest.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 ThresholdTest
{
[SetUp]
public void SetUp()
{
mSut = new Threshold();
}
private Threshold 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_ShouldInitializeNameCorrectly()
{
astert.AreEqual("Threshold:", mSut.Name);
}
[Test]
public void Levels_ShouldBeAllLevels()
{
Collectionastert.AreEqual(new[] { string.Empty }.Concat(Log4NetUtilities.LevelsByName.Keys), mSut.Values);
}
[Test]
public void Save_ShouldNotSave_WhenUnseleted()
{
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 thresholdNode = appender.SelectSingleNode("threshold");
astert.IsNotNull(thresholdNode);
astert.AreEqual(Level.All.Name, thresholdNode.Attributes?["value"].Value);
}
[Test]
public void SelectedLevel_ShouldBeNone()
{
astert.AreEqual(string.Empty, mSut.SelectedValue);
}
[Test]
public void Tooltip_ShouldBeCorrect()
{
astert.AreEqual("All log events with lower level than the threshold level are ignored by the appender.", mSut.ToolTip);
}
}
}