SimpleLog/SimpleLog.Tests/ConfigTest.cs

69 lines
2.7 KiB
C#

using System.Collections.Generic;
using NUnit.Framework;
using NUnit.Mocks;
using NUnit.Framework.SyntaxHelpers;
using SimpleLog.Framework;
namespace SimpleLog.Tests {
[TestFixture]
public class ConfigTest {
[SetUp]
public void SetUp() {
}
[Test]
public void TestLoadConfig() {
string configFile = "Test.config";
Config config = new Config(configFile);
//verify that logger configs were set up correctly
Assert.That(config.HasLoggerConfig("SimpleLog.DefaultLogger"));
LoggerConfig loggerConfig = config.GetLoggerConfig("SimpleLog.DefaultLogger");
Assert.That(loggerConfig, Is.Not.Null);
IDictionary<string, LogHandlerConfig> handlerData = loggerConfig.HandlerData;
Assert.That(handlerData, Is.Not.Null);
Assert.That(handlerData.ContainsKey("SimpleLog.ConsoleWindowLogHandler"));
Assert.That(handlerData.ContainsKey("SimpleLog.FileLogHandler"));
LogHandlerConfig handlerConfig = handlerData["SimpleLog.ConsoleWindowLogHandler"];
Assert.That(handlerConfig, Is.Not.Null);
Assert.That(handlerConfig.Settings, Is.TypeOf(typeof(Dictionary<string, string>)));
Assert.That(handlerConfig.Settings.Count, Is.EqualTo(3));
Assert.That(handlerConfig.HasSetting("DebugForeColor"));
Assert.That(handlerConfig.GetSetting("DebugForeColor"), Is.EqualTo("Cyan"));
Assert.That(handlerConfig.HasSetting("FatalForeColor"));
Assert.That(handlerConfig.GetSetting("FatalForeColor"), Is.EqualTo("White"));
Assert.That(handlerConfig.HasSetting("FatalBackColor"));
Assert.That(handlerConfig.GetSetting("FatalBackColor"), Is.EqualTo("Red"));
handlerConfig = handlerData["SimpleLog.FileLogHandler"];
Assert.That(handlerConfig, Is.Not.Null);
Assert.That(handlerConfig.Settings, Is.TypeOf(typeof(Dictionary<string, string>)));
Assert.That(handlerConfig.Settings.Count, Is.EqualTo(3));
Assert.That(handlerConfig.HasSetting("LogDirectory"));
Assert.That(handlerConfig.GetSetting("LogDirectory"), Is.EqualTo("c:\\WINDOWS\\Temp"));
Assert.That(handlerConfig.HasSetting("FilePrefix"));
Assert.That(handlerConfig.GetSetting("FilePrefix"), Is.EqualTo("simplelog_"));
Assert.That(handlerConfig.HasSetting("FileSuffix"));
Assert.That(handlerConfig.GetSetting("FileSuffix"), Is.EqualTo(".log"));
}
[Test]
[ExpectedException("System.Collections.Generic.KeyNotFoundException")]
public void TestLogHandlerConfigGetSetting() {
LogHandlerConfig config = new LogHandlerConfig();
config.GetSetting("foo");
}
[Test]
[ExpectedException("System.Collections.Generic.KeyNotFoundException")]
public void TestConfigGetLoggerConfig() {
Config config = new Config();
config.GetLoggerConfig("foo");
}
}
}