Update Safe Exam Browser Patch to 3.10.0.826
This commit is contained in:
@@ -16,9 +16,13 @@ using SafeExamBrowser.Communication.Contracts.Hosts;
|
||||
using SafeExamBrowser.Communication.Contracts.Proxies;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Runtime.Operations;
|
||||
using SafeExamBrowser.Runtime.Communication;
|
||||
using SafeExamBrowser.Runtime.Operations.Session;
|
||||
using SafeExamBrowser.Settings;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
||||
using SafeExamBrowser.WindowsApi.Contracts;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
@@ -29,20 +33,24 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
private Action clientReady;
|
||||
private Action terminated;
|
||||
private AppConfig appConfig;
|
||||
private Dependencies dependencies;
|
||||
private Mock<IClientProxy> proxy;
|
||||
private Mock<ILogger> logger;
|
||||
private Mock<IProcess> process;
|
||||
private Mock<IProcessFactory> processFactory;
|
||||
private Mock<IProxyFactory> proxyFactory;
|
||||
private RuntimeContext runtimeContext;
|
||||
private Mock<IRuntimeHost> runtimeHost;
|
||||
private SessionConfiguration session;
|
||||
private SessionContext sessionContext;
|
||||
private AppSettings settings;
|
||||
private ClientOperation sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
runtimeContext = new RuntimeContext();
|
||||
runtimeHost = new Mock<IRuntimeHost>();
|
||||
|
||||
appConfig = new AppConfig();
|
||||
clientReady = new Action(() => runtimeHost.Raise(h => h.ClientReady += null));
|
||||
logger = new Mock<ILogger>();
|
||||
@@ -50,9 +58,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
processFactory = new Mock<IProcessFactory>();
|
||||
proxy = new Mock<IClientProxy>();
|
||||
proxyFactory = new Mock<IProxyFactory>();
|
||||
runtimeHost = new Mock<IRuntimeHost>();
|
||||
session = new SessionConfiguration();
|
||||
sessionContext = new SessionContext();
|
||||
settings = new AppSettings();
|
||||
terminated = new Action(() =>
|
||||
{
|
||||
@@ -63,11 +69,19 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
appConfig.ClientLogFilePath = "";
|
||||
session.AppConfig = appConfig;
|
||||
session.Settings = settings;
|
||||
sessionContext.Current = session;
|
||||
sessionContext.Next = session;
|
||||
runtimeContext.Current = session;
|
||||
runtimeContext.Next = session;
|
||||
|
||||
dependencies = new Dependencies(
|
||||
new ClientBridge(Mock.Of<IRuntimeHost>(), runtimeContext),
|
||||
logger.Object,
|
||||
Mock.Of<IMessageBox>(),
|
||||
Mock.Of<IRuntimeWindow>(),
|
||||
runtimeContext,
|
||||
Mock.Of<IText>());
|
||||
proxyFactory.Setup(f => f.CreateClientProxy(It.IsAny<string>(), It.IsAny<Interlocutor>())).Returns(proxy.Object);
|
||||
|
||||
sut = new ClientOperation(logger.Object, processFactory.Object, proxyFactory.Object, runtimeHost.Object, sessionContext, 0);
|
||||
sut = new ClientOperation(dependencies, processFactory.Object, proxyFactory.Object, runtimeHost.Object, 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -84,8 +98,8 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
result = sut.Perform();
|
||||
|
||||
Assert.AreEqual(process.Object, sessionContext.ClientProcess);
|
||||
Assert.AreEqual(proxy.Object, sessionContext.ClientProxy);
|
||||
Assert.AreEqual(process.Object, runtimeContext.ClientProcess);
|
||||
Assert.AreEqual(proxy.Object, runtimeContext.ClientProxy);
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
}
|
||||
|
||||
@@ -100,7 +114,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var terminateClient = new Action(() => Task.Delay(100).ContinueWith(_ => process.Raise(p => p.Terminated += null, 0)));
|
||||
|
||||
processFactory.Setup(f => f.StartNew(It.IsAny<string>(), It.IsAny<string[]>())).Returns(process.Object).Callback(terminateClient);
|
||||
sut = new ClientOperation(logger.Object, processFactory.Object, proxyFactory.Object, runtimeHost.Object, sessionContext, ONE_SECOND);
|
||||
sut = new ClientOperation(dependencies, processFactory.Object, proxyFactory.Object, runtimeHost.Object, ONE_SECOND);
|
||||
|
||||
before = DateTime.Now;
|
||||
result = sut.Perform();
|
||||
@@ -120,8 +134,8 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
result = sut.Perform();
|
||||
|
||||
Assert.IsNotNull(sessionContext.ClientProcess);
|
||||
Assert.IsNotNull(sessionContext.ClientProxy);
|
||||
Assert.IsNotNull(runtimeContext.ClientProcess);
|
||||
Assert.IsNotNull(runtimeContext.ClientProxy);
|
||||
Assert.AreEqual(OperationResult.Failed, result);
|
||||
}
|
||||
|
||||
@@ -139,8 +153,8 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
result = sut.Perform();
|
||||
|
||||
Assert.IsNotNull(sessionContext.ClientProcess);
|
||||
Assert.IsNotNull(sessionContext.ClientProxy);
|
||||
Assert.IsNotNull(runtimeContext.ClientProcess);
|
||||
Assert.IsNotNull(runtimeContext.ClientProxy);
|
||||
Assert.AreEqual(OperationResult.Failed, result);
|
||||
}
|
||||
|
||||
@@ -158,8 +172,8 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
result = sut.Repeat();
|
||||
|
||||
Assert.AreEqual(process.Object, sessionContext.ClientProcess);
|
||||
Assert.AreEqual(proxy.Object, sessionContext.ClientProxy);
|
||||
Assert.AreEqual(process.Object, runtimeContext.ClientProcess);
|
||||
Assert.AreEqual(proxy.Object, runtimeContext.ClientProxy);
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
}
|
||||
|
||||
@@ -175,8 +189,8 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
proxy.Verify(p => p.Disconnect(), Times.Once);
|
||||
process.Verify(p => p.TryKill(It.IsAny<int>()), Times.Never);
|
||||
|
||||
Assert.IsNull(sessionContext.ClientProcess);
|
||||
Assert.IsNull(sessionContext.ClientProxy);
|
||||
Assert.IsNull(runtimeContext.ClientProcess);
|
||||
Assert.IsNull(runtimeContext.ClientProxy);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -189,8 +203,8 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
process.Verify(p => p.TryKill(It.IsAny<int>()), Times.AtLeastOnce);
|
||||
|
||||
Assert.IsNull(sessionContext.ClientProcess);
|
||||
Assert.IsNull(sessionContext.ClientProxy);
|
||||
Assert.IsNull(runtimeContext.ClientProcess);
|
||||
Assert.IsNull(runtimeContext.ClientProxy);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -201,8 +215,8 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
process.Verify(p => p.TryKill(It.IsAny<int>()), Times.Exactly(5));
|
||||
|
||||
Assert.IsNotNull(sessionContext.ClientProcess);
|
||||
Assert.IsNotNull(sessionContext.ClientProxy);
|
||||
Assert.IsNotNull(runtimeContext.ClientProcess);
|
||||
Assert.IsNotNull(runtimeContext.ClientProxy);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -216,8 +230,8 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
proxy.Verify(p => p.Disconnect(), Times.Never);
|
||||
process.Verify(p => p.TryKill(It.IsAny<int>()), Times.Never);
|
||||
|
||||
Assert.IsNull(sessionContext.ClientProcess);
|
||||
Assert.IsNull(sessionContext.ClientProxy);
|
||||
Assert.IsNull(runtimeContext.ClientProcess);
|
||||
Assert.IsNull(runtimeContext.ClientProxy);
|
||||
}
|
||||
|
||||
private void PerformNormally()
|
||||
|
@@ -14,56 +14,58 @@ using SafeExamBrowser.Communication.Contracts.Hosts;
|
||||
using SafeExamBrowser.Communication.Contracts.Proxies;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Runtime.Communication;
|
||||
using SafeExamBrowser.Runtime.Operations.Session;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
||||
using SafeExamBrowser.WindowsApi.Contracts;
|
||||
using SafeExamBrowser.Runtime.Operations;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
[TestClass]
|
||||
public class ClientTerminationOperationTests
|
||||
{
|
||||
private Action clientReady;
|
||||
private Action terminated;
|
||||
private AppConfig appConfig;
|
||||
private Mock<IClientProxy> proxy;
|
||||
private Mock<ILogger> logger;
|
||||
private Mock<IProcess> process;
|
||||
private Mock<IProcessFactory> processFactory;
|
||||
private Mock<IProxyFactory> proxyFactory;
|
||||
private Mock<IRuntimeHost> runtimeHost;
|
||||
private SessionConfiguration session;
|
||||
private SessionContext sessionContext;
|
||||
|
||||
private RuntimeContext runtimeContext;
|
||||
private ClientTerminationOperation sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
runtimeContext = new RuntimeContext();
|
||||
runtimeHost = new Mock<IRuntimeHost>();
|
||||
|
||||
appConfig = new AppConfig();
|
||||
clientReady = new Action(() => runtimeHost.Raise(h => h.ClientReady += null));
|
||||
logger = new Mock<ILogger>();
|
||||
process = new Mock<IProcess>();
|
||||
processFactory = new Mock<IProcessFactory>();
|
||||
proxy = new Mock<IClientProxy>();
|
||||
proxyFactory = new Mock<IProxyFactory>();
|
||||
runtimeHost = new Mock<IRuntimeHost>();
|
||||
session = new SessionConfiguration();
|
||||
sessionContext = new SessionContext();
|
||||
terminated = new Action(() =>
|
||||
{
|
||||
runtimeHost.Raise(h => h.ClientDisconnected += null);
|
||||
process.Raise(p => p.Terminated += null, 0);
|
||||
});
|
||||
|
||||
session.AppConfig = appConfig;
|
||||
sessionContext.ClientProcess = process.Object;
|
||||
sessionContext.ClientProxy = proxy.Object;
|
||||
sessionContext.Current = session;
|
||||
sessionContext.Next = session;
|
||||
runtimeContext.ClientProcess = process.Object;
|
||||
runtimeContext.ClientProxy = proxy.Object;
|
||||
runtimeContext.Current = session;
|
||||
runtimeContext.Next = session;
|
||||
proxyFactory.Setup(f => f.CreateClientProxy(It.IsAny<string>(), It.IsAny<Interlocutor>())).Returns(proxy.Object);
|
||||
|
||||
sut = new ClientTerminationOperation(logger.Object, processFactory.Object, proxyFactory.Object, runtimeHost.Object, sessionContext, 0);
|
||||
var dependencies = new Dependencies(
|
||||
new ClientBridge(Mock.Of<IRuntimeHost>(), runtimeContext),
|
||||
Mock.Of<ILogger>(),
|
||||
Mock.Of<IMessageBox>(),
|
||||
Mock.Of<IRuntimeWindow>(),
|
||||
runtimeContext,
|
||||
Mock.Of<IText>());
|
||||
|
||||
sut = new ClientTerminationOperation(dependencies, processFactory.Object, proxyFactory.Object, runtimeHost.Object, 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -81,10 +83,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
proxy.Verify(p => p.InitiateShutdown(), Times.Once);
|
||||
proxy.Verify(p => p.Disconnect(), Times.Once);
|
||||
process.Verify(p => p.TryKill(default(int)), Times.Never);
|
||||
process.Verify(p => p.TryKill(default), Times.Never);
|
||||
|
||||
Assert.IsNull(sessionContext.ClientProcess);
|
||||
Assert.IsNull(sessionContext.ClientProxy);
|
||||
Assert.IsNull(runtimeContext.ClientProcess);
|
||||
Assert.IsNull(runtimeContext.ClientProxy);
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
}
|
||||
|
||||
@@ -92,7 +94,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
public void MustDoNothingOnRepeatIfNoClientRunning()
|
||||
{
|
||||
process.SetupGet(p => p.HasTerminated).Returns(true);
|
||||
sessionContext.ClientProcess = process.Object;
|
||||
runtimeContext.ClientProcess = process.Object;
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
|
@@ -11,14 +11,22 @@ using System.IO;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts.Data;
|
||||
using SafeExamBrowser.Communication.Contracts.Hosts;
|
||||
using SafeExamBrowser.Communication.Contracts.Proxies;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Configuration.Contracts.Cryptography;
|
||||
using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Runtime.Operations;
|
||||
using SafeExamBrowser.Runtime.Operations.Events;
|
||||
using SafeExamBrowser.Runtime.Communication;
|
||||
using SafeExamBrowser.Runtime.Operations.Session;
|
||||
using SafeExamBrowser.Settings;
|
||||
using SafeExamBrowser.Settings.Security;
|
||||
using SafeExamBrowser.SystemComponents.Contracts;
|
||||
using SafeExamBrowser.UserInterface.Contracts;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows.Data;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
@@ -28,13 +36,17 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
private const string FILE_NAME = "SebClientSettings.seb";
|
||||
|
||||
private AppConfig appConfig;
|
||||
private RuntimeContext context;
|
||||
private Dependencies dependencies;
|
||||
private SessionConfiguration currentSession;
|
||||
private SessionConfiguration nextSession;
|
||||
|
||||
private Mock<IFileSystem> fileSystem;
|
||||
private Mock<IHashAlgorithm> hashAlgorithm;
|
||||
private Mock<ILogger> logger;
|
||||
private Mock<IConfigurationRepository> repository;
|
||||
private SessionConfiguration currentSession;
|
||||
private SessionConfiguration nextSession;
|
||||
private SessionContext sessionContext;
|
||||
private Mock<IMessageBox> messageBox;
|
||||
private Mock<IUserInterfaceFactory> uiFactory;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
@@ -45,15 +57,26 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
logger = new Mock<ILogger>();
|
||||
repository = new Mock<IConfigurationRepository>();
|
||||
currentSession = new SessionConfiguration();
|
||||
messageBox = new Mock<IMessageBox>();
|
||||
nextSession = new SessionConfiguration();
|
||||
sessionContext = new SessionContext();
|
||||
context = new RuntimeContext();
|
||||
uiFactory = new Mock<IUserInterfaceFactory>();
|
||||
|
||||
dependencies = new Dependencies(
|
||||
new ClientBridge(Mock.Of<IRuntimeHost>(), context),
|
||||
logger.Object,
|
||||
messageBox.Object,
|
||||
Mock.Of<IRuntimeWindow>(),
|
||||
context,
|
||||
Mock.Of<IText>());
|
||||
|
||||
appConfig.AppDataFilePath = $@"C:\Not\Really\AppData\File.xml";
|
||||
appConfig.ProgramDataFilePath = $@"C:\Not\Really\ProgramData\File.xml";
|
||||
currentSession.AppConfig = appConfig;
|
||||
currentSession.Settings = new AppSettings();
|
||||
nextSession.AppConfig = appConfig;
|
||||
sessionContext.Current = currentSession;
|
||||
sessionContext.Next = nextSession;
|
||||
context.Current = currentSession;
|
||||
context.Next = nextSession;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -68,7 +91,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
var sut = new ConfigurationOperation(new[] { "abc.exe", url }, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
var resource = new Uri(url);
|
||||
|
||||
@@ -86,7 +109,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
|
||||
var sut = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
var sut = new ConfigurationOperation(null, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
repository.Verify(r => r.TryLoadSettings(It.Is<Uri>(u => u.Equals(location)), out settings, It.IsAny<PasswordParameters>()), Times.Once);
|
||||
@@ -102,7 +125,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
appConfig.AppDataFilePath = location;
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
|
||||
var sut = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
var sut = new ConfigurationOperation(null, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
repository.Verify(r => r.TryLoadSettings(It.Is<Uri>(u => u.Equals(location)), out settings, It.IsAny<PasswordParameters>()), Times.Once);
|
||||
@@ -118,7 +141,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
nextSession.Settings = settings;
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.LoadWithBrowser);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
var sut = new ConfigurationOperation(new[] { "abc.exe", url }, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
Assert.IsFalse(settings.Browser.DeleteCacheOnShutdown);
|
||||
@@ -135,7 +158,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
repository.Setup(r => r.LoadDefaultSettings()).Returns(defaultSettings);
|
||||
|
||||
var sut = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
var sut = new ConfigurationOperation(null, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
repository.Verify(r => r.LoadDefaultSettings(), Times.Once);
|
||||
@@ -150,20 +173,16 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var settings = new AppSettings();
|
||||
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
||||
|
||||
sessionContext.Current = null;
|
||||
context.Current = null;
|
||||
settings.ConfigurationMode = ConfigurationMode.ConfigureClient;
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
repository.Setup(r => r.ConfigureClientWith(It.IsAny<Uri>(), It.IsAny<PasswordParameters>())).Returns(SaveStatus.Success);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
sut.ActionRequired += args =>
|
||||
{
|
||||
if (args is ConfigurationCompletedEventArgs c)
|
||||
{
|
||||
c.AbortStartup = true;
|
||||
}
|
||||
};
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Returns(MessageBoxResult.Yes);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "abc.exe", url }, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
Assert.AreEqual(OperationResult.Aborted, result);
|
||||
@@ -179,15 +198,11 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
repository.Setup(r => r.ConfigureClientWith(It.IsAny<Uri>(), It.IsAny<PasswordParameters>())).Returns(SaveStatus.Success);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
sut.ActionRequired += args =>
|
||||
{
|
||||
if (args is ConfigurationCompletedEventArgs c)
|
||||
{
|
||||
c.AbortStartup = false;
|
||||
}
|
||||
};
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Returns(MessageBoxResult.No);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "abc.exe", url }, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
@@ -204,15 +219,11 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
repository.Setup(r => r.ConfigureClientWith(It.IsAny<Uri>(), It.IsAny<PasswordParameters>())).Returns(SaveStatus.UnexpectedError);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
sut.ActionRequired += args =>
|
||||
{
|
||||
if (args is ClientConfigurationErrorMessageArgs)
|
||||
{
|
||||
informed = true;
|
||||
}
|
||||
};
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => informed = true);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "abc.exe", url }, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
Assert.AreEqual(OperationResult.Failed, result);
|
||||
@@ -227,15 +238,11 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
settings.ConfigurationMode = ConfigurationMode.Exam;
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
|
||||
var sut = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
sut.ActionRequired += args =>
|
||||
{
|
||||
if (args is ConfigurationCompletedEventArgs c)
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
};
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(Assert.Fail);
|
||||
|
||||
var sut = new ConfigurationOperation(null, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
@@ -249,14 +256,14 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
repository.Setup(r => r.LoadDefaultSettings()).Returns(defaultSettings);
|
||||
|
||||
var sut = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
var sut = new ConfigurationOperation(null, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
result = sut.Perform();
|
||||
|
||||
repository.Verify(r => r.LoadDefaultSettings(), Times.Once);
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
Assert.AreSame(defaultSettings, nextSession.Settings);
|
||||
|
||||
sut = new ConfigurationOperation(new string[] { }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
sut = new ConfigurationOperation(new string[] { }, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
result = sut.Perform();
|
||||
|
||||
repository.Verify(r => r.LoadDefaultSettings(), Times.Exactly(2));
|
||||
@@ -268,7 +275,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
public void Perform_MustNotFailWithInvalidUri()
|
||||
{
|
||||
var uri = @"an/invalid\uri.'*%yolo/()你好";
|
||||
var sut = new ConfigurationOperation(new[] { "blubb.exe", uri }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
var sut = new ConfigurationOperation(new[] { "abc.exe", uri }, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
@@ -278,6 +285,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
public void Perform_MustOnlyAllowToEnterAdminPasswordFiveTimes()
|
||||
{
|
||||
var count = 0;
|
||||
var dialog = new Mock<IPasswordDialog>();
|
||||
var localSettings = new AppSettings();
|
||||
var settings = new AppSettings { ConfigurationMode = ConfigurationMode.ConfigureClient };
|
||||
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
||||
@@ -285,21 +293,14 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
appConfig.AppDataFilePath = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations), "Testdata", FILE_NAME);
|
||||
localSettings.Security.AdminPasswordHash = "1234";
|
||||
settings.Security.AdminPasswordHash = "9876";
|
||||
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
repository.Setup(r => r.TryLoadSettings(It.Is<Uri>(u => u.LocalPath.Contains(FILE_NAME)), out localSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
nextSession.Settings = settings;
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
sut.ActionRequired += args =>
|
||||
{
|
||||
if (args is PasswordRequiredEventArgs p && p.Purpose == PasswordRequestPurpose.LocalAdministrator)
|
||||
{
|
||||
count++;
|
||||
p.Success = true;
|
||||
}
|
||||
};
|
||||
dialog.Setup(d => d.Show(It.IsAny<IWindow>())).Callback(() => count++).Returns(new PasswordDialogResult { Success = true });
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
repository.Setup(r => r.TryLoadSettings(It.Is<Uri>(u => u.LocalPath.Contains(FILE_NAME)), out localSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
uiFactory.Setup(f => f.CreatePasswordDialog(It.IsAny<string>(), It.IsAny<string>())).Returns(dialog.Object);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "abc.exe", url }, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
Assert.AreEqual(5, count);
|
||||
@@ -310,21 +311,15 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
public void Perform_MustOnlyAllowToEnterSettingsPasswordFiveTimes()
|
||||
{
|
||||
var count = 0;
|
||||
var dialog = new Mock<IPasswordDialog>();
|
||||
var settings = default(AppSettings);
|
||||
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
||||
|
||||
dialog.Setup(d => d.Show(It.IsAny<IWindow>())).Callback(() => count++).Returns(new PasswordDialogResult { Success = true });
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.PasswordNeeded);
|
||||
uiFactory.Setup(f => f.CreatePasswordDialog(It.IsAny<string>(), It.IsAny<string>())).Returns(dialog.Object);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
sut.ActionRequired += args =>
|
||||
{
|
||||
if (args is PasswordRequiredEventArgs p && p.Purpose == PasswordRequestPurpose.Settings)
|
||||
{
|
||||
count++;
|
||||
p.Success = true;
|
||||
}
|
||||
};
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "abc.exe", url }, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
repository.Verify(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>()), Times.Exactly(6));
|
||||
@@ -336,6 +331,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
[TestMethod]
|
||||
public void Perform_MustSucceedIfAdminPasswordCorrect()
|
||||
{
|
||||
var dialog = new Mock<IPasswordDialog>();
|
||||
var password = "test";
|
||||
var currentSettings = new AppSettings { ConfigurationMode = ConfigurationMode.ConfigureClient };
|
||||
var nextSettings = new AppSettings { ConfigurationMode = ConfigurationMode.ConfigureClient };
|
||||
@@ -344,21 +340,15 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
currentSettings.Security.AdminPasswordHash = "1234";
|
||||
nextSession.Settings = nextSettings;
|
||||
nextSettings.Security.AdminPasswordHash = "9876";
|
||||
|
||||
dialog.Setup(d => d.Show(It.IsAny<IWindow>())).Returns(new PasswordDialogResult { Password = password, Success = true });
|
||||
hashAlgorithm.Setup(h => h.GenerateHashFor(It.Is<string>(p => p == password))).Returns(currentSettings.Security.AdminPasswordHash);
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out currentSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
repository.Setup(r => r.TryLoadSettings(It.Is<Uri>(u => u.AbsoluteUri == url), out nextSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
repository.Setup(r => r.ConfigureClientWith(It.IsAny<Uri>(), It.IsAny<PasswordParameters>())).Returns(SaveStatus.Success);
|
||||
uiFactory.Setup(f => f.CreatePasswordDialog(It.IsAny<string>(), It.IsAny<string>())).Returns(dialog.Object);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
sut.ActionRequired += args =>
|
||||
{
|
||||
if (args is PasswordRequiredEventArgs p && p.Purpose == PasswordRequestPurpose.LocalAdministrator)
|
||||
{
|
||||
p.Password = password;
|
||||
p.Success = true;
|
||||
}
|
||||
};
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "abc.exe", url }, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
repository.Verify(r => r.ConfigureClientWith(It.IsAny<Uri>(), It.IsAny<PasswordParameters>()), Times.Once);
|
||||
@@ -379,16 +369,9 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out currentSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
repository.Setup(r => r.TryLoadSettings(It.Is<Uri>(u => u.AbsoluteUri == url), out nextSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
repository.Setup(r => r.ConfigureClientWith(It.IsAny<Uri>(), It.IsAny<PasswordParameters>())).Returns(SaveStatus.Success);
|
||||
uiFactory.Setup(f => f.CreatePasswordDialog(It.IsAny<string>(), It.IsAny<string>())).Callback(Assert.Fail);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
sut.ActionRequired += args =>
|
||||
{
|
||||
if (args is PasswordRequiredEventArgs)
|
||||
{
|
||||
Assert.Fail();
|
||||
}
|
||||
};
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "abc.exe", url }, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
hashAlgorithm.Verify(h => h.GenerateHashFor(It.IsAny<string>()), Times.Never);
|
||||
@@ -399,23 +382,17 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
[TestMethod]
|
||||
public void Perform_MustSucceedIfSettingsPasswordCorrect()
|
||||
{
|
||||
var dialog = new Mock<IPasswordDialog>();
|
||||
var password = "test";
|
||||
var settings = new AppSettings { ConfigurationMode = ConfigurationMode.Exam };
|
||||
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
||||
|
||||
dialog.Setup(d => d.Show(It.IsAny<IWindow>())).Returns(new PasswordDialogResult { Password = password, Success = true });
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.PasswordNeeded);
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.Is<PasswordParameters>(p => p.Password == password))).Returns(LoadStatus.Success);
|
||||
uiFactory.Setup(f => f.CreatePasswordDialog(It.IsAny<string>(), It.IsAny<string>())).Returns(dialog.Object);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
sut.ActionRequired += args =>
|
||||
{
|
||||
if (args is PasswordRequiredEventArgs p)
|
||||
{
|
||||
p.Password = password;
|
||||
p.Success = true;
|
||||
}
|
||||
};
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "abc.exe", url }, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
repository.Verify(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.Is<PasswordParameters>(p => p.Password == password)), Times.AtLeastOnce);
|
||||
@@ -443,7 +420,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.Is<PasswordParameters>(p => p.IsHash == true && p.Password == settings.Security.AdminPasswordHash)))
|
||||
.Returns(LoadStatus.Success);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
var sut = new ConfigurationOperation(new[] { "abc.exe", url }, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
repository.Verify(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.Is<PasswordParameters>(p => p.Password == settings.Security.AdminPasswordHash)), Times.AtLeastOnce);
|
||||
@@ -454,29 +431,25 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
[TestMethod]
|
||||
public void Perform_MustAbortAskingForAdminPasswordIfDecidedByUser()
|
||||
{
|
||||
var dialog = new Mock<IPasswordDialog>();
|
||||
var password = "test";
|
||||
var currentSettings = new AppSettings { ConfigurationMode = ConfigurationMode.ConfigureClient };
|
||||
var nextSettings = new AppSettings { ConfigurationMode = ConfigurationMode.ConfigureClient };
|
||||
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
||||
|
||||
appConfig.AppDataFilePath = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), nameof(Operations), "Testdata", FILE_NAME);
|
||||
currentSession.Settings = currentSettings;
|
||||
currentSettings.Security.AdminPasswordHash = "1234";
|
||||
nextSession.Settings = nextSettings;
|
||||
nextSettings.Security.AdminPasswordHash = "9876";
|
||||
|
||||
dialog.Setup(d => d.Show(It.IsAny<IWindow>())).Returns(new PasswordDialogResult { Success = false });
|
||||
hashAlgorithm.Setup(h => h.GenerateHashFor(It.Is<string>(p => p == password))).Returns(currentSettings.Security.AdminPasswordHash);
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out currentSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
repository.Setup(r => r.TryLoadSettings(It.Is<Uri>(u => u.AbsoluteUri == url), out nextSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
uiFactory.Setup(f => f.CreatePasswordDialog(It.IsAny<string>(), It.IsAny<string>())).Returns(dialog.Object);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
sut.ActionRequired += args =>
|
||||
{
|
||||
if (args is PasswordRequiredEventArgs p && p.Purpose == PasswordRequestPurpose.LocalAdministrator)
|
||||
{
|
||||
p.Success = false;
|
||||
}
|
||||
};
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "abc.exe", url }, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
repository.Verify(r => r.ConfigureClientWith(It.IsAny<Uri>(), It.IsAny<PasswordParameters>()), Times.Never);
|
||||
@@ -487,20 +460,15 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
[TestMethod]
|
||||
public void Perform_MustAbortAskingForSettingsPasswordIfDecidedByUser()
|
||||
{
|
||||
var dialog = new Mock<IPasswordDialog>();
|
||||
var settings = default(AppSettings);
|
||||
var url = @"http://www.safeexambrowser.org/whatever.seb";
|
||||
|
||||
dialog.Setup(d => d.Show(It.IsAny<IWindow>())).Returns(new PasswordDialogResult { Success = false });
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.PasswordNeeded);
|
||||
uiFactory.Setup(f => f.CreatePasswordDialog(It.IsAny<string>(), It.IsAny<string>())).Returns(dialog.Object);
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "blubb.exe", url }, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
sut.ActionRequired += args =>
|
||||
{
|
||||
if (args is PasswordRequiredEventArgs p)
|
||||
{
|
||||
p.Success = false;
|
||||
}
|
||||
};
|
||||
|
||||
var sut = new ConfigurationOperation(new[] { "abc.exe", url }, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Perform();
|
||||
|
||||
Assert.AreEqual(OperationResult.Aborted, result);
|
||||
@@ -515,10 +483,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var settings = new AppSettings { ConfigurationMode = ConfigurationMode.Exam };
|
||||
|
||||
currentSession.Settings = currentSettings;
|
||||
sessionContext.ReconfigurationFilePath = resource.LocalPath;
|
||||
context.ReconfigurationFilePath = resource.LocalPath;
|
||||
repository.Setup(r => r.TryLoadSettings(It.Is<Uri>(u => u.Equals(resource)), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
|
||||
var sut = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
var sut = new ConfigurationOperation(null, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Repeat();
|
||||
|
||||
fileSystem.Verify(f => f.Delete(It.Is<string>(s => s == resource.LocalPath)), Times.Once);
|
||||
@@ -537,11 +505,11 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var settings = new AppSettings { ConfigurationMode = ConfigurationMode.ConfigureClient };
|
||||
|
||||
currentSession.Settings = currentSettings;
|
||||
sessionContext.ReconfigurationFilePath = resource.LocalPath;
|
||||
context.ReconfigurationFilePath = resource.LocalPath;
|
||||
repository.Setup(r => r.TryLoadSettings(It.Is<Uri>(u => u.Equals(resource)), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
repository.Setup(r => r.ConfigureClientWith(It.Is<Uri>(u => u.Equals(resource)), It.IsAny<PasswordParameters>())).Returns(SaveStatus.Success);
|
||||
|
||||
var sut = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
var sut = new ConfigurationOperation(null, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Repeat();
|
||||
|
||||
fileSystem.Verify(f => f.Delete(It.Is<string>(s => s == resource.LocalPath)), Times.Once);
|
||||
@@ -563,12 +531,12 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var order = 0;
|
||||
|
||||
currentSession.Settings = currentSettings;
|
||||
sessionContext.ReconfigurationFilePath = resource.LocalPath;
|
||||
context.ReconfigurationFilePath = resource.LocalPath;
|
||||
fileSystem.Setup(f => f.Delete(It.IsAny<string>())).Callback(() => delete = ++order);
|
||||
repository.Setup(r => r.TryLoadSettings(It.Is<Uri>(u => u.Equals(resource)), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
repository.Setup(r => r.ConfigureClientWith(It.Is<Uri>(u => u.Equals(resource)), It.IsAny<PasswordParameters>())).Returns(SaveStatus.Success).Callback(() => configure = ++order);
|
||||
|
||||
var sut = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
var sut = new ConfigurationOperation(null, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Repeat();
|
||||
|
||||
fileSystem.Verify(f => f.Delete(It.Is<string>(s => s == resource.LocalPath)), Times.Once);
|
||||
@@ -586,17 +554,17 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var resource = new Uri("file:///C:/does/not/exist.txt");
|
||||
var settings = default(AppSettings);
|
||||
|
||||
sessionContext.ReconfigurationFilePath = null;
|
||||
context.ReconfigurationFilePath = null;
|
||||
repository.Setup(r => r.TryLoadSettings(It.IsAny<Uri>(), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
|
||||
var sut = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
var sut = new ConfigurationOperation(null, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Repeat();
|
||||
|
||||
fileSystem.Verify(f => f.Delete(It.Is<string>(s => s == resource.LocalPath)), Times.Never);
|
||||
repository.Verify(r => r.TryLoadSettings(It.Is<Uri>(u => u.Equals(resource)), out settings, It.IsAny<PasswordParameters>()), Times.Never);
|
||||
Assert.AreEqual(OperationResult.Failed, result);
|
||||
|
||||
sessionContext.ReconfigurationFilePath = resource.LocalPath;
|
||||
context.ReconfigurationFilePath = resource.LocalPath;
|
||||
result = sut.Repeat();
|
||||
|
||||
fileSystem.Verify(f => f.Delete(It.Is<string>(s => s == resource.LocalPath)), Times.Never);
|
||||
@@ -608,33 +576,52 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
public void Repeat_MustAbortForSettingsPasswordIfWishedByUser()
|
||||
{
|
||||
var currentSettings = new AppSettings();
|
||||
var dialog = new Mock<IPasswordDialog>();
|
||||
var location = Path.GetDirectoryName(GetType().Assembly.Location);
|
||||
var resource = new Uri(Path.Combine(location, nameof(Operations), "Testdata", FILE_NAME));
|
||||
var settings = new AppSettings { ConfigurationMode = ConfigurationMode.ConfigureClient };
|
||||
|
||||
currentSession.Settings = currentSettings;
|
||||
sessionContext.ReconfigurationFilePath = resource.LocalPath;
|
||||
context.ReconfigurationFilePath = resource.LocalPath;
|
||||
|
||||
dialog.Setup(d => d.Show(It.IsAny<IWindow>())).Returns(new PasswordDialogResult { Success = false });
|
||||
repository.Setup(r => r.TryLoadSettings(It.Is<Uri>(u => u.Equals(resource)), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.PasswordNeeded);
|
||||
uiFactory.Setup(f => f.CreatePasswordDialog(It.IsAny<string>(), It.IsAny<string>())).Returns(dialog.Object);
|
||||
|
||||
var sut = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
sut.ActionRequired += args =>
|
||||
{
|
||||
if (args is PasswordRequiredEventArgs p)
|
||||
{
|
||||
p.Success = false;
|
||||
}
|
||||
};
|
||||
|
||||
var sut = new ConfigurationOperation(null, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Repeat();
|
||||
|
||||
fileSystem.Verify(f => f.Delete(It.Is<string>(s => s == resource.LocalPath)), Times.Once);
|
||||
Assert.AreEqual(OperationResult.Aborted, result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Repeat_MustNotWaitForPasswordViaClientIfCommunicationHasFailed()
|
||||
{
|
||||
var clientProxy = new Mock<IClientProxy>();
|
||||
var currentSettings = new AppSettings();
|
||||
var location = Path.GetDirectoryName(GetType().Assembly.Location);
|
||||
var resource = new Uri(Path.Combine(location, nameof(Operations), "Testdata", FILE_NAME));
|
||||
var settings = new AppSettings { ConfigurationMode = ConfigurationMode.ConfigureClient };
|
||||
|
||||
context.ClientProxy = clientProxy.Object;
|
||||
context.ReconfigurationFilePath = resource.LocalPath;
|
||||
currentSession.Settings = currentSettings;
|
||||
currentSettings.Security.KioskMode = KioskMode.CreateNewDesktop;
|
||||
clientProxy.Setup(c => c.RequestPassword(It.IsAny<PasswordRequestPurpose>(), It.IsAny<Guid>())).Returns(new CommunicationResult(false));
|
||||
repository.Setup(r => r.TryLoadSettings(It.Is<Uri>(u => u.Equals(resource)), out settings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.PasswordNeeded);
|
||||
|
||||
var sut = new ConfigurationOperation(null, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Repeat();
|
||||
|
||||
clientProxy.Verify(c => c.RequestPassword(It.IsAny<PasswordRequestPurpose>(), It.IsAny<Guid>()), Times.Once);
|
||||
Assert.AreEqual(OperationResult.Aborted, result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Revert_MustDoNothing()
|
||||
{
|
||||
var sut = new ConfigurationOperation(null, repository.Object, fileSystem.Object, hashAlgorithm.Object, logger.Object, sessionContext);
|
||||
var sut = new ConfigurationOperation(null, dependencies, fileSystem.Object, hashAlgorithm.Object, repository.Object, uiFactory.Object);
|
||||
var result = sut.Revert();
|
||||
|
||||
fileSystem.VerifyNoOtherCalls();
|
||||
|
@@ -8,35 +8,47 @@
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts.Hosts;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Runtime.Operations;
|
||||
using SafeExamBrowser.Runtime.Operations.Events;
|
||||
using SafeExamBrowser.Runtime.Communication;
|
||||
using SafeExamBrowser.Runtime.Operations.Session;
|
||||
using SafeExamBrowser.Settings;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
[TestClass]
|
||||
public class DisclaimerOperationTests
|
||||
{
|
||||
private Mock<ILogger> logger;
|
||||
private RuntimeContext context;
|
||||
private Mock<IMessageBox> messageBox;
|
||||
private AppSettings settings;
|
||||
private SessionContext context;
|
||||
|
||||
private DisclaimerOperation sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
context = new SessionContext();
|
||||
logger = new Mock<ILogger>();
|
||||
context = new RuntimeContext();
|
||||
messageBox = new Mock<IMessageBox>();
|
||||
settings = new AppSettings();
|
||||
|
||||
context.Next = new SessionConfiguration();
|
||||
context.Next.Settings = settings;
|
||||
sut = new DisclaimerOperation(logger.Object, context);
|
||||
|
||||
var dependencies = new Dependencies(
|
||||
new ClientBridge(Mock.Of<IRuntimeHost>(), context),
|
||||
Mock.Of<ILogger>(),
|
||||
messageBox.Object,
|
||||
Mock.Of<IRuntimeWindow>(),
|
||||
context,
|
||||
Mock.Of<IText>());
|
||||
|
||||
sut = new DisclaimerOperation(dependencies);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -45,15 +57,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var count = 0;
|
||||
|
||||
settings.Proctoring.ScreenProctoring.Enabled = true;
|
||||
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs m)
|
||||
{
|
||||
count++;
|
||||
m.Result = MessageBoxResult.Ok;
|
||||
}
|
||||
};
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => count++)
|
||||
.Returns(MessageBoxResult.Ok);
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
@@ -67,15 +74,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var disclaimerShown = false;
|
||||
|
||||
settings.Proctoring.ScreenProctoring.Enabled = true;
|
||||
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs m)
|
||||
{
|
||||
disclaimerShown = true;
|
||||
m.Result = MessageBoxResult.Cancel;
|
||||
}
|
||||
};
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => disclaimerShown = true)
|
||||
.Returns(MessageBoxResult.Cancel);
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
@@ -88,14 +90,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
var disclaimerShown = false;
|
||||
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs m)
|
||||
{
|
||||
disclaimerShown = true;
|
||||
m.Result = MessageBoxResult.Cancel;
|
||||
}
|
||||
};
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => disclaimerShown = true)
|
||||
.Returns(MessageBoxResult.Cancel);
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
@@ -109,15 +107,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var count = 0;
|
||||
|
||||
settings.Proctoring.ScreenProctoring.Enabled = true;
|
||||
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs m)
|
||||
{
|
||||
count++;
|
||||
m.Result = MessageBoxResult.Ok;
|
||||
}
|
||||
};
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => count++)
|
||||
.Returns(MessageBoxResult.Ok);
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
@@ -131,15 +124,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var disclaimerShown = false;
|
||||
|
||||
settings.Proctoring.ScreenProctoring.Enabled = true;
|
||||
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs m)
|
||||
{
|
||||
disclaimerShown = true;
|
||||
m.Result = MessageBoxResult.Cancel;
|
||||
}
|
||||
};
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => disclaimerShown = true)
|
||||
.Returns(MessageBoxResult.Cancel);
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
@@ -152,14 +140,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
var disclaimerShown = false;
|
||||
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs m)
|
||||
{
|
||||
disclaimerShown = true;
|
||||
m.Result = MessageBoxResult.Cancel;
|
||||
}
|
||||
};
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => disclaimerShown = true)
|
||||
.Returns(MessageBoxResult.Cancel);
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
@@ -172,14 +156,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
var disclaimerShown = false;
|
||||
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs m)
|
||||
{
|
||||
disclaimerShown = true;
|
||||
m.Result = MessageBoxResult.Cancel;
|
||||
}
|
||||
};
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => disclaimerShown = true)
|
||||
.Returns(MessageBoxResult.Cancel);
|
||||
|
||||
var result = sut.Revert();
|
||||
|
||||
|
@@ -8,24 +8,27 @@
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts.Hosts;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Monitoring.Contracts.Display;
|
||||
using SafeExamBrowser.Runtime.Operations;
|
||||
using SafeExamBrowser.Runtime.Operations.Events;
|
||||
using SafeExamBrowser.Runtime.Communication;
|
||||
using SafeExamBrowser.Runtime.Operations.Session;
|
||||
using SafeExamBrowser.Settings;
|
||||
using SafeExamBrowser.Settings.Monitoring;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
[TestClass]
|
||||
public class DisplayMonitorOperationTests
|
||||
{
|
||||
private SessionContext context;
|
||||
private RuntimeContext context;
|
||||
private Mock<IDisplayMonitor> displayMonitor;
|
||||
private Mock<ILogger> logger;
|
||||
private Mock<IMessageBox> messageBox;
|
||||
private AppSettings settings;
|
||||
private Mock<IText> text;
|
||||
|
||||
@@ -34,15 +37,24 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
context = new SessionContext();
|
||||
context = new RuntimeContext();
|
||||
displayMonitor = new Mock<IDisplayMonitor>();
|
||||
logger = new Mock<ILogger>();
|
||||
messageBox = new Mock<IMessageBox>();
|
||||
settings = new AppSettings();
|
||||
text = new Mock<IText>();
|
||||
|
||||
context.Next = new SessionConfiguration();
|
||||
context.Next.Settings = settings;
|
||||
sut = new DisplayMonitorOperation(displayMonitor.Object, logger.Object, context, text.Object);
|
||||
|
||||
var dependencies = new Dependencies(
|
||||
new ClientBridge(Mock.Of<IRuntimeHost>(), context),
|
||||
Mock.Of<ILogger>(),
|
||||
messageBox.Object,
|
||||
Mock.Of<IRuntimeWindow>(),
|
||||
context,
|
||||
text.Object);
|
||||
|
||||
sut = new DisplayMonitorOperation(dependencies, displayMonitor.Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -62,13 +74,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var messageShown = false;
|
||||
|
||||
displayMonitor.Setup(m => m.ValidateConfiguration(It.IsAny<DisplaySettings>())).Returns(new ValidationResult { IsAllowed = false });
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs)
|
||||
{
|
||||
messageShown = true;
|
||||
}
|
||||
};
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => messageShown = true);
|
||||
text.Setup(t => t.Get(It.IsAny<TextKey>())).Returns(string.Empty);
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
@@ -95,13 +104,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var messageShown = false;
|
||||
|
||||
displayMonitor.Setup(m => m.ValidateConfiguration(It.IsAny<DisplaySettings>())).Returns(new ValidationResult { IsAllowed = false });
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs)
|
||||
{
|
||||
messageShown = true;
|
||||
}
|
||||
};
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => messageShown = true);
|
||||
text.Setup(t => t.Get(It.IsAny<TextKey>())).Returns(string.Empty);
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
|
@@ -8,12 +8,17 @@
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts.Hosts;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Runtime.Operations;
|
||||
using SafeExamBrowser.Runtime.Communication;
|
||||
using SafeExamBrowser.Runtime.Operations.Session;
|
||||
using SafeExamBrowser.Settings;
|
||||
using SafeExamBrowser.Settings.Security;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
||||
using SafeExamBrowser.WindowsApi.Contracts;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
@@ -23,37 +28,45 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
private SessionConfiguration currentSession;
|
||||
private AppSettings currentSettings;
|
||||
private Dependencies dependencies;
|
||||
private SessionConfiguration nextSession;
|
||||
private AppSettings nextSettings;
|
||||
private RuntimeContext context;
|
||||
|
||||
private Mock<IDesktopFactory> desktopFactory;
|
||||
private Mock<IDesktopMonitor> desktopMonitor;
|
||||
private Mock<IExplorerShell> explorerShell;
|
||||
private Mock<ILogger> logger;
|
||||
private SessionConfiguration nextSession;
|
||||
private AppSettings nextSettings;
|
||||
private Mock<IProcessFactory> processFactory;
|
||||
private SessionContext sessionContext;
|
||||
|
||||
private KioskModeOperation sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
context = new RuntimeContext();
|
||||
currentSession = new SessionConfiguration();
|
||||
currentSettings = new AppSettings();
|
||||
desktopFactory = new Mock<IDesktopFactory>();
|
||||
desktopMonitor = new Mock<IDesktopMonitor>();
|
||||
explorerShell = new Mock<IExplorerShell>();
|
||||
logger = new Mock<ILogger>();
|
||||
nextSession = new SessionConfiguration();
|
||||
nextSettings = new AppSettings();
|
||||
processFactory = new Mock<IProcessFactory>();
|
||||
sessionContext = new SessionContext();
|
||||
|
||||
currentSession.Settings = currentSettings;
|
||||
nextSession.Settings = nextSettings;
|
||||
sessionContext.Current = currentSession;
|
||||
sessionContext.Next = nextSession;
|
||||
context.Current = currentSession;
|
||||
context.Next = nextSession;
|
||||
|
||||
sut = new KioskModeOperation(desktopFactory.Object, desktopMonitor.Object, explorerShell.Object, logger.Object, processFactory.Object, sessionContext);
|
||||
dependencies = new Dependencies(
|
||||
new ClientBridge(Mock.Of<IRuntimeHost>(), context),
|
||||
Mock.Of<ILogger>(),
|
||||
Mock.Of<IMessageBox>(),
|
||||
Mock.Of<IRuntimeWindow>(),
|
||||
context,
|
||||
Mock.Of<IText>());
|
||||
|
||||
sut = new KioskModeOperation(dependencies, desktopFactory.Object, desktopMonitor.Object, explorerShell.Object, processFactory.Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
@@ -8,22 +8,26 @@
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts.Hosts;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Monitoring.Contracts;
|
||||
using SafeExamBrowser.Runtime.Operations;
|
||||
using SafeExamBrowser.Runtime.Operations.Events;
|
||||
using SafeExamBrowser.Runtime.Communication;
|
||||
using SafeExamBrowser.Runtime.Operations.Session;
|
||||
using SafeExamBrowser.Settings;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
[TestClass]
|
||||
public class RemoteSessionOperationTests
|
||||
{
|
||||
private SessionContext context;
|
||||
private RuntimeContext context;
|
||||
private Mock<IRemoteSessionDetector> detector;
|
||||
private Mock<ILogger> logger;
|
||||
private Mock<IMessageBox> messageBox;
|
||||
private AppSettings settings;
|
||||
|
||||
private RemoteSessionOperation sut;
|
||||
@@ -31,14 +35,23 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
context = new SessionContext();
|
||||
context = new RuntimeContext();
|
||||
detector = new Mock<IRemoteSessionDetector>();
|
||||
logger = new Mock<ILogger>();
|
||||
messageBox = new Mock<IMessageBox>();
|
||||
settings = new AppSettings();
|
||||
|
||||
context.Next = new SessionConfiguration();
|
||||
context.Next.Settings = settings;
|
||||
sut = new RemoteSessionOperation(detector.Object, logger.Object, context);
|
||||
|
||||
var dependencies = new Dependencies(
|
||||
new ClientBridge(Mock.Of<IRuntimeHost>(), context),
|
||||
Mock.Of<ILogger>(),
|
||||
messageBox.Object,
|
||||
Mock.Of<IRuntimeWindow>(),
|
||||
context,
|
||||
Mock.Of<IText>());
|
||||
|
||||
sut = new RemoteSessionOperation(dependencies, detector.Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -48,13 +61,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
detector.Setup(d => d.IsRemoteSession()).Returns(true);
|
||||
settings.Service.DisableRemoteConnections = true;
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs)
|
||||
{
|
||||
messageShown = true;
|
||||
}
|
||||
};
|
||||
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => messageShown = true);
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
@@ -71,13 +81,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
detector.Setup(d => d.IsRemoteSession()).Returns(true);
|
||||
settings.Service.DisableRemoteConnections = false;
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs)
|
||||
{
|
||||
messageShown = true;
|
||||
}
|
||||
};
|
||||
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => messageShown = true);
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
@@ -94,13 +101,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
detector.Setup(d => d.IsRemoteSession()).Returns(false);
|
||||
settings.Service.DisableRemoteConnections = true;
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs)
|
||||
{
|
||||
messageShown = true;
|
||||
}
|
||||
};
|
||||
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => messageShown = true);
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
@@ -117,13 +121,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
detector.Setup(d => d.IsRemoteSession()).Returns(true);
|
||||
settings.Service.DisableRemoteConnections = true;
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs)
|
||||
{
|
||||
messageShown = true;
|
||||
}
|
||||
};
|
||||
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => messageShown = true);
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
@@ -140,13 +141,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
detector.Setup(d => d.IsRemoteSession()).Returns(true);
|
||||
settings.Service.DisableRemoteConnections = false;
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs)
|
||||
{
|
||||
messageShown = true;
|
||||
}
|
||||
};
|
||||
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => messageShown = true);
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
@@ -163,13 +161,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
detector.Setup(d => d.IsRemoteSession()).Returns(false);
|
||||
settings.Service.DisableRemoteConnections = true;
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs)
|
||||
{
|
||||
messageShown = true;
|
||||
}
|
||||
};
|
||||
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => messageShown = true);
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
@@ -186,13 +181,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
detector.Setup(d => d.IsRemoteSession()).Returns(true);
|
||||
settings.Service.DisableRemoteConnections = false;
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is MessageEventArgs)
|
||||
{
|
||||
messageShown = true;
|
||||
}
|
||||
};
|
||||
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => messageShown = true);
|
||||
|
||||
var result = sut.Revert();
|
||||
|
||||
|
@@ -10,40 +10,45 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts.Hosts;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Configuration.Contracts.Cryptography;
|
||||
using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||
using SafeExamBrowser.Core.Contracts.OperationModel.Events;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Runtime.Operations;
|
||||
using SafeExamBrowser.Runtime.Operations.Events;
|
||||
using SafeExamBrowser.Runtime.Communication;
|
||||
using SafeExamBrowser.Runtime.Operations.Session;
|
||||
using SafeExamBrowser.Server.Contracts;
|
||||
using SafeExamBrowser.Server.Contracts.Data;
|
||||
using SafeExamBrowser.Settings;
|
||||
using SafeExamBrowser.Settings.Server;
|
||||
using SafeExamBrowser.SystemComponents.Contracts;
|
||||
using SafeExamBrowser.UserInterface.Contracts;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows.Data;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
[TestClass]
|
||||
public class ServerOperationTests
|
||||
{
|
||||
private SessionContext context;
|
||||
private RuntimeContext context;
|
||||
private Mock<IFileSystem> fileSystem;
|
||||
private Mock<ILogger> logger;
|
||||
private Mock<IConfigurationRepository> repository;
|
||||
private Mock<IServerProxy> server;
|
||||
private Mock<IConfigurationRepository> configuration;
|
||||
private Mock<IUserInterfaceFactory> uiFactory;
|
||||
|
||||
private ServerOperation sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
configuration = new Mock<IConfigurationRepository>();
|
||||
context = new SessionContext();
|
||||
context = new RuntimeContext();
|
||||
fileSystem = new Mock<IFileSystem>();
|
||||
logger = new Mock<ILogger>();
|
||||
repository = new Mock<IConfigurationRepository>();
|
||||
server = new Mock<IServerProxy>();
|
||||
uiFactory = new Mock<IUserInterfaceFactory>();
|
||||
|
||||
context.Current = new SessionConfiguration();
|
||||
context.Current.AppConfig = new AppConfig();
|
||||
@@ -52,7 +57,15 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
context.Next.AppConfig = new AppConfig();
|
||||
context.Next.Settings = new AppSettings();
|
||||
|
||||
sut = new ServerOperation(new string[0], configuration.Object, fileSystem.Object, logger.Object, context, server.Object);
|
||||
var dependencies = new Dependencies(
|
||||
new ClientBridge(Mock.Of<IRuntimeHost>(), context),
|
||||
Mock.Of<ILogger>(),
|
||||
Mock.Of<IMessageBox>(),
|
||||
Mock.Of<IRuntimeWindow>(),
|
||||
context,
|
||||
Mock.Of<IText>());
|
||||
|
||||
sut = new ServerOperation(dependencies, fileSystem.Object, repository.Object, server.Object, uiFactory.Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -62,6 +75,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var connection = new ConnectionInfo { Api = "some API", ConnectionToken = "some token", Oauth2Token = "some OAuth2 token" };
|
||||
var counter = 0;
|
||||
var delete = 0;
|
||||
var dialog = new Mock<IExamSelectionDialog>();
|
||||
var exam = new Exam { Id = "some id", LmsName = "some LMS", Name = "some name", Url = "some URL" };
|
||||
var examSelection = 0;
|
||||
var examSettings = new AppSettings();
|
||||
@@ -72,7 +86,11 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var initialSettings = context.Next.Settings;
|
||||
var serverSettings = context.Next.Settings.Server;
|
||||
|
||||
configuration
|
||||
dialog
|
||||
.Setup(d => d.Show(It.IsAny<IWindow>()))
|
||||
.Returns(new ExamSelectionDialogResult { SelectedExam = exam, Success = true })
|
||||
.Callback(() => examSelection = ++counter);
|
||||
repository
|
||||
.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>()))
|
||||
.Returns(LoadStatus.Success);
|
||||
context.Next.Settings.SessionMode = SessionMode.Server;
|
||||
@@ -83,21 +101,13 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
server.Setup(s => s.SendSelectedExam(It.IsAny<Exam>())).Returns(new ServerResponse<string>(true, default));
|
||||
server
|
||||
.Setup(s => s.GetAvailableExams(It.IsAny<string>()))
|
||||
.Returns(new ServerResponse<IEnumerable<Exam>>(true, default(IEnumerable<Exam>)))
|
||||
.Returns(new ServerResponse<IEnumerable<Exam>>(true, default))
|
||||
.Callback(() => getExams = ++counter);
|
||||
server
|
||||
.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>()))
|
||||
.Returns(new ServerResponse<Uri>(true, new Uri("file:///configuration.seb")))
|
||||
.Callback(() => getConfiguration = ++counter);
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is ExamSelectionEventArgs e)
|
||||
{
|
||||
e.Success = true;
|
||||
e.SelectedExam = exam;
|
||||
examSelection = ++counter;
|
||||
}
|
||||
};
|
||||
uiFactory.Setup(f => f.CreateExamSelectionDialog(It.IsAny<IEnumerable<Exam>>())).Returns(dialog.Object);
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
@@ -131,26 +141,21 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
[TestMethod]
|
||||
public void Perform_MustFailIfSettingsCouldNotBeLoaded()
|
||||
{
|
||||
var dialog = new Mock<IExamSelectionDialog>();
|
||||
var connection = new ConnectionInfo { Api = "some API", ConnectionToken = "some token", Oauth2Token = "some OAuth2 token" };
|
||||
var exam = new Exam { Id = "some id", LmsName = "some LMS", Name = "some name", Url = "some URL" };
|
||||
var examSettings = new AppSettings();
|
||||
var initialSettings = context.Next.Settings;
|
||||
|
||||
configuration.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.UnexpectedError);
|
||||
dialog.Setup(d => d.Show(It.IsAny<IWindow>())).Returns(new ExamSelectionDialogResult { SelectedExam = exam, Success = true });
|
||||
repository.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.UnexpectedError);
|
||||
context.Next.Settings.SessionMode = SessionMode.Server;
|
||||
server.Setup(s => s.Connect()).Returns(new ServerResponse(true));
|
||||
server.Setup(s => s.Initialize(It.IsAny<ServerSettings>()));
|
||||
server.Setup(s => s.GetConnectionInfo()).Returns(connection);
|
||||
server.Setup(s => s.GetAvailableExams(It.IsAny<string>())).Returns(new ServerResponse<IEnumerable<Exam>>(true, default(IEnumerable<Exam>)));
|
||||
server.Setup(s => s.GetAvailableExams(It.IsAny<string>())).Returns(new ServerResponse<IEnumerable<Exam>>(true, default));
|
||||
server.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>())).Returns(new ServerResponse<Uri>(true, new Uri("file:///configuration.seb")));
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is ExamSelectionEventArgs e)
|
||||
{
|
||||
e.Success = true;
|
||||
e.SelectedExam = exam;
|
||||
}
|
||||
};
|
||||
uiFactory.Setup(f => f.CreateExamSelectionDialog(It.IsAny<IEnumerable<Exam>>())).Returns(dialog.Object);
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
@@ -177,30 +182,25 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
var connection = new ConnectionInfo { Api = "some API", ConnectionToken = "some token", Oauth2Token = "some OAuth2 token" };
|
||||
var exam = new Exam { Id = "some id", LmsName = "some LMS", Name = "some name", Url = "some URL" };
|
||||
var examDialog = new Mock<IExamSelectionDialog>();
|
||||
var examSettings = new AppSettings();
|
||||
var messageShown = false;
|
||||
var serverDialog = new Mock<IServerFailureDialog>();
|
||||
|
||||
configuration.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
examDialog.Setup(d => d.Show(It.IsAny<IWindow>())).Returns(new ExamSelectionDialogResult { SelectedExam = exam, Success = true });
|
||||
repository.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
context.Next.Settings.SessionMode = SessionMode.Server;
|
||||
server.Setup(s => s.Connect()).Returns(new ServerResponse(true));
|
||||
server.Setup(s => s.Initialize(It.IsAny<ServerSettings>()));
|
||||
server.Setup(s => s.GetConnectionInfo()).Returns(connection);
|
||||
server.Setup(s => s.GetAvailableExams(It.IsAny<string>())).Returns(new ServerResponse<IEnumerable<Exam>>(true, default(IEnumerable<Exam>)));
|
||||
server.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>())).Returns(new ServerResponse<Uri>(false, default(Uri)));
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is ExamSelectionEventArgs e)
|
||||
{
|
||||
e.Success = true;
|
||||
e.SelectedExam = exam;
|
||||
}
|
||||
|
||||
if (args is ServerFailureEventArgs s)
|
||||
{
|
||||
s.Abort = true;
|
||||
messageShown = true;
|
||||
}
|
||||
};
|
||||
server.Setup(s => s.GetAvailableExams(It.IsAny<string>())).Returns(new ServerResponse<IEnumerable<Exam>>(true, default));
|
||||
server.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>())).Returns(new ServerResponse<Uri>(false, default));
|
||||
serverDialog
|
||||
.Setup(d => d.Show(It.IsAny<IWindow>()))
|
||||
.Returns(new ServerFailureDialogResult { Abort = true })
|
||||
.Callback(() => messageShown = true);
|
||||
uiFactory.Setup(f => f.CreateExamSelectionDialog(It.IsAny<IEnumerable<Exam>>())).Returns(examDialog.Object);
|
||||
uiFactory.Setup(f => f.CreateServerFailureDialog(It.IsAny<string>(), It.IsAny<bool>())).Returns(serverDialog.Object);
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
@@ -220,30 +220,25 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
var connection = new ConnectionInfo { Api = "some API", ConnectionToken = "some token", Oauth2Token = "some OAuth2 token" };
|
||||
var exam = new Exam { Id = "some id", LmsName = "some LMS", Name = "some name", Url = "some URL" };
|
||||
var examDialog = new Mock<IExamSelectionDialog>();
|
||||
var examSettings = new AppSettings();
|
||||
var messageShown = false;
|
||||
var serverDialog = new Mock<IServerFailureDialog>();
|
||||
|
||||
configuration.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
examDialog.Setup(d => d.Show(It.IsAny<IWindow>())).Returns(new ExamSelectionDialogResult { SelectedExam = exam, Success = true });
|
||||
repository.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
context.Next.Settings.SessionMode = SessionMode.Server;
|
||||
server.Setup(s => s.Connect()).Returns(new ServerResponse(true));
|
||||
server.Setup(s => s.Initialize(It.IsAny<ServerSettings>()));
|
||||
server.Setup(s => s.GetConnectionInfo()).Returns(connection);
|
||||
server.Setup(s => s.GetAvailableExams(It.IsAny<string>())).Returns(new ServerResponse<IEnumerable<Exam>>(true, default(IEnumerable<Exam>)));
|
||||
server.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>())).Returns(new ServerResponse<Uri>(false, default(Uri)));
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is ExamSelectionEventArgs e)
|
||||
{
|
||||
e.Success = true;
|
||||
e.SelectedExam = exam;
|
||||
}
|
||||
|
||||
if (args is ServerFailureEventArgs s)
|
||||
{
|
||||
s.Fallback = true;
|
||||
messageShown = true;
|
||||
}
|
||||
};
|
||||
server.Setup(s => s.GetAvailableExams(It.IsAny<string>())).Returns(new ServerResponse<IEnumerable<Exam>>(true, default));
|
||||
server.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>())).Returns(new ServerResponse<Uri>(false, default));
|
||||
serverDialog
|
||||
.Setup(d => d.Show(It.IsAny<IWindow>()))
|
||||
.Returns(new ServerFailureDialogResult { Fallback = true })
|
||||
.Callback(() => messageShown = true);
|
||||
uiFactory.Setup(f => f.CreateExamSelectionDialog(It.IsAny<IEnumerable<Exam>>())).Returns(examDialog.Object);
|
||||
uiFactory.Setup(f => f.CreateServerFailureDialog(It.IsAny<string>(), It.IsAny<bool>())).Returns(serverDialog.Object);
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
@@ -266,8 +261,11 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var exam = new Exam { Id = "some id", LmsName = "some LMS", Name = "some name", Url = "some URL" };
|
||||
var examSettings = new AppSettings();
|
||||
var serverSettings = context.Next.Settings.Server;
|
||||
var examDialog = new Mock<IExamSelectionDialog>();
|
||||
var serverDialog = new Mock<IServerFailureDialog>();
|
||||
|
||||
configuration.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
examDialog.Setup(d => d.Show(It.IsAny<IWindow>())).Callback(Assert.Fail);
|
||||
repository.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
context.Next.Settings.SessionMode = SessionMode.Server;
|
||||
context.Next.Settings.Server.ExamId = "some id";
|
||||
fileSystem.Setup(f => f.Delete(It.IsAny<string>()));
|
||||
@@ -277,7 +275,9 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
server.Setup(s => s.GetAvailableExams(It.IsAny<string>())).Returns(new ServerResponse<IEnumerable<Exam>>(true, new[] { exam }));
|
||||
server.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>())).Returns(new ServerResponse<Uri>(true, new Uri("file:///configuration.seb")));
|
||||
server.Setup(s => s.SendSelectedExam(It.IsAny<Exam>())).Returns(new ServerResponse<string>(true, default));
|
||||
sut.ActionRequired += (args) => Assert.Fail();
|
||||
serverDialog.Setup(d => d.Show(It.IsAny<IWindow>())).Callback(Assert.Fail);
|
||||
uiFactory.Setup(f => f.CreateExamSelectionDialog(It.IsAny<IEnumerable<Exam>>())).Returns(examDialog.Object);
|
||||
uiFactory.Setup(f => f.CreateServerFailureDialog(It.IsAny<string>(), It.IsAny<bool>())).Returns(serverDialog.Object);
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
@@ -298,13 +298,13 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var initialSettings = context.Next.Settings;
|
||||
|
||||
context.Next.Settings.SessionMode = SessionMode.Normal;
|
||||
sut.ActionRequired += (_) => Assert.Fail();
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
configuration.VerifyNoOtherCalls();
|
||||
repository.VerifyNoOtherCalls();
|
||||
fileSystem.VerifyNoOtherCalls();
|
||||
server.VerifyNoOtherCalls();
|
||||
uiFactory.VerifyNoOtherCalls();
|
||||
|
||||
Assert.AreSame(initialSettings, context.Next.Settings);
|
||||
Assert.AreEqual(SessionMode.Normal, context.Next.Settings.SessionMode);
|
||||
@@ -318,6 +318,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var connection = new ConnectionInfo { Api = "some API", ConnectionToken = "some token", Oauth2Token = "some OAuth2 token" };
|
||||
var counter = 0;
|
||||
var delete = 0;
|
||||
var dialog = new Mock<IExamSelectionDialog>();
|
||||
var exam = new Exam { Id = "some id", LmsName = "some LMS", Name = "some name", Url = "some URL" };
|
||||
var examSelection = 0;
|
||||
var examSettings = new AppSettings();
|
||||
@@ -328,7 +329,11 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var initialSettings = context.Next.Settings;
|
||||
var serverSettings = context.Next.Settings.Server;
|
||||
|
||||
configuration
|
||||
dialog
|
||||
.Setup(d => d.Show(It.IsAny<IWindow>()))
|
||||
.Returns(new ExamSelectionDialogResult { SelectedExam = exam, Success = true })
|
||||
.Callback(() => examSelection = ++counter);
|
||||
repository
|
||||
.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>()))
|
||||
.Returns(LoadStatus.Success);
|
||||
context.Next.Settings.SessionMode = SessionMode.Server;
|
||||
@@ -339,21 +344,13 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
server.Setup(s => s.SendSelectedExam(It.IsAny<Exam>())).Returns(new ServerResponse<string>(true, default));
|
||||
server
|
||||
.Setup(s => s.GetAvailableExams(It.IsAny<string>()))
|
||||
.Returns(new ServerResponse<IEnumerable<Exam>>(true, default(IEnumerable<Exam>)))
|
||||
.Returns(new ServerResponse<IEnumerable<Exam>>(true, default))
|
||||
.Callback(() => getExams = ++counter);
|
||||
server
|
||||
.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>()))
|
||||
.Returns(new ServerResponse<Uri>(true, new Uri("file:///configuration.seb")))
|
||||
.Callback(() => getConfiguration = ++counter);
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is ExamSelectionEventArgs e)
|
||||
{
|
||||
e.Success = true;
|
||||
e.SelectedExam = exam;
|
||||
examSelection = ++counter;
|
||||
}
|
||||
};
|
||||
uiFactory.Setup(f => f.CreateExamSelectionDialog(It.IsAny<IEnumerable<Exam>>())).Returns(dialog.Object);
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
@@ -391,22 +388,17 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var exam = new Exam { Id = "some id", LmsName = "some LMS", Name = "some name", Url = "some URL" };
|
||||
var examSettings = new AppSettings();
|
||||
var initialSettings = context.Next.Settings;
|
||||
var dialog = new Mock<IExamSelectionDialog>();
|
||||
|
||||
configuration.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.UnexpectedError);
|
||||
dialog.Setup(d => d.Show(It.IsAny<IWindow>())).Returns(new ExamSelectionDialogResult { SelectedExam = exam, Success = true });
|
||||
repository.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.UnexpectedError);
|
||||
context.Next.Settings.SessionMode = SessionMode.Server;
|
||||
server.Setup(s => s.Connect()).Returns(new ServerResponse(true));
|
||||
server.Setup(s => s.Initialize(It.IsAny<ServerSettings>()));
|
||||
server.Setup(s => s.GetConnectionInfo()).Returns(connection);
|
||||
server.Setup(s => s.GetAvailableExams(It.IsAny<string>())).Returns(new ServerResponse<IEnumerable<Exam>>(true, default(IEnumerable<Exam>)));
|
||||
server.Setup(s => s.GetAvailableExams(It.IsAny<string>())).Returns(new ServerResponse<IEnumerable<Exam>>(true, default));
|
||||
server.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>())).Returns(new ServerResponse<Uri>(true, new Uri("file:///configuration.seb")));
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is ExamSelectionEventArgs e)
|
||||
{
|
||||
e.Success = true;
|
||||
e.SelectedExam = exam;
|
||||
}
|
||||
};
|
||||
uiFactory.Setup(f => f.CreateExamSelectionDialog(It.IsAny<IEnumerable<Exam>>())).Returns(dialog.Object);
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
@@ -435,28 +427,25 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var exam = new Exam { Id = "some id", LmsName = "some LMS", Name = "some name", Url = "some URL" };
|
||||
var examSettings = new AppSettings();
|
||||
var messageShown = false;
|
||||
var examDialog = new Mock<IExamSelectionDialog>();
|
||||
var serverDialog = new Mock<IServerFailureDialog>();
|
||||
|
||||
configuration.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
examDialog
|
||||
.Setup(d => d.Show(It.IsAny<IWindow>()))
|
||||
.Returns(new ExamSelectionDialogResult { SelectedExam = exam, Success = true });
|
||||
repository.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
context.Next.Settings.SessionMode = SessionMode.Server;
|
||||
server.Setup(s => s.Connect()).Returns(new ServerResponse(true));
|
||||
server.Setup(s => s.Initialize(It.IsAny<ServerSettings>()));
|
||||
server.Setup(s => s.GetConnectionInfo()).Returns(connection);
|
||||
server.Setup(s => s.GetAvailableExams(It.IsAny<string>())).Returns(new ServerResponse<IEnumerable<Exam>>(true, default(IEnumerable<Exam>)));
|
||||
server.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>())).Returns(new ServerResponse<Uri>(false, default(Uri)));
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is ExamSelectionEventArgs e)
|
||||
{
|
||||
e.Success = true;
|
||||
e.SelectedExam = exam;
|
||||
}
|
||||
|
||||
if (args is ServerFailureEventArgs s)
|
||||
{
|
||||
s.Abort = true;
|
||||
messageShown = true;
|
||||
}
|
||||
};
|
||||
server.Setup(s => s.GetAvailableExams(It.IsAny<string>())).Returns(new ServerResponse<IEnumerable<Exam>>(true, default));
|
||||
server.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>())).Returns(new ServerResponse<Uri>(false, default));
|
||||
serverDialog
|
||||
.Setup(d => d.Show(It.IsAny<IWindow>()))
|
||||
.Returns(new ServerFailureDialogResult { Abort = true })
|
||||
.Callback(() => messageShown = true);
|
||||
uiFactory.Setup(f => f.CreateExamSelectionDialog(It.IsAny<IEnumerable<Exam>>())).Returns(examDialog.Object);
|
||||
uiFactory.Setup(f => f.CreateServerFailureDialog(It.IsAny<string>(), It.IsAny<bool>())).Returns(serverDialog.Object);
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
@@ -478,28 +467,23 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var exam = new Exam { Id = "some id", LmsName = "some LMS", Name = "some name", Url = "some URL" };
|
||||
var examSettings = new AppSettings();
|
||||
var messageShown = false;
|
||||
var examDialog = new Mock<IExamSelectionDialog>();
|
||||
var serverDialog = new Mock<IServerFailureDialog>();
|
||||
|
||||
configuration.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
examDialog.Setup(d => d.Show(It.IsAny<IWindow>())).Returns(new ExamSelectionDialogResult { SelectedExam = exam, Success = true });
|
||||
repository.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
context.Next.Settings.SessionMode = SessionMode.Server;
|
||||
server.Setup(s => s.Connect()).Returns(new ServerResponse(true));
|
||||
server.Setup(s => s.Initialize(It.IsAny<ServerSettings>()));
|
||||
server.Setup(s => s.GetConnectionInfo()).Returns(connection);
|
||||
server.Setup(s => s.GetAvailableExams(It.IsAny<string>())).Returns(new ServerResponse<IEnumerable<Exam>>(true, default(IEnumerable<Exam>)));
|
||||
server.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>())).Returns(new ServerResponse<Uri>(false, default(Uri)));
|
||||
sut.ActionRequired += (args) =>
|
||||
{
|
||||
if (args is ExamSelectionEventArgs e)
|
||||
{
|
||||
e.Success = true;
|
||||
e.SelectedExam = exam;
|
||||
}
|
||||
|
||||
if (args is ServerFailureEventArgs s)
|
||||
{
|
||||
s.Fallback = true;
|
||||
messageShown = true;
|
||||
}
|
||||
};
|
||||
server.Setup(s => s.GetAvailableExams(It.IsAny<string>())).Returns(new ServerResponse<IEnumerable<Exam>>(true, default));
|
||||
server.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>())).Returns(new ServerResponse<Uri>(false, default));
|
||||
serverDialog
|
||||
.Setup(d => d.Show(It.IsAny<IWindow>()))
|
||||
.Returns(new ServerFailureDialogResult { Fallback = true })
|
||||
.Callback(() => messageShown = true);
|
||||
uiFactory.Setup(f => f.CreateExamSelectionDialog(It.IsAny<IEnumerable<Exam>>())).Returns(examDialog.Object);
|
||||
uiFactory.Setup(f => f.CreateServerFailureDialog(It.IsAny<string>(), It.IsAny<bool>())).Returns(serverDialog.Object);
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
@@ -515,6 +499,83 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Repeat_MustCorrectlyReconfigureServerSession()
|
||||
{
|
||||
var connect = 0;
|
||||
var connection = new ConnectionInfo { Api = "some API", ConnectionToken = "some token", Oauth2Token = "some OAuth2 token" };
|
||||
var counter = 0;
|
||||
var delete = 0;
|
||||
var dialog = new Mock<IExamSelectionDialog>();
|
||||
var disconnect = 0;
|
||||
var exam = new Exam { Id = "some id", LmsName = "some LMS", Name = "some name", Url = "some URL" };
|
||||
var examSelection = 0;
|
||||
var examSettings = new AppSettings();
|
||||
var getConfiguration = 0;
|
||||
var getConnection = 0;
|
||||
var getExams = 0;
|
||||
var initialize = 0;
|
||||
var initialSettings = context.Next.Settings;
|
||||
var serverSettings = context.Next.Settings.Server;
|
||||
|
||||
dialog
|
||||
.Setup(d => d.Show(It.IsAny<IWindow>()))
|
||||
.Returns(new ExamSelectionDialogResult { SelectedExam = exam, Success = true })
|
||||
.Callback(() => examSelection = ++counter);
|
||||
repository
|
||||
.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>()))
|
||||
.Returns(LoadStatus.Success);
|
||||
context.Current.Settings.SessionMode = SessionMode.Server;
|
||||
context.Next.Settings.SessionMode = SessionMode.Server;
|
||||
fileSystem.Setup(f => f.Delete(It.IsAny<string>())).Callback(() => delete = ++counter);
|
||||
server.Setup(s => s.Connect()).Returns(new ServerResponse(true)).Callback(() => connect = ++counter);
|
||||
server.Setup(s => s.Disconnect()).Returns(new ServerResponse(true)).Callback(() => disconnect = ++counter);
|
||||
server.Setup(s => s.Initialize(It.IsAny<ServerSettings>())).Callback(() => initialize = ++counter);
|
||||
server.Setup(s => s.GetConnectionInfo()).Returns(connection).Callback(() => getConnection = ++counter);
|
||||
server.Setup(s => s.SendSelectedExam(It.IsAny<Exam>())).Returns(new ServerResponse<string>(true, default));
|
||||
server
|
||||
.Setup(s => s.GetAvailableExams(It.IsAny<string>()))
|
||||
.Returns(new ServerResponse<IEnumerable<Exam>>(true, default))
|
||||
.Callback(() => getExams = ++counter);
|
||||
server
|
||||
.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>()))
|
||||
.Returns(new ServerResponse<Uri>(true, new Uri("file:///configuration.seb")))
|
||||
.Callback(() => getConfiguration = ++counter);
|
||||
uiFactory.Setup(f => f.CreateExamSelectionDialog(It.IsAny<IEnumerable<Exam>>())).Returns(dialog.Object);
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
|
||||
fileSystem.Verify(f => f.Delete(It.IsAny<string>()), Times.Once);
|
||||
server.Verify(s => s.Connect(), Times.Once);
|
||||
server.Verify(s => s.Disconnect(), Times.Once);
|
||||
server.Verify(s => s.Initialize(It.IsAny<ServerSettings>()), Times.Once);
|
||||
server.Verify(s => s.GetAvailableExams(It.IsAny<string>()), Times.Once);
|
||||
server.Verify(s => s.GetConfigurationFor(It.Is<Exam>(e => e == exam)), Times.Once);
|
||||
server.Verify(s => s.GetConnectionInfo(), Times.Once);
|
||||
server.Verify(s => s.SendSelectedExam(It.Is<Exam>(e => e == exam)), Times.Once);
|
||||
|
||||
Assert.AreEqual(1, disconnect);
|
||||
Assert.AreEqual(2, initialize);
|
||||
Assert.AreEqual(3, connect);
|
||||
Assert.AreEqual(4, getExams);
|
||||
Assert.AreEqual(5, examSelection);
|
||||
Assert.AreEqual(6, getConfiguration);
|
||||
Assert.AreEqual(7, getConnection);
|
||||
Assert.AreEqual(8, delete);
|
||||
Assert.AreEqual(connection.Api, context.Next.AppConfig.ServerApi);
|
||||
Assert.AreEqual(connection.ConnectionToken, context.Next.AppConfig.ServerConnectionToken);
|
||||
Assert.AreEqual(connection.Oauth2Token, context.Next.AppConfig.ServerOauth2Token);
|
||||
Assert.AreEqual(exam.Id, context.Next.AppConfig.ServerExamId);
|
||||
Assert.AreEqual(exam.Url, context.Next.Settings.Browser.StartUrl);
|
||||
Assert.AreSame(examSettings, context.Next.Settings);
|
||||
Assert.AreSame(serverSettings, context.Next.Settings.Server);
|
||||
Assert.AreNotSame(initialSettings, context.Next.Settings);
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
Assert.AreEqual(SessionMode.Server, context.Next.Settings.SessionMode);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Repeat_MustAutomaticallySelectExam()
|
||||
{
|
||||
@@ -522,8 +583,10 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var exam = new Exam { Id = "some id", LmsName = "some LMS", Name = "some name", Url = "some URL" };
|
||||
var examSettings = new AppSettings();
|
||||
var serverSettings = context.Next.Settings.Server;
|
||||
var dialog = new Mock<IExamSelectionDialog>();
|
||||
|
||||
configuration.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
dialog.Setup(d => d.Show(It.IsAny<IWindow>())).Callback(Assert.Fail);
|
||||
repository.Setup(c => c.TryLoadSettings(It.IsAny<Uri>(), out examSettings, It.IsAny<PasswordParameters>())).Returns(LoadStatus.Success);
|
||||
context.Next.Settings.SessionMode = SessionMode.Server;
|
||||
context.Next.Settings.Server.ExamId = "some id";
|
||||
fileSystem.Setup(f => f.Delete(It.IsAny<string>()));
|
||||
@@ -533,7 +596,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
server.Setup(s => s.GetAvailableExams(It.IsAny<string>())).Returns(new ServerResponse<IEnumerable<Exam>>(true, new[] { exam }));
|
||||
server.Setup(s => s.GetConfigurationFor(It.IsAny<Exam>())).Returns(new ServerResponse<Uri>(true, new Uri("file:///configuration.seb")));
|
||||
server.Setup(s => s.SendSelectedExam(It.IsAny<Exam>())).Returns(new ServerResponse<string>(true, default));
|
||||
sut.ActionRequired += (args) => Assert.Fail();
|
||||
uiFactory.Setup(f => f.CreateExamSelectionDialog(It.IsAny<IEnumerable<Exam>>())).Returns(dialog.Object);
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
@@ -548,36 +611,6 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Repeat_MustNotAllowToReconfigureServerSession()
|
||||
{
|
||||
var args = default(ActionRequiredEventArgs);
|
||||
|
||||
context.Current.AppConfig.ServerApi = "api";
|
||||
context.Current.AppConfig.ServerConnectionToken = "token";
|
||||
context.Current.AppConfig.ServerExamId = "id";
|
||||
context.Current.AppConfig.ServerOauth2Token = "oauth2";
|
||||
context.Current.Settings.SessionMode = SessionMode.Server;
|
||||
context.Next.Settings.SessionMode = SessionMode.Server;
|
||||
|
||||
sut.ActionRequired += (a) =>
|
||||
{
|
||||
args = a;
|
||||
};
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
configuration.VerifyNoOtherCalls();
|
||||
fileSystem.VerifyNoOtherCalls();
|
||||
server.VerifyNoOtherCalls();
|
||||
|
||||
Assert.IsNull(context.Next.AppConfig.ServerApi);
|
||||
Assert.IsNull(context.Next.AppConfig.ServerConnectionToken);
|
||||
Assert.IsNull(context.Next.AppConfig.ServerOauth2Token);
|
||||
Assert.IsInstanceOfType(args, typeof(MessageEventArgs));
|
||||
Assert.AreEqual(OperationResult.Aborted, result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Repeat_MustDoNothingIfNormalSession()
|
||||
{
|
||||
@@ -585,13 +618,13 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
context.Current.Settings.SessionMode = SessionMode.Normal;
|
||||
context.Next.Settings.SessionMode = SessionMode.Normal;
|
||||
sut.ActionRequired += (_) => Assert.Fail();
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
configuration.VerifyNoOtherCalls();
|
||||
repository.VerifyNoOtherCalls();
|
||||
fileSystem.VerifyNoOtherCalls();
|
||||
server.VerifyNoOtherCalls();
|
||||
uiFactory.VerifyNoOtherCalls();
|
||||
|
||||
Assert.AreSame(initialSettings, context.Next.Settings);
|
||||
Assert.AreEqual(SessionMode.Normal, context.Next.Settings.SessionMode);
|
||||
@@ -646,13 +679,13 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
public void Revert_MustDoNothingIfNormalSession()
|
||||
{
|
||||
context.Current.Settings.SessionMode = SessionMode.Normal;
|
||||
sut.ActionRequired += (_) => Assert.Fail();
|
||||
|
||||
var result = sut.Revert();
|
||||
|
||||
configuration.VerifyNoOtherCalls();
|
||||
repository.VerifyNoOtherCalls();
|
||||
fileSystem.VerifyNoOtherCalls();
|
||||
server.VerifyNoOtherCalls();
|
||||
uiFactory.VerifyNoOtherCalls();
|
||||
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
}
|
||||
|
@@ -14,25 +14,29 @@ using SafeExamBrowser.Communication.Contracts.Hosts;
|
||||
using SafeExamBrowser.Communication.Contracts.Proxies;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Runtime.Operations;
|
||||
using SafeExamBrowser.Runtime.Operations.Events;
|
||||
using SafeExamBrowser.Runtime.Communication;
|
||||
using SafeExamBrowser.Runtime.Operations.Session;
|
||||
using SafeExamBrowser.Settings;
|
||||
using SafeExamBrowser.Settings.Service;
|
||||
using SafeExamBrowser.SystemComponents.Contracts;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
[TestClass]
|
||||
public class ServiceOperationTests
|
||||
{
|
||||
private SessionContext context;
|
||||
private Mock<ILogger> logger;
|
||||
private RuntimeContext context;
|
||||
private Dependencies dependencies;
|
||||
private Mock<IMessageBox> messageBox;
|
||||
private Mock<IRuntimeHost> runtimeHost;
|
||||
private Mock<IServiceProxy> service;
|
||||
private EventWaitHandle serviceEvent;
|
||||
private Mock<IUserInfo> userInfo;
|
||||
|
||||
private ServiceOperation sut;
|
||||
|
||||
[TestInitialize]
|
||||
@@ -40,11 +44,11 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
var serviceEventName = $"{nameof(SafeExamBrowser)}-{nameof(ServiceOperationTests)}";
|
||||
|
||||
logger = new Mock<ILogger>();
|
||||
context = new RuntimeContext();
|
||||
messageBox = new Mock<IMessageBox>();
|
||||
runtimeHost = new Mock<IRuntimeHost>();
|
||||
service = new Mock<IServiceProxy>();
|
||||
serviceEvent = new EventWaitHandle(false, EventResetMode.AutoReset, serviceEventName);
|
||||
context = new SessionContext();
|
||||
userInfo = new Mock<IUserInfo>();
|
||||
|
||||
context.Current = new SessionConfiguration();
|
||||
@@ -56,7 +60,15 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
context.Next.AppConfig.ServiceEventName = serviceEventName;
|
||||
context.Next.Settings = new AppSettings();
|
||||
|
||||
sut = new ServiceOperation(logger.Object, runtimeHost.Object, service.Object, context, 0, userInfo.Object);
|
||||
dependencies = new Dependencies(
|
||||
new ClientBridge(Mock.Of<IRuntimeHost>(), context),
|
||||
Mock.Of<ILogger>(),
|
||||
messageBox.Object,
|
||||
Mock.Of<IRuntimeWindow>(),
|
||||
context,
|
||||
Mock.Of<IText>());
|
||||
|
||||
sut = new ServiceOperation(dependencies, runtimeHost.Object, service.Object, 0, userInfo.Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -137,7 +149,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
service.Setup(s => s.Connect(null, true)).Returns(true);
|
||||
service.Setup(s => s.StartSession(It.IsAny<ServiceConfiguration>())).Returns(new CommunicationResult(true));
|
||||
|
||||
sut = new ServiceOperation(logger.Object, runtimeHost.Object, service.Object, context, TIMEOUT, userInfo.Object);
|
||||
sut = new ServiceOperation(dependencies, runtimeHost.Object, service.Object, TIMEOUT, userInfo.Object);
|
||||
|
||||
before = DateTime.Now;
|
||||
var result = sut.Perform();
|
||||
@@ -183,9 +195,11 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var errorShown = false;
|
||||
|
||||
context.Next.Settings.Service.Policy = ServicePolicy.Mandatory;
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => errorShown = true);
|
||||
service.SetupGet(s => s.IsConnected).Returns(false);
|
||||
service.Setup(s => s.Connect(null, true)).Returns(false);
|
||||
sut.ActionRequired += (args) => errorShown = args is MessageEventArgs m && m.Icon == MessageBoxIcon.Error;
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
@@ -213,9 +227,11 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var warningShown = false;
|
||||
|
||||
context.Next.Settings.Service.Policy = ServicePolicy.Warn;
|
||||
messageBox
|
||||
.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()))
|
||||
.Callback(() => warningShown = true);
|
||||
service.SetupGet(s => s.IsConnected).Returns(false);
|
||||
service.Setup(s => s.Connect(null, true)).Returns(false);
|
||||
sut.ActionRequired += (args) => warningShown = args is MessageEventArgs m && m.Icon == MessageBoxIcon.Warning;
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
@@ -264,9 +280,9 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
service.Verify(s => s.RunSystemConfigurationUpdate(), Times.Never);
|
||||
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
Assert.IsTrue(start1 == 1);
|
||||
Assert.IsTrue(stop1 == 2);
|
||||
Assert.IsTrue(start2 == 3);
|
||||
Assert.AreEqual(1, start1);
|
||||
Assert.AreEqual(2, stop1);
|
||||
Assert.AreEqual(3, start2);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -358,7 +374,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var before = default(DateTime);
|
||||
|
||||
service.Setup(s => s.StopSession(It.IsAny<Guid>())).Returns(new CommunicationResult(true));
|
||||
sut = new ServiceOperation(logger.Object, runtimeHost.Object, service.Object, context, TIMEOUT, userInfo.Object);
|
||||
sut = new ServiceOperation(dependencies, runtimeHost.Object, service.Object, TIMEOUT, userInfo.Object);
|
||||
|
||||
PerformNormally();
|
||||
|
||||
@@ -458,7 +474,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var before = default(DateTime);
|
||||
|
||||
service.Setup(s => s.StopSession(It.IsAny<Guid>())).Returns(new CommunicationResult(true));
|
||||
sut = new ServiceOperation(logger.Object, runtimeHost.Object, service.Object, context, TIMEOUT, userInfo.Object);
|
||||
sut = new ServiceOperation(dependencies, runtimeHost.Object, service.Object, TIMEOUT, userInfo.Object);
|
||||
|
||||
PerformNormally();
|
||||
|
||||
@@ -537,8 +553,8 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
PerformNormally();
|
||||
|
||||
context.Current.SessionId = default(Guid);
|
||||
context.Next.SessionId = default(Guid);
|
||||
context.Current.SessionId = default;
|
||||
context.Next.SessionId = default;
|
||||
service.Setup(s => s.StopSession(It.Is<Guid>(id => id == sessionId))).Returns(new CommunicationResult(true)).Callback(() => serviceEvent.Set());
|
||||
service.Setup(s => s.RunSystemConfigurationUpdate()).Returns(new CommunicationResult(true));
|
||||
service.Setup(s => s.Disconnect()).Returns(true);
|
||||
@@ -546,7 +562,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var result = sut.Revert();
|
||||
|
||||
service.Verify(s => s.StopSession(It.Is<Guid>(id => id == sessionId)), Times.Once);
|
||||
service.Verify(s => s.StopSession(It.Is<Guid>(id => id == default(Guid))), Times.Never);
|
||||
service.Verify(s => s.StopSession(It.Is<Guid>(id => id == default)), Times.Never);
|
||||
service.Verify(s => s.Disconnect(), Times.Once);
|
||||
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
|
@@ -8,12 +8,17 @@
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts.Hosts;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Runtime.Operations;
|
||||
using SafeExamBrowser.Runtime.Communication;
|
||||
using SafeExamBrowser.Runtime.Operations.Session;
|
||||
using SafeExamBrowser.Settings;
|
||||
using SafeExamBrowser.Settings.Logging;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
@@ -24,8 +29,7 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
private Mock<ILogger> logger;
|
||||
private SessionConfiguration nextSession;
|
||||
private AppSettings nextSettings;
|
||||
private SessionContext sessionContext;
|
||||
|
||||
private RuntimeContext runtimeContext;
|
||||
private SessionActivationOperation sut;
|
||||
|
||||
[TestInitialize]
|
||||
@@ -35,25 +39,33 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
logger = new Mock<ILogger>();
|
||||
nextSession = new SessionConfiguration();
|
||||
nextSettings = new AppSettings();
|
||||
sessionContext = new SessionContext();
|
||||
runtimeContext = new RuntimeContext();
|
||||
|
||||
nextSession.Settings = nextSettings;
|
||||
sessionContext.Current = currentSession;
|
||||
sessionContext.Next = nextSession;
|
||||
runtimeContext.Current = currentSession;
|
||||
runtimeContext.Next = nextSession;
|
||||
|
||||
sut = new SessionActivationOperation(logger.Object, sessionContext);
|
||||
var dependencies = new Dependencies(
|
||||
new ClientBridge(Mock.Of<IRuntimeHost>(), runtimeContext),
|
||||
logger.Object,
|
||||
Mock.Of<IMessageBox>(),
|
||||
Mock.Of<IRuntimeWindow>(),
|
||||
runtimeContext,
|
||||
Mock.Of<IText>());
|
||||
|
||||
sut = new SessionActivationOperation(dependencies);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Perform_MustCorrectlyActivateFirstSession()
|
||||
{
|
||||
sessionContext.Current = null;
|
||||
runtimeContext.Current = null;
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
Assert.AreSame(sessionContext.Current, nextSession);
|
||||
Assert.IsNull(sessionContext.Next);
|
||||
Assert.AreSame(runtimeContext.Current, nextSession);
|
||||
Assert.IsNull(runtimeContext.Next);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -72,8 +84,8 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
var result = sut.Repeat();
|
||||
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
Assert.AreSame(sessionContext.Current, nextSession);
|
||||
Assert.IsNull(sessionContext.Next);
|
||||
Assert.AreSame(runtimeContext.Current, nextSession);
|
||||
Assert.IsNull(runtimeContext.Next);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
@@ -12,9 +12,13 @@ using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts.Hosts;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Runtime.Operations;
|
||||
using SafeExamBrowser.Runtime.Communication;
|
||||
using SafeExamBrowser.Runtime.Operations.Session;
|
||||
using SafeExamBrowser.SystemComponents.Contracts;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
@@ -22,12 +26,11 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
public class SessionInitializationOperationTests
|
||||
{
|
||||
private AppConfig appConfig;
|
||||
private Mock<IConfigurationRepository> configuration;
|
||||
private RuntimeContext context;
|
||||
private Mock<IFileSystem> fileSystem;
|
||||
private Mock<ILogger> logger;
|
||||
private Mock<IRuntimeHost> runtimeHost;
|
||||
private Mock<IConfigurationRepository> repository;
|
||||
private SessionConfiguration session;
|
||||
private SessionContext sessionContext;
|
||||
|
||||
private SessionInitializationOperation sut;
|
||||
|
||||
@@ -35,18 +38,25 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
public void Initialize()
|
||||
{
|
||||
appConfig = new AppConfig();
|
||||
configuration = new Mock<IConfigurationRepository>();
|
||||
context = new RuntimeContext();
|
||||
repository = new Mock<IConfigurationRepository>();
|
||||
fileSystem = new Mock<IFileSystem>();
|
||||
logger = new Mock<ILogger>();
|
||||
runtimeHost = new Mock<IRuntimeHost>();
|
||||
session = new SessionConfiguration();
|
||||
sessionContext = new SessionContext();
|
||||
|
||||
configuration.Setup(c => c.InitializeSessionConfiguration()).Returns(session);
|
||||
context.Next = session;
|
||||
repository.Setup(c => c.InitializeSessionConfiguration()).Returns(session);
|
||||
session.AppConfig = appConfig;
|
||||
sessionContext.Next = session;
|
||||
|
||||
sut = new SessionInitializationOperation(configuration.Object, fileSystem.Object, logger.Object, runtimeHost.Object, sessionContext);
|
||||
var dependencies = new Dependencies(
|
||||
new ClientBridge(Mock.Of<IRuntimeHost>(), context),
|
||||
logger.Object,
|
||||
Mock.Of<IMessageBox>(),
|
||||
Mock.Of<IRuntimeWindow>(),
|
||||
context,
|
||||
Mock.Of<IText>());
|
||||
|
||||
sut = new SessionInitializationOperation(dependencies, fileSystem.Object, repository.Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -59,11 +69,11 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
var result = sut.Perform();
|
||||
|
||||
configuration.Verify(c => c.InitializeSessionConfiguration(), Times.Once);
|
||||
repository.Verify(c => c.InitializeSessionConfiguration(), Times.Once);
|
||||
fileSystem.Verify(f => f.CreateDirectory(It.Is<string>(s => s == appConfig.TemporaryDirectory)), Times.Once);
|
||||
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
Assert.IsNull(sessionContext.Current);
|
||||
Assert.IsNull(context.Current);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -74,15 +84,15 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
|
||||
appConfig.TemporaryDirectory = @"C:\Some\Random\Path";
|
||||
session.ClientAuthenticationToken = token;
|
||||
sessionContext.Current = currentSession;
|
||||
context.Current = currentSession;
|
||||
|
||||
var result = sut.Repeat();
|
||||
|
||||
configuration.Verify(c => c.InitializeSessionConfiguration(), Times.Once);
|
||||
repository.Verify(c => c.InitializeSessionConfiguration(), Times.Once);
|
||||
fileSystem.Verify(f => f.CreateDirectory(It.Is<string>(s => s == appConfig.TemporaryDirectory)), Times.Once);
|
||||
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
Assert.AreSame(currentSession,sessionContext.Current);
|
||||
Assert.AreSame(currentSession, context.Current);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -90,10 +100,9 @@ namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
var result = sut.Revert();
|
||||
|
||||
configuration.VerifyNoOtherCalls();
|
||||
repository.VerifyNoOtherCalls();
|
||||
fileSystem.VerifyNoOtherCalls();
|
||||
logger.VerifyNoOtherCalls();
|
||||
runtimeHost.VerifyNoOtherCalls();
|
||||
|
||||
Assert.AreEqual(OperationResult.Success, result);
|
||||
}
|
||||
|
@@ -8,35 +8,49 @@
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts.Hosts;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Core.Contracts.OperationModel;
|
||||
using SafeExamBrowser.I18n.Contracts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
using SafeExamBrowser.Monitoring.Contracts;
|
||||
using SafeExamBrowser.Runtime.Operations;
|
||||
using SafeExamBrowser.Runtime.Communication;
|
||||
using SafeExamBrowser.Runtime.Operations.Session;
|
||||
using SafeExamBrowser.Settings;
|
||||
using SafeExamBrowser.Settings.Security;
|
||||
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
||||
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
||||
|
||||
namespace SafeExamBrowser.Runtime.UnitTests.Operations
|
||||
{
|
||||
[TestClass]
|
||||
public class VirtualMachineOperationTests
|
||||
{
|
||||
private RuntimeContext context;
|
||||
private Mock<IVirtualMachineDetector> detector;
|
||||
private Mock<ILogger> logger;
|
||||
private SessionContext context;
|
||||
|
||||
private VirtualMachineOperation sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
context = new RuntimeContext();
|
||||
detector = new Mock<IVirtualMachineDetector>();
|
||||
logger = new Mock<ILogger>();
|
||||
context = new SessionContext();
|
||||
|
||||
context.Next = new SessionConfiguration();
|
||||
context.Next.Settings = new AppSettings();
|
||||
|
||||
sut = new VirtualMachineOperation(detector.Object, logger.Object, context);
|
||||
var dependencies = new Dependencies(
|
||||
new ClientBridge(Mock.Of<IRuntimeHost>(), context),
|
||||
logger.Object,
|
||||
Mock.Of<IMessageBox>(),
|
||||
Mock.Of<IRuntimeWindow>(),
|
||||
context,
|
||||
Mock.Of<IText>());
|
||||
|
||||
sut = new VirtualMachineOperation(dependencies, detector.Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
Reference in New Issue
Block a user