From 645ae7d307554a158e55977415347516dd8bc6eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Thu, 22 Jul 2021 15:08:40 +0200 Subject: [PATCH] Extended unit tests for client host. --- .../Communication/ClientHostTests.cs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/SafeExamBrowser.Client.UnitTests/Communication/ClientHostTests.cs b/SafeExamBrowser.Client.UnitTests/Communication/ClientHostTests.cs index 32091025..a891ee15 100644 --- a/SafeExamBrowser.Client.UnitTests/Communication/ClientHostTests.cs +++ b/SafeExamBrowser.Client.UnitTests/Communication/ClientHostTests.cs @@ -7,6 +7,7 @@ */ using System; +using System.Linq; using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -151,6 +152,32 @@ namespace SafeExamBrowser.Client.UnitTests.Communication Assert.AreEqual(PROCESS_ID, (response as AuthenticationResponse)?.ProcessId); } + [TestMethod] + public void MustHandleExamSelectionRequestCorrectly() + { + var examSelectionRequested = false; + var requestId = Guid.NewGuid(); + var resetEvent = new AutoResetEvent(false); + + sut.ExamSelectionRequested += (args) => + { + examSelectionRequested = true; + resetEvent.Set(); + }; + sut.AuthenticationToken = Guid.Empty; + + var token = sut.Connect(Guid.Empty).CommunicationToken.Value; + var request = new ExamSelectionRequestMessage(Enumerable.Empty<(string id, string lms, string name, string url)>(), requestId) { CommunicationToken = token }; + var response = sut.Send(request); + + resetEvent.WaitOne(); + + Assert.IsTrue(examSelectionRequested); + Assert.IsNotNull(response); + Assert.IsInstanceOfType(response, typeof(SimpleResponse)); + Assert.AreEqual(SimpleResponsePurport.Acknowledged, (response as SimpleResponse)?.Purport); + } + [TestMethod] public void MustHandleMessageBoxRequestCorrectly() { @@ -259,6 +286,32 @@ namespace SafeExamBrowser.Client.UnitTests.Communication Assert.AreEqual(SimpleResponsePurport.Acknowledged, (response as SimpleResponse)?.Purport); } + [TestMethod] + public void MustHandleServerFailureCorrectly() + { + var serverFailureActionRequested = false; + var requestId = Guid.NewGuid(); + var resetEvent = new AutoResetEvent(false); + + sut.ServerFailureActionRequested += (args) => + { + serverFailureActionRequested = true; + resetEvent.Set(); + }; + sut.AuthenticationToken = Guid.Empty; + + var token = sut.Connect(Guid.Empty).CommunicationToken.Value; + var request = new ServerFailureActionRequestMessage("", true, requestId) { CommunicationToken = token }; + var response = sut.Send(request); + + resetEvent.WaitOne(); + + Assert.IsTrue(serverFailureActionRequested); + Assert.IsNotNull(response); + Assert.IsInstanceOfType(response, typeof(SimpleResponse)); + Assert.AreEqual(SimpleResponsePurport.Acknowledged, (response as SimpleResponse)?.Purport); + } + [TestMethod] public void MustHandleShutdownRequestCorrectly() {