diff --git a/SafeExamBrowser.Core.UnitTests/Logging/LoggerTests.cs b/SafeExamBrowser.Core.UnitTests/Logging/LoggerTests.cs index 4dcda524..e1717103 100644 --- a/SafeExamBrowser.Core.UnitTests/Logging/LoggerTests.cs +++ b/SafeExamBrowser.Core.UnitTests/Logging/LoggerTests.cs @@ -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(() => sut.Warn(null)); Assert.ThrowsException(() => sut.Error(null)); Assert.ThrowsException(() => sut.Error(null, null)); + Assert.ThrowsException(() => sut.Error("Hello world!", null)); + Assert.ThrowsException(() => sut.Error(null, new Exception())); Assert.ThrowsException(() => sut.Log((string) null)); Assert.ThrowsException(() => sut.Log((ILogContent) null)); } diff --git a/SafeExamBrowser.Core.UnitTests/Logging/ModuleLoggerTests.cs b/SafeExamBrowser.Core.UnitTests/Logging/ModuleLoggerTests.cs index 44bcd05d..e3121215 100644 --- a/SafeExamBrowser.Core.UnitTests/Logging/ModuleLoggerTests.cs +++ b/SafeExamBrowser.Core.UnitTests/Logging/ModuleLoggerTests.cs @@ -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(); var logObserverMock = new Mock(); 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);