Extended unit tests for communication proxies.
This commit is contained in:
parent
645ae7d307
commit
35726c99a7
3 changed files with 116 additions and 3 deletions
|
@ -135,6 +135,27 @@ namespace SafeExamBrowser.Communication.UnitTests.Proxies
|
|||
Assert.IsFalse(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyRequestExamSelection()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<ExamSelectionRequestMessage>())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.RequestExamSelection(null, default(Guid));
|
||||
|
||||
proxy.Verify(p => p.Send(It.IsAny<ExamSelectionRequestMessage>()), Times.Once);
|
||||
Assert.IsTrue(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfExamSelectionRequestNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<ExamSelectionRequestMessage>())).Returns<Response>(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<ServerFailureActionRequestMessage>())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.RequestServerFailureAction(default(string), default(bool), default(Guid));
|
||||
|
||||
proxy.Verify(p => p.Send(It.IsAny<ServerFailureActionRequestMessage>()), Times.Once);
|
||||
Assert.IsTrue(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfServerFailureActionRequestNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<ServerFailureActionRequestMessage>())).Returns<Response>(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<Message>())).Throws<Exception>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ExamSelectionReplyMessage>())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.SubmitExamSelectionResult(requestId, true, examId);
|
||||
|
||||
Assert.IsTrue(communication.Success);
|
||||
proxy.Verify(p => p.Send(It.Is<ExamSelectionReplyMessage>(m => m.SelectedExamId == examId && m.RequestId == requestId && m.Success)), Times.Once);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfExamSelectionTransmissionNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<ExamSelectionReplyMessage>())).Returns<Response>(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<ServerFailureActionReplyMessage>())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.SubmitServerFailureActionResult(requestId, true, true, false);
|
||||
|
||||
Assert.IsTrue(communication.Success);
|
||||
proxy.Verify(p => p.Send(It.Is<ServerFailureActionReplyMessage>(m => m.RequestId == requestId && m.Abort && m.Fallback && !m.Retry)), Times.Once);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfServerFailureActionTransmissionNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<ServerFailureActionReplyMessage>())).Returns<Response>(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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Message>())).Throws<Exception>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue