From 72425f0d6c816c892d09e4967395aac807745734 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Fri, 10 Aug 2018 15:16:33 +0200 Subject: [PATCH] SEBWIN-220: Extended unit tests for proxies. --- .../Communication/Proxies/BaseProxyTests.cs | 15 +++++ .../Communication/Proxies/ClientProxyTests.cs | 62 ++++++++++++++++++- .../Proxies/RuntimeProxyTests.cs | 42 +++++++++++++ 3 files changed, 117 insertions(+), 2 deletions(-) diff --git a/SafeExamBrowser.Core.UnitTests/Communication/Proxies/BaseProxyTests.cs b/SafeExamBrowser.Core.UnitTests/Communication/Proxies/BaseProxyTests.cs index 1efcab54..b2880f74 100644 --- a/SafeExamBrowser.Core.UnitTests/Communication/Proxies/BaseProxyTests.cs +++ b/SafeExamBrowser.Core.UnitTests/Communication/Proxies/BaseProxyTests.cs @@ -105,6 +105,21 @@ namespace SafeExamBrowser.Core.UnitTests.Communication.Proxies Assert.IsFalse(connected); } + [TestMethod] + public void MustHandleConnectionFailureCorrectly() + { + var proxy = new Mock(); + + proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny())).Throws(); + + var token = Guid.NewGuid(); + var connected = sut.Connect(token); + + proxyObjectFactory.Verify(f => f.CreateObject(It.IsAny()), Times.Once); + + Assert.IsFalse(connected); + } + [TestMethod] public void MustFailToDisconnectIfNotConnected() { diff --git a/SafeExamBrowser.Core.UnitTests/Communication/Proxies/ClientProxyTests.cs b/SafeExamBrowser.Core.UnitTests/Communication/Proxies/ClientProxyTests.cs index c95ad41e..652e0871 100644 --- a/SafeExamBrowser.Core.UnitTests/Communication/Proxies/ClientProxyTests.cs +++ b/SafeExamBrowser.Core.UnitTests/Communication/Proxies/ClientProxyTests.cs @@ -58,7 +58,7 @@ namespace SafeExamBrowser.Core.UnitTests.Communication.Proxies } [TestMethod] - public void MustIndicateIfShutdownCommandNotAcknowledged() + public void MustFailIfShutdownCommandNotAcknowledged() { proxy.Setup(p => p.Send(It.Is(m => m.Purport == SimpleMessagePurport.Shutdown))).Returns(null); @@ -82,7 +82,7 @@ namespace SafeExamBrowser.Core.UnitTests.Communication.Proxies } [TestMethod] - public void MustIndicateIfAuthenticationCommandNotAcknowledged() + public void MustFailIfAuthenticationCommandNotAcknowledged() { proxy.Setup(p => p.Send(It.Is(m => m.Purport == SimpleMessagePurport.Authenticate))).Returns(null); @@ -91,5 +91,63 @@ namespace SafeExamBrowser.Core.UnitTests.Communication.Proxies Assert.AreEqual(default(AuthenticationResponse), communication.Value); Assert.IsFalse(communication.Success); } + + [TestMethod] + public void MustCorrectlyInformAboutReconfigurationDenial() + { + proxy.Setup(p => p.Send(It.IsAny())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged)); + + var communication = sut.InformReconfigurationDenied(null); + + proxy.Verify(p => p.Send(It.IsAny()), Times.Once); + Assert.IsTrue(communication.Success); + } + + [TestMethod] + public void MustFailIfReconfigurationDenialNotAcknowledged() + { + proxy.Setup(p => p.Send(It.IsAny())).Returns(null); + + var communication = sut.InformReconfigurationDenied(null); + + Assert.IsFalse(communication.Success); + } + + [TestMethod] + public void MustCorrectlyRequestPassword() + { + proxy.Setup(p => p.Send(It.IsAny())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged)); + + var communication = sut.RequestPassword(default(PasswordRequestPurpose), default(Guid)); + + proxy.Verify(p => p.Send(It.IsAny()), Times.Once); + Assert.IsTrue(communication.Success); + } + + [TestMethod] + public void MustFailIfPasswordRequestNotAcknowledged() + { + proxy.Setup(p => p.Send(It.IsAny())).Returns(null); + + var communication = sut.RequestPassword(default(PasswordRequestPurpose), default(Guid)); + + Assert.IsFalse(communication.Success); + } + + [TestMethod] + public void MustExecuteOperationsFailsafe() + { + proxy.Setup(p => p.Send(It.IsAny())).Throws(); + + var authenticate = sut.RequestAuthentication(); + var password = sut.RequestPassword(default(PasswordRequestPurpose), default(Guid)); + var reconfiguration = sut.InformReconfigurationDenied(null); + var shutdown = sut.InitiateShutdown(); + + Assert.IsFalse(authenticate.Success); + Assert.IsFalse(password.Success); + Assert.IsFalse(reconfiguration.Success); + Assert.IsFalse(shutdown.Success); + } } } diff --git a/SafeExamBrowser.Core.UnitTests/Communication/Proxies/RuntimeProxyTests.cs b/SafeExamBrowser.Core.UnitTests/Communication/Proxies/RuntimeProxyTests.cs index f593ce69..cf249bcb 100644 --- a/SafeExamBrowser.Core.UnitTests/Communication/Proxies/RuntimeProxyTests.cs +++ b/SafeExamBrowser.Core.UnitTests/Communication/Proxies/RuntimeProxyTests.cs @@ -142,5 +142,47 @@ namespace SafeExamBrowser.Core.UnitTests.Communication.Proxies Assert.IsFalse(communication.Success); } + + [TestMethod] + public void MustCorrectlySubmitPassword() + { + var password = "blubb"; + var requestId = Guid.NewGuid(); + + proxy.Setup(p => p.Send(It.IsAny())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged)); + + var communication = sut.SubmitPassword(requestId, true, password); + + Assert.IsTrue(communication.Success); + proxy.Verify(p => p.Send(It.Is(m => m.Password == password && m.RequestId == requestId && m.Success)), Times.Once); + } + + [TestMethod] + public void MustFailIfPasswordTransmissionNotAcknowledged() + { + proxy.Setup(p => p.Send(It.IsAny())).Returns(null); + + var communication = sut.SubmitPassword(default(Guid), false); + + Assert.IsFalse(communication.Success); + } + + [TestMethod] + public void MustExecuteOperationsFailsafe() + { + proxy.Setup(p => p.Send(It.IsAny())).Throws(); + + var client = sut.InformClientReady(); + var configuration = sut.GetConfiguration(); + var password = sut.SubmitPassword(default(Guid), false); + var reconfiguration = sut.RequestReconfiguration(null); + var shutdown = sut.RequestShutdown(); + + Assert.IsFalse(client.Success); + Assert.IsFalse(configuration.Success); + Assert.IsFalse(password.Success); + Assert.IsFalse(reconfiguration.Success); + Assert.IsFalse(shutdown.Success); + } } }