SimpleLog/SimpleLog.Tests/DefaultMessageHandlerTest.cs

45 lines
1.3 KiB
C#

using System;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
namespace SimpleLog.Tests {
[TestFixture]
public class DefaultMessageHandlerTest {
private DefaultMessageHandler messageHandler;
[SetUp]
public void Init() {
this.messageHandler = new DefaultMessageHandler();
}
[Test]
public void TestConvertMessageToStringWithException() {
Exception e = new Exception("yay!");
Assert.That(this.messageHandler.ConvertMessageToString(e), Text.StartsWith("yay!\n"));
}
[Test]
public void TestConvertMessageToString() {
string message = "yay!";
Assert.That(this.messageHandler.ConvertMessageToString(message), Text.Matches("yay!"));
object obj = "yay!";
Assert.That(this.messageHandler.ConvertMessageToString(obj), Text.Matches("yay!"));
}
[Test]
public void TestConstructLogMessage() {
this.messageHandler.DateFormat = "yyyy-MM-dd HH:mm:ss";
this.messageHandler.Delimiter = " ";
this.messageHandler.Context = "some kind of context";
string expected = "\\d{4}-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d ";
expected += "WARNING ";
expected += "\\[some kind of context\\] ";
expected += "log message\n";
Assert.That(this.messageHandler.FormatLogMessage("log message", Framework.LogLevel.Warning), Text.Matches(expected));
}
}
}