SEBWIN-220: Extended unit tests for proxies.
This commit is contained in:
parent
c32028d3dd
commit
72425f0d6c
3 changed files with 117 additions and 2 deletions
|
@ -105,6 +105,21 @@ namespace SafeExamBrowser.Core.UnitTests.Communication.Proxies
|
|||
Assert.IsFalse(connected);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustHandleConnectionFailureCorrectly()
|
||||
{
|
||||
var proxy = new Mock<IProxyObject>();
|
||||
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Throws<Exception>();
|
||||
|
||||
var token = Guid.NewGuid();
|
||||
var connected = sut.Connect(token);
|
||||
|
||||
proxyObjectFactory.Verify(f => f.CreateObject(It.IsAny<string>()), Times.Once);
|
||||
|
||||
Assert.IsFalse(connected);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailToDisconnectIfNotConnected()
|
||||
{
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace SafeExamBrowser.Core.UnitTests.Communication.Proxies
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustIndicateIfShutdownCommandNotAcknowledged()
|
||||
public void MustFailIfShutdownCommandNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.Shutdown))).Returns<Response>(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<SimpleMessage>(m => m.Purport == SimpleMessagePurport.Authenticate))).Returns<Response>(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<ReconfigurationDeniedMessage>())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.InformReconfigurationDenied(null);
|
||||
|
||||
proxy.Verify(p => p.Send(It.IsAny<ReconfigurationDeniedMessage>()), Times.Once);
|
||||
Assert.IsTrue(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfReconfigurationDenialNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<ReconfigurationDeniedMessage>())).Returns<Response>(null);
|
||||
|
||||
var communication = sut.InformReconfigurationDenied(null);
|
||||
|
||||
Assert.IsFalse(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyRequestPassword()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<PasswordRequestMessage>())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.RequestPassword(default(PasswordRequestPurpose), default(Guid));
|
||||
|
||||
proxy.Verify(p => p.Send(It.IsAny<PasswordRequestMessage>()), Times.Once);
|
||||
Assert.IsTrue(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfPasswordRequestNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<PasswordRequestMessage>())).Returns<Response>(null);
|
||||
|
||||
var communication = sut.RequestPassword(default(PasswordRequestPurpose), default(Guid));
|
||||
|
||||
Assert.IsFalse(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustExecuteOperationsFailsafe()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<Message>())).Throws<Exception>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<PasswordReplyMessage>())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.SubmitPassword(requestId, true, password);
|
||||
|
||||
Assert.IsTrue(communication.Success);
|
||||
proxy.Verify(p => p.Send(It.Is<PasswordReplyMessage>(m => m.Password == password && m.RequestId == requestId && m.Success)), Times.Once);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfPasswordTransmissionNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<PasswordReplyMessage>())).Returns<Response>(null);
|
||||
|
||||
var communication = sut.SubmitPassword(default(Guid), false);
|
||||
|
||||
Assert.IsFalse(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustExecuteOperationsFailsafe()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<Message>())).Throws<Exception>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue