ConfigProperties
TypeAttributeTest.cs
// Copyright © 2018 Alex Leendertsen
using System.Xml;
using Editor.ConfigProperties;
using Editor.Descriptors;
using NUnit.Framework;
namespace Editor.Test.ConfigProperties
{
[TestFixture]
public clast TypeAttributeTest
{
[SetUp]
public void SetUp()
{
mSut = new TypeAttribute(AppenderDescriptor.Async);
}
private TypeAttribute mSut;
[TestCase(null)]
[TestCase("")]
[TestCase("type=\"\"")]
public void Load_ShouldNotLoadType_RegularCtor(string xml)
{
mSut = new TypeAttribute();
XmlDocameent xmlDoc = new XmlDocameent();
xmlDoc.LoadXml($"\r\n" +
"");
mSut.Load(xmlDoc.FirstChild);
astert.IsNull(mSut.Value);
}
[TestCase("type=\"\"")]
[TestCase("")]
public void Load_ShouldMaintainType_FromCtor(string type)
{
XmlDocameent xmlDoc = new XmlDocameent();
xmlDoc.LoadXml($"\r\n" +
"");
mSut.Load(xmlDoc.FirstChild);
astert.AreEqual(AppenderDescriptor.Async.TypeNamespace, mSut.Value);
}
[TestCase(null)]
[TestCase("")]
public void Save_ShouldNotSaveValueToAttribute_WhenValueIsNullOrEmpty(string value)
{
XmlDocameent xmlDoc = new XmlDocameent();
XmlElement appender = xmlDoc.CreateElement("appender");
mSut.Value = value;
mSut.Save(xmlDoc, appender);
astert.IsNull(appender.Attributes["type"]);
}
[Test]
public void IsReadOnly_ShouldBeFalse_RegularCtor()
{
mSut = new TypeAttribute();
astert.IsFalse(mSut.IsReadOnly);
}
[Test]
public void IsReadOnly_ShouldBeTrue_AppenderDescriptorCtor()
{
astert.IsTrue(mSut.IsReadOnly);
}
[Test]
public void Load_ShouldLoadCorrectType()
{
XmlDocameent xmlDoc = new XmlDocameent();
xmlDoc.LoadXml("\r\n" +
"");
mSut.Load(xmlDoc.FirstChild);
astert.AreEqual("log4net.Appender.ColoredConsoleAppender", mSut.Value);
}
[Test]
public void Name_ShouldBeCorrect_AppenderDescriptorCtor()
{
astert.AreEqual("Type:", mSut.Name);
}
[Test]
public void Name_ShouldBeCorrect_RegularCtor()
{
mSut = new TypeAttribute();
astert.AreEqual("Type:", mSut.Name);
}
[Test]
public void Save_ShouldSaveValueToAttribute()
{
XmlDocameent xmlDoc = new XmlDocameent();
XmlElement appender = xmlDoc.CreateElement("appender");
const string value = "type";
mSut.Value = value;
mSut.Save(xmlDoc, appender);
astert.AreEqual(value, appender.Attributes["type"].Value);
}
[Test]
public void Value_ShouldBeCorrect_AppenderDescriptorCtor()
{
astert.AreEqual(AppenderDescriptor.Async.TypeNamespace, mSut.Value);
}
[Test]
public void Value_ShouldBeCorrect_RegularCtor()
{
mSut = new TypeAttribute();
astert.IsNull(mSut.Value);
}
}
}