SEBWIN-183: Added missing test conditions for loggers.

This commit is contained in:
dbuechel 2017-10-11 07:38:25 +02:00
parent f952904cf0
commit 1cb388b754
2 changed files with 22 additions and 1 deletions

View file

@ -25,14 +25,21 @@ namespace SafeExamBrowser.Core.UnitTests.Logging
var info = "I'm an info message";
var warn = "I'm a warning!";
var error = "I AM AN ERROR!!";
var exceptionMessage = "I'm an exception message";
var exception = new Exception(exceptionMessage);
var message = "I'm a simple text message";
var content = new LogText("I'm some raw log text...");
sut.Info(info);
sut.Warn(warn);
sut.Error(error);
sut.Error(error, exception);
sut.Log(message);
sut.Log(content);
var log = sut.GetLog();
Assert.IsTrue(log.Count == 3);
Assert.IsTrue(log.Count == 7);
Assert.IsTrue(info.Equals((log[0] as ILogMessage).Message));
Assert.IsTrue((log[0] as ILogMessage).Severity == LogLevel.Info);
@ -42,6 +49,14 @@ namespace SafeExamBrowser.Core.UnitTests.Logging
Assert.IsTrue(error.Equals((log[2] as ILogMessage).Message));
Assert.IsTrue((log[2] as ILogMessage).Severity == LogLevel.Error);
Assert.IsTrue(error.Equals((log[3] as ILogMessage).Message));
Assert.IsTrue((log[3] as ILogMessage).Severity == LogLevel.Error);
Assert.IsTrue((log[4] as ILogText).Text.Contains(exceptionMessage));
Assert.IsTrue(message.Equals((log[5] as ILogText).Text));
Assert.IsTrue(content.Text.Equals((log[6] as ILogText).Text));
}
[TestMethod]
@ -76,6 +91,8 @@ namespace SafeExamBrowser.Core.UnitTests.Logging
Assert.ThrowsException<ArgumentNullException>(() => sut.Warn(null));
Assert.ThrowsException<ArgumentNullException>(() => sut.Error(null));
Assert.ThrowsException<ArgumentNullException>(() => sut.Error(null, null));
Assert.ThrowsException<ArgumentNullException>(() => sut.Error("Hello world!", null));
Assert.ThrowsException<ArgumentNullException>(() => sut.Error(null, new Exception()));
Assert.ThrowsException<ArgumentNullException>(() => sut.Log((string) null));
Assert.ThrowsException<ArgumentNullException>(() => sut.Log((ILogContent) null));
}

View file

@ -6,6 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using SafeExamBrowser.Contracts.Logging;
@ -19,6 +20,7 @@ namespace SafeExamBrowser.Core.UnitTests.Logging
[TestMethod]
public void MustCorrectlyForwardCalls()
{
var exception = new Exception();
var loggerMock = new Mock<ILogger>();
var logObserverMock = new Mock<ILogObserver>();
var logText = new LogText("Log text");
@ -27,6 +29,7 @@ namespace SafeExamBrowser.Core.UnitTests.Logging
sut.Info("Info");
sut.Warn("Warning");
sut.Error("Error");
sut.Error("Error", exception);
sut.Log("Raw text");
sut.Log(logText);
sut.Subscribe(logObserverMock.Object);
@ -36,6 +39,7 @@ namespace SafeExamBrowser.Core.UnitTests.Logging
loggerMock.Verify(l => l.Info($"[{nameof(ModuleLoggerTests)}] Info"), Times.Once);
loggerMock.Verify(l => l.Warn($"[{nameof(ModuleLoggerTests)}] Warning"), Times.Once);
loggerMock.Verify(l => l.Error($"[{nameof(ModuleLoggerTests)}] Error"), Times.Once);
loggerMock.Verify(l => l.Error($"[{nameof(ModuleLoggerTests)}] Error", exception), Times.Once);
loggerMock.Verify(l => l.Log("Raw text"), Times.Once);
loggerMock.Verify(l => l.Log(logText), Times.Once);
loggerMock.Verify(l => l.Subscribe(logObserverMock.Object), Times.Once);