2018-10-12 15:23:43 +02:00
|
|
|
|
/*
|
2019-01-09 11:25:21 +01:00
|
|
|
|
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
|
2018-10-12 15:23:43 +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/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using Moq;
|
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
2019-02-12 10:34:39 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Configuration.Settings;
|
2018-10-12 15:23:43 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Core.OperationModel;
|
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
|
|
|
|
using SafeExamBrowser.Runtime.Operations;
|
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class SessionActivationOperationTests
|
|
|
|
|
{
|
|
|
|
|
private Mock<ISessionConfiguration> currentSession;
|
|
|
|
|
private Mock<ILogger> logger;
|
|
|
|
|
private Mock<ISessionConfiguration> nextSession;
|
2019-02-12 10:34:39 +01:00
|
|
|
|
private Settings nextSettings;
|
2018-10-12 15:23:43 +02:00
|
|
|
|
private SessionContext sessionContext;
|
|
|
|
|
|
|
|
|
|
private SessionActivationOperation sut;
|
|
|
|
|
|
|
|
|
|
[TestInitialize]
|
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
|
|
|
|
currentSession = new Mock<ISessionConfiguration>();
|
|
|
|
|
logger = new Mock<ILogger>();
|
|
|
|
|
nextSession = new Mock<ISessionConfiguration>();
|
2019-02-12 10:34:39 +01:00
|
|
|
|
nextSettings = new Settings();
|
2018-10-12 15:23:43 +02:00
|
|
|
|
sessionContext = new SessionContext();
|
|
|
|
|
|
2019-02-12 10:34:39 +01:00
|
|
|
|
nextSession.SetupGet(s => s.Settings).Returns(nextSettings);
|
2018-10-12 15:23:43 +02:00
|
|
|
|
sessionContext.Current = currentSession.Object;
|
|
|
|
|
sessionContext.Next = nextSession.Object;
|
|
|
|
|
|
|
|
|
|
sut = new SessionActivationOperation(logger.Object, sessionContext);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2019-02-26 10:07:41 +01:00
|
|
|
|
public void Perform_MustCorrectlyActivateFirstSession()
|
2018-10-12 15:23:43 +02:00
|
|
|
|
{
|
|
|
|
|
sessionContext.Current = null;
|
|
|
|
|
|
|
|
|
|
var result = sut.Perform();
|
|
|
|
|
|
|
|
|
|
currentSession.VerifyNoOtherCalls();
|
|
|
|
|
nextSession.VerifyGet(s => s.Id);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(OperationResult.Success, result);
|
|
|
|
|
Assert.AreSame(sessionContext.Current, nextSession.Object);
|
|
|
|
|
Assert.IsNull(sessionContext.Next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2019-02-26 10:07:41 +01:00
|
|
|
|
public void Perform_MustCorrectlySwitchLogSeverity()
|
|
|
|
|
{
|
|
|
|
|
nextSettings.LogLevel = LogLevel.Info;
|
|
|
|
|
|
|
|
|
|
sut.Perform();
|
|
|
|
|
|
|
|
|
|
logger.VerifySet(l => l.LogLevel = It.Is<LogLevel>(ll => ll == nextSettings.LogLevel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Repeat_MustCorrectlySwitchSession()
|
2018-10-12 15:23:43 +02:00
|
|
|
|
{
|
|
|
|
|
var result = sut.Repeat();
|
|
|
|
|
|
|
|
|
|
currentSession.VerifyGet(s => s.Id);
|
|
|
|
|
nextSession.VerifyGet(s => s.Id);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(OperationResult.Success, result);
|
|
|
|
|
Assert.AreSame(sessionContext.Current, nextSession.Object);
|
|
|
|
|
Assert.IsNull(sessionContext.Next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2019-02-26 10:07:41 +01:00
|
|
|
|
public void Repeat_MustCorrectlySwitchLogSeverity()
|
|
|
|
|
{
|
|
|
|
|
nextSettings.LogLevel = LogLevel.Warning;
|
|
|
|
|
|
|
|
|
|
sut.Perform();
|
|
|
|
|
|
|
|
|
|
logger.VerifySet(l => l.LogLevel = It.Is<LogLevel>(ll => ll == nextSettings.LogLevel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Revert_MustAlwaysCompleteSuccessfully()
|
2018-10-12 15:23:43 +02:00
|
|
|
|
{
|
|
|
|
|
var result = sut.Revert();
|
|
|
|
|
|
|
|
|
|
currentSession.VerifyNoOtherCalls();
|
|
|
|
|
nextSession.VerifyNoOtherCalls();
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(OperationResult.Success, result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|