2017-10-10 15:44:04 +02:00
|
|
|
|
/*
|
2019-01-09 11:25:21 +01:00
|
|
|
|
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
|
2017-10-10 15:44:04 +02:00
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-10-11 07:38:25 +02:00
|
|
|
|
using System;
|
2017-10-10 15:44:04 +02:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using Moq;
|
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
|
|
|
|
|
2018-08-31 10:06:27 +02:00
|
|
|
|
namespace SafeExamBrowser.Logging.UnitTests
|
2017-10-10 15:44:04 +02:00
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class ModuleLoggerTests
|
|
|
|
|
{
|
2018-08-31 15:29:36 +02:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustCorrectlyClone()
|
|
|
|
|
{
|
|
|
|
|
var loggerMock = new Mock<ILogger>();
|
|
|
|
|
var sut = new ModuleLogger(loggerMock.Object, nameof(ModuleLoggerTests));
|
|
|
|
|
var clone = sut.CloneFor("blubb");
|
|
|
|
|
|
|
|
|
|
sut.Debug("Debug");
|
|
|
|
|
clone.Debug("Debug");
|
|
|
|
|
|
|
|
|
|
loggerMock.Verify(l => l.Debug($"[{nameof(ModuleLoggerTests)}] Debug"), Times.Once);
|
|
|
|
|
loggerMock.Verify(l => l.Debug($"[blubb] Debug"), Times.Once);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 15:44:04 +02:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MustCorrectlyForwardCalls()
|
|
|
|
|
{
|
2017-10-11 07:38:25 +02:00
|
|
|
|
var exception = new Exception();
|
2017-10-10 15:44:04 +02:00
|
|
|
|
var loggerMock = new Mock<ILogger>();
|
|
|
|
|
var logObserverMock = new Mock<ILogObserver>();
|
|
|
|
|
var logText = new LogText("Log text");
|
2018-08-31 15:29:36 +02:00
|
|
|
|
var sut = new ModuleLogger(loggerMock.Object, nameof(ModuleLoggerTests));
|
2017-10-10 15:44:04 +02:00
|
|
|
|
|
2018-03-14 15:27:11 +01:00
|
|
|
|
sut.Debug("Debug");
|
2017-10-10 15:44:04 +02:00
|
|
|
|
sut.Info("Info");
|
|
|
|
|
sut.Warn("Warning");
|
|
|
|
|
sut.Error("Error");
|
2017-10-11 07:38:25 +02:00
|
|
|
|
sut.Error("Error", exception);
|
2017-10-10 15:44:04 +02:00
|
|
|
|
sut.Log("Raw text");
|
|
|
|
|
sut.Subscribe(logObserverMock.Object);
|
|
|
|
|
sut.Unsubscribe(logObserverMock.Object);
|
|
|
|
|
sut.GetLog();
|
|
|
|
|
|
2018-03-14 15:27:11 +01:00
|
|
|
|
loggerMock.Verify(l => l.Debug($"[{nameof(ModuleLoggerTests)}] Debug"), Times.Once);
|
2017-10-10 15:44:04 +02:00
|
|
|
|
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);
|
2017-10-11 07:38:25 +02:00
|
|
|
|
loggerMock.Verify(l => l.Error($"[{nameof(ModuleLoggerTests)}] Error", exception), Times.Once);
|
2017-10-10 15:44:04 +02:00
|
|
|
|
loggerMock.Verify(l => l.Log("Raw text"), Times.Once);
|
|
|
|
|
loggerMock.Verify(l => l.Subscribe(logObserverMock.Object), Times.Once);
|
|
|
|
|
loggerMock.Verify(l => l.Unsubscribe(logObserverMock.Object), Times.Once);
|
|
|
|
|
loggerMock.Verify(l => l.GetLog(), Times.Once);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|