SEBWIN-296: Extended unit tests for runtime host and controller.

This commit is contained in:
dbuechel 2019-02-26 08:40:00 +01:00
parent 9892ace4d9
commit f32bf19f50
2 changed files with 126 additions and 2 deletions

View file

@ -274,6 +274,22 @@ namespace SafeExamBrowser.Runtime.UnitTests.Communication
Assert.AreEqual(SimpleResponsePurport.UnknownMessage, (response as SimpleResponse)?.Purport);
}
[TestMethod]
public void MustNotFailIfNoEventHandlersSubscribed()
{
sut.AllowConnection = true;
sut.StartupToken = Guid.Empty;
var token = sut.Connect(Guid.Empty).CommunicationToken.Value;
sut.Send(new SimpleMessage(SimpleMessagePurport.ClientIsReady) { CommunicationToken = token });
sut.Send(new SimpleMessage(SimpleMessagePurport.ConfigurationNeeded) { CommunicationToken = token });
sut.Send(new SimpleMessage(SimpleMessagePurport.RequestShutdown) { CommunicationToken = token });
sut.Send(new MessageBoxReplyMessage(Guid.Empty, MessageBoxResult.Cancel) { CommunicationToken = token });
sut.Send(new PasswordReplyMessage(Guid.Empty, false, "") { CommunicationToken = token });
sut.Send(new ReconfigurationMessage("") { CommunicationToken = token });
}
private class TestMessage : Message { };
}
}

View file

@ -16,6 +16,7 @@ using SafeExamBrowser.Contracts.Communication.Proxies;
using SafeExamBrowser.Contracts.Configuration;
using SafeExamBrowser.Contracts.Configuration.Settings;
using SafeExamBrowser.Contracts.Core.OperationModel;
using SafeExamBrowser.Contracts.Core.OperationModel.Events;
using SafeExamBrowser.Contracts.I18n;
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Contracts.UserInterface;
@ -114,8 +115,7 @@ namespace SafeExamBrowser.Runtime.UnitTests
public void ClientProxy_MustShutdownWhenConnectionLost()
{
StartSession();
clientProcess.Raise(c => c.Terminated += null, -1);
clientProxy.Raise(c => c.ConnectionLost += null);
messageBox.Verify(m => m.Show(
It.IsAny<TextKey>(),
@ -201,6 +201,19 @@ namespace SafeExamBrowser.Runtime.UnitTests
shutdown.Verify(s => s(), Times.Once);
}
[TestMethod]
public void Operations_MustAllowToAbortStartupForClientConfiguration()
{
var args = new ConfigurationCompletedEventArgs();
messageBox.Setup(m => m.Show(It.IsAny<TextKey>(), It.IsAny<TextKey>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>())).Returns(MessageBoxResult.Yes);
sut.TryStart();
sessionSequence.Raise(s => s.ActionRequired += null, args);
Assert.IsTrue(args.AbortStartup);
}
[TestMethod]
public void Operations_MustRequestPasswordViaDialogOnDefaultDesktop()
{
@ -337,6 +350,45 @@ namespace SafeExamBrowser.Runtime.UnitTests
It.IsAny<Guid>()), Times.Once);
}
[TestMethod]
public void Operations_MustUpdateProgress()
{
var args = new ProgressChangedEventArgs
{
CurrentValue = 23,
IsIndeterminate = true,
MaxValue = 150,
Progress = true,
Regress = true
};
var runtimeWindow = new Mock<IRuntimeWindow>();
uiFactory.Setup(u => u.CreateRuntimeWindow(It.IsAny<AppConfig>())).Returns(runtimeWindow.Object);
sut.TryStart();
sessionSequence.Raise(o => o.ProgressChanged += null, args);
runtimeWindow.Verify(s => s.SetValue(It.Is<int>(i => i == args.CurrentValue)), Times.Once);
runtimeWindow.Verify(s => s.SetIndeterminate(), Times.Once);
runtimeWindow.Verify(s => s.SetMaxValue(It.Is<int>(i => i == args.MaxValue)), Times.Once);
runtimeWindow.Verify(s => s.Progress(), Times.Once);
runtimeWindow.Verify(s => s.Regress(), Times.Once);
}
[TestMethod]
public void Operations_MustUpdateStatus()
{
var key = TextKey.OperationStatus_EmptyClipboard;
var runtimeWindow = new Mock<IRuntimeWindow>();
uiFactory.Setup(u => u.CreateRuntimeWindow(It.IsAny<AppConfig>())).Returns(runtimeWindow.Object);
sut.TryStart();
sessionSequence.Raise(o => o.StatusChanged += null, key);
runtimeWindow.Verify(s => s.UpdateStatus(It.Is<TextKey>(k => k == key), It.IsAny<bool>()), Times.Once);
}
[TestMethod]
public void Shutdown_MustRevertSessionThenBootstrapSequence()
{
@ -392,6 +444,26 @@ namespace SafeExamBrowser.Runtime.UnitTests
Assert.AreEqual(1, bootstrap);
}
[TestMethod]
public void Shutdown_MustIndicateFailureToUser()
{
var order = 0;
var bootstrap = 0;
var session = 0;
sut.TryStart();
bootstrapSequence.Reset();
sessionSequence.Reset();
bootstrapSequence.Setup(b => b.TryRevert()).Returns(OperationResult.Failed).Callback(() => bootstrap = ++order);
sessionSequence.Setup(b => b.TryRevert()).Returns(OperationResult.Success).Callback(() => session = ++order);
sut.Terminate();
messageBox.Verify(m => m.Show(It.IsAny<TextKey>(), It.IsAny<TextKey>(), It.IsAny<MessageBoxAction>(), It.IsAny<MessageBoxIcon>(), It.IsAny<IWindow>()), Times.AtLeastOnce);
}
[TestMethod]
public void Startup_MustPerformBootstrapThenSessionSequence()
{
@ -440,6 +512,42 @@ namespace SafeExamBrowser.Runtime.UnitTests
Assert.AreEqual(0, session);
}
[TestMethod]
public void Startup_MustTerminateOnSessionStartFailure()
{
bootstrapSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Success);
sessionSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Failed).Callback(() => sessionContext.Current = currentSession.Object);
sessionContext.Current = null;
var success = sut.TryStart();
bootstrapSequence.Verify(b => b.TryPerform(), Times.Once);
bootstrapSequence.Verify(b => b.TryRevert(), Times.Never);
sessionSequence.Verify(b => b.TryPerform(), Times.Once);
sessionSequence.Verify(b => b.TryRepeat(), Times.Never);
sessionSequence.Verify(b => b.TryRevert(), Times.Once);
shutdown.Verify(s => s(), Times.Once);
}
[TestMethod]
public void Startup_MustNotTerminateOnSessionStartAbortion()
{
bootstrapSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Success);
sessionSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Aborted).Callback(() => sessionContext.Current = currentSession.Object);
sessionContext.Current = null;
var success = sut.TryStart();
bootstrapSequence.Verify(b => b.TryPerform(), Times.Once);
bootstrapSequence.Verify(b => b.TryRevert(), Times.Never);
sessionSequence.Verify(b => b.TryPerform(), Times.Once);
sessionSequence.Verify(b => b.TryRepeat(), Times.Never);
sessionSequence.Verify(b => b.TryRevert(), Times.Never);
shutdown.Verify(s => s(), Times.Never);
}
private void StartSession()
{
bootstrapSequence.Setup(b => b.TryPerform()).Returns(OperationResult.Success);