From 35726c99a7102ae8dda698370d2b732a1691b28a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Mon, 26 Jul 2021 11:31:49 +0200 Subject: [PATCH] Extended unit tests for communication proxies. --- .../Proxies/ClientProxyTests.cs | 52 ++++++++++++++++++- .../Proxies/RuntimeProxyTests.cs | 51 ++++++++++++++++++ .../Proxies/ServiceProxyTests.cs | 16 +++++- 3 files changed, 116 insertions(+), 3 deletions(-) diff --git a/SafeExamBrowser.Communication.UnitTests/Proxies/ClientProxyTests.cs b/SafeExamBrowser.Communication.UnitTests/Proxies/ClientProxyTests.cs index cd243f06..3254e14b 100644 --- a/SafeExamBrowser.Communication.UnitTests/Proxies/ClientProxyTests.cs +++ b/SafeExamBrowser.Communication.UnitTests/Proxies/ClientProxyTests.cs @@ -135,6 +135,27 @@ namespace SafeExamBrowser.Communication.UnitTests.Proxies Assert.IsFalse(communication.Success); } + [TestMethod] + public void MustCorrectlyRequestExamSelection() + { + proxy.Setup(p => p.Send(It.IsAny())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged)); + + var communication = sut.RequestExamSelection(null, default(Guid)); + + proxy.Verify(p => p.Send(It.IsAny()), Times.Once); + Assert.IsTrue(communication.Success); + } + + [TestMethod] + public void MustFailIfExamSelectionRequestNotAcknowledged() + { + proxy.Setup(p => p.Send(It.IsAny())).Returns(null); + + var communication = sut.RequestExamSelection(null, default(Guid)); + + Assert.IsFalse(communication.Success); + } + [TestMethod] public void MustCorrectlyRequestPassword() { @@ -156,6 +177,27 @@ namespace SafeExamBrowser.Communication.UnitTests.Proxies Assert.IsFalse(communication.Success); } + [TestMethod] + public void MustCorrectlyRequestServerFailureAction() + { + proxy.Setup(p => p.Send(It.IsAny())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged)); + + var communication = sut.RequestServerFailureAction(default(string), default(bool), default(Guid)); + + proxy.Verify(p => p.Send(It.IsAny()), Times.Once); + Assert.IsTrue(communication.Success); + } + + [TestMethod] + public void MustFailIfServerFailureActionRequestNotAcknowledged() + { + proxy.Setup(p => p.Send(It.IsAny())).Returns(null); + + var communication = sut.RequestServerFailureAction(default(string), default(bool), default(Guid)); + + Assert.IsFalse(communication.Success); + } + [TestMethod] public void MustCorrectlyShowMessage() { @@ -183,15 +225,21 @@ namespace SafeExamBrowser.Communication.UnitTests.Proxies proxy.Setup(p => p.Send(It.IsAny())).Throws(); var authenticate = sut.RequestAuthentication(); + var examSelection = sut.RequestExamSelection(null, default(Guid)); var message = sut.ShowMessage(default(string), default(string), default(int), default(int), default(Guid)); var password = sut.RequestPassword(default(PasswordRequestPurpose), default(Guid)); - var reconfiguration = sut.InformReconfigurationDenied(null); + var reconfigurationAborted = sut.InformReconfigurationAborted(); + var reconfigurationDenied = sut.InformReconfigurationDenied(null); + var serverFailure = sut.RequestServerFailureAction(default(string), default(bool), default(Guid)); var shutdown = sut.InitiateShutdown(); Assert.IsFalse(authenticate.Success); + Assert.IsFalse(examSelection.Success); Assert.IsFalse(message.Success); Assert.IsFalse(password.Success); - Assert.IsFalse(reconfiguration.Success); + Assert.IsFalse(reconfigurationAborted.Success); + Assert.IsFalse(reconfigurationDenied.Success); + Assert.IsFalse(serverFailure.Success); Assert.IsFalse(shutdown.Success); } } diff --git a/SafeExamBrowser.Communication.UnitTests/Proxies/RuntimeProxyTests.cs b/SafeExamBrowser.Communication.UnitTests/Proxies/RuntimeProxyTests.cs index 894d55a3..2a494afa 100644 --- a/SafeExamBrowser.Communication.UnitTests/Proxies/RuntimeProxyTests.cs +++ b/SafeExamBrowser.Communication.UnitTests/Proxies/RuntimeProxyTests.cs @@ -146,6 +146,30 @@ namespace SafeExamBrowser.Communication.UnitTests.Proxies Assert.IsFalse(communication.Success); } + [TestMethod] + public void MustCorrectlySubmitExamSelection() + { + var examId = "abc123"; + var requestId = Guid.NewGuid(); + + proxy.Setup(p => p.Send(It.IsAny())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged)); + + var communication = sut.SubmitExamSelectionResult(requestId, true, examId); + + Assert.IsTrue(communication.Success); + proxy.Verify(p => p.Send(It.Is(m => m.SelectedExamId == examId && m.RequestId == requestId && m.Success)), Times.Once); + } + + [TestMethod] + public void MustFailIfExamSelectionTransmissionNotAcknowledged() + { + proxy.Setup(p => p.Send(It.IsAny())).Returns(null); + + var communication = sut.SubmitExamSelectionResult(default(Guid), false); + + Assert.IsFalse(communication.Success); + } + [TestMethod] public void MustCorrectlySubmitPassword() { @@ -194,6 +218,29 @@ namespace SafeExamBrowser.Communication.UnitTests.Proxies Assert.IsFalse(communication.Success); } + [TestMethod] + public void MustCorrectlySubmitServerFailureAction() + { + var requestId = Guid.NewGuid(); + + proxy.Setup(p => p.Send(It.IsAny())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged)); + + var communication = sut.SubmitServerFailureActionResult(requestId, true, true, false); + + Assert.IsTrue(communication.Success); + proxy.Verify(p => p.Send(It.Is(m => m.RequestId == requestId && m.Abort && m.Fallback && !m.Retry)), Times.Once); + } + + [TestMethod] + public void MustFailIfServerFailureActionTransmissionNotAcknowledged() + { + proxy.Setup(p => p.Send(It.IsAny())).Returns(null); + + var communication = sut.SubmitServerFailureActionResult(default(Guid), default(bool), default(bool), default(bool)); + + Assert.IsFalse(communication.Success); + } + [TestMethod] public void MustExecuteOperationsFailsafe() { @@ -201,16 +248,20 @@ namespace SafeExamBrowser.Communication.UnitTests.Proxies var client = sut.InformClientReady(); var configuration = sut.GetConfiguration(); + var examSelection = sut.SubmitExamSelectionResult(default(Guid), default(bool)); var message = sut.SubmitMessageBoxResult(default(Guid), default(int)); var password = sut.SubmitPassword(default(Guid), false); var reconfiguration = sut.RequestReconfiguration(null, null); + var serverFailure = sut.SubmitServerFailureActionResult(default(Guid), default(bool), default(bool), default(bool)); var shutdown = sut.RequestShutdown(); Assert.IsFalse(client.Success); Assert.IsFalse(configuration.Success); + Assert.IsFalse(examSelection.Success); Assert.IsFalse(message.Success); Assert.IsFalse(password.Success); Assert.IsFalse(reconfiguration.Success); + Assert.IsFalse(serverFailure.Success); Assert.IsFalse(shutdown.Success); } } diff --git a/SafeExamBrowser.Communication.UnitTests/Proxies/ServiceProxyTests.cs b/SafeExamBrowser.Communication.UnitTests/Proxies/ServiceProxyTests.cs index abb5a5e4..c507f59c 100644 --- a/SafeExamBrowser.Communication.UnitTests/Proxies/ServiceProxyTests.cs +++ b/SafeExamBrowser.Communication.UnitTests/Proxies/ServiceProxyTests.cs @@ -9,10 +9,10 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -using SafeExamBrowser.Communication.Proxies; using SafeExamBrowser.Communication.Contracts; using SafeExamBrowser.Communication.Contracts.Data; using SafeExamBrowser.Communication.Contracts.Proxies; +using SafeExamBrowser.Communication.Proxies; using SafeExamBrowser.Configuration.Contracts; using SafeExamBrowser.Logging.Contracts; @@ -116,5 +116,19 @@ namespace SafeExamBrowser.Communication.UnitTests.Proxies Assert.IsFalse(communication.Success); } + + [TestMethod] + public void MustExecuteOperationsFailsafe() + { + proxy.Setup(p => p.Send(It.IsAny())).Throws(); + + var configuration = sut.RunSystemConfigurationUpdate(); + var start = sut.StartSession(default(ServiceConfiguration)); + var stop = sut.StopSession(default(Guid)); + + Assert.IsFalse(configuration.Success); + Assert.IsFalse(start.Success); + Assert.IsFalse(stop.Success); + } } }