Restore SEBPatch
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using SafeExamBrowser.Communication.Hosts;
|
||||
using SafeExamBrowser.Communication.Contracts;
|
||||
using SafeExamBrowser.Communication.Contracts.Data;
|
||||
using SafeExamBrowser.Communication.Contracts.Hosts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
|
||||
namespace SafeExamBrowser.Communication.UnitTests.Hosts
|
||||
{
|
||||
internal class BaseHostStub : BaseHost
|
||||
{
|
||||
public Func<Guid?, bool> OnConnectStub { get; set; }
|
||||
public Action<Interlocutor> OnDisconnectStub { get; set; }
|
||||
public Func<Message, Response> OnReceiveStub { get; set; }
|
||||
public Func<SimpleMessagePurport, Response> OnReceiveSimpleMessageStub { get; set; }
|
||||
|
||||
public BaseHostStub(string address, IHostObjectFactory factory, ILogger logger, int timeout_ms) : base(address, factory, logger, timeout_ms)
|
||||
{
|
||||
}
|
||||
|
||||
public Guid? GetCommunicationToken()
|
||||
{
|
||||
return CommunicationToken.Any() ? CommunicationToken.First() : default(Guid?);
|
||||
}
|
||||
|
||||
protected override bool OnConnect(Guid? token)
|
||||
{
|
||||
return OnConnectStub?.Invoke(token) == true;
|
||||
}
|
||||
|
||||
protected override void OnDisconnect(Interlocutor interlocutor)
|
||||
{
|
||||
OnDisconnectStub?.Invoke(interlocutor);
|
||||
}
|
||||
|
||||
protected override Response OnReceive(Message message)
|
||||
{
|
||||
return OnReceiveStub?.Invoke(message);
|
||||
}
|
||||
|
||||
protected override Response OnReceive(SimpleMessagePurport message)
|
||||
{
|
||||
return OnReceiveSimpleMessageStub?.Invoke(message);
|
||||
}
|
||||
}
|
||||
}
|
293
SafeExamBrowser.Communication.UnitTests/Hosts/BaseHostTests.cs
Normal file
293
SafeExamBrowser.Communication.UnitTests/Hosts/BaseHostTests.cs
Normal file
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.ServiceModel;
|
||||
using System.Threading;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts;
|
||||
using SafeExamBrowser.Communication.Contracts.Data;
|
||||
using SafeExamBrowser.Communication.Contracts.Hosts;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
|
||||
namespace SafeExamBrowser.Communication.UnitTests.Hosts
|
||||
{
|
||||
[TestClass]
|
||||
public class BaseHostTests
|
||||
{
|
||||
private Mock<IHostObject> hostObject;
|
||||
private Mock<IHostObjectFactory> hostObjectFactory;
|
||||
private Mock<ILogger> logger;
|
||||
private BaseHostStub sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
hostObject = new Mock<IHostObject>();
|
||||
hostObjectFactory = new Mock<IHostObjectFactory>();
|
||||
logger = new Mock<ILogger>();
|
||||
|
||||
hostObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>(), It.IsAny<ICommunication>())).Returns(hostObject.Object);
|
||||
|
||||
sut = new BaseHostStub("net.pipe://some/address/here", hostObjectFactory.Object, logger.Object, 10);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyStartHost()
|
||||
{
|
||||
var threadId = Thread.CurrentThread.ManagedThreadId;
|
||||
|
||||
hostObject.Setup(h => h.Open()).Callback(() => threadId = Thread.CurrentThread.ManagedThreadId);
|
||||
|
||||
sut.Start();
|
||||
|
||||
hostObjectFactory.Verify(f => f.CreateObject(It.IsAny<string>(), sut), Times.Once);
|
||||
|
||||
Assert.AreNotEqual(Thread.CurrentThread.ManagedThreadId, threadId);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(CommunicationException))]
|
||||
public void MustCorrectlyHandleStartupException()
|
||||
{
|
||||
hostObject.Setup(h => h.Open()).Throws<Exception>();
|
||||
|
||||
sut.Start();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyStopHost()
|
||||
{
|
||||
sut.Start();
|
||||
sut.Stop();
|
||||
|
||||
hostObject.Verify(h => h.Close(), Times.Once);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(CommunicationException))]
|
||||
public void MustCorrectlyHandleShutdownException()
|
||||
{
|
||||
hostObject.Setup(h => h.Close()).Throws<Exception>();
|
||||
|
||||
sut.Start();
|
||||
sut.Stop();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustNotFailToStopIfNotRunning()
|
||||
{
|
||||
sut.Stop();
|
||||
sut.Stop();
|
||||
sut.Stop();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustNotFailToEvaluateIsRunningIfNotRunning()
|
||||
{
|
||||
var running = sut.IsRunning;
|
||||
|
||||
Assert.IsFalse(running);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyIndicateWhetherHostIsRunning()
|
||||
{
|
||||
hostObject.SetupGet(h => h.State).Returns(CommunicationState.Faulted);
|
||||
|
||||
sut.Start();
|
||||
|
||||
Assert.IsFalse(sut.IsRunning);
|
||||
|
||||
hostObject.SetupGet(h => h.State).Returns(CommunicationState.Opened);
|
||||
|
||||
Assert.IsTrue(sut.IsRunning);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyHandleConnectionRequest()
|
||||
{
|
||||
var token = Guid.NewGuid();
|
||||
var receivedToken = default(Guid?);
|
||||
|
||||
sut.OnConnectStub = (t) =>
|
||||
{
|
||||
receivedToken = t;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
var response = sut.Connect(token);
|
||||
|
||||
Assert.IsTrue(response.ConnectionEstablished);
|
||||
Assert.AreEqual(token, receivedToken);
|
||||
Assert.AreEqual(sut.GetCommunicationToken(), response.CommunicationToken);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyHandleDeniedConnectionRequest()
|
||||
{
|
||||
var token = Guid.NewGuid();
|
||||
var receivedToken = default(Guid?);
|
||||
|
||||
sut.OnConnectStub = (t) =>
|
||||
{
|
||||
receivedToken = t;
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
var response = sut.Connect(token);
|
||||
|
||||
Assert.IsFalse(response.ConnectionEstablished);
|
||||
Assert.AreEqual(token, receivedToken);
|
||||
Assert.IsNull(sut.GetCommunicationToken());
|
||||
Assert.IsNull(response.CommunicationToken);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyHandleDisconnectionRequest()
|
||||
{
|
||||
var message = new DisconnectionMessage { Interlocutor = Interlocutor.Runtime };
|
||||
var disconnected = false;
|
||||
var interlocutor = Interlocutor.Unknown;
|
||||
|
||||
sut.OnConnectStub = (t) => { return true; };
|
||||
sut.OnDisconnectStub = (i) => { disconnected = true; interlocutor = i; };
|
||||
sut.Connect();
|
||||
|
||||
message.CommunicationToken = sut.GetCommunicationToken().Value;
|
||||
|
||||
var response = sut.Disconnect(message);
|
||||
|
||||
Assert.AreEqual(message.Interlocutor, interlocutor);
|
||||
Assert.IsTrue(disconnected);
|
||||
Assert.IsTrue(response.ConnectionTerminated);
|
||||
Assert.IsNull(sut.GetCommunicationToken());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyHandleUnauthorizedDisconnectionRequest()
|
||||
{
|
||||
var disconnected = false;
|
||||
|
||||
sut.OnConnectStub = (t) => { return true; };
|
||||
sut.OnDisconnectStub = (i) => disconnected = true;
|
||||
sut.Connect();
|
||||
|
||||
var response = sut.Disconnect(new DisconnectionMessage());
|
||||
|
||||
Assert.IsFalse(disconnected);
|
||||
Assert.IsFalse(response.ConnectionTerminated);
|
||||
Assert.IsNotNull(sut.GetCommunicationToken());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyHandleUnauthorizedTransmission()
|
||||
{
|
||||
var received = false;
|
||||
var simpleReceived = false;
|
||||
|
||||
sut.OnReceiveStub = (m) => { received = true; return null; };
|
||||
sut.OnReceiveSimpleMessageStub = (m) => { simpleReceived = true; return null; };
|
||||
|
||||
var response = sut.Send(new DisconnectionMessage());
|
||||
|
||||
Assert.IsFalse(received);
|
||||
Assert.IsFalse(simpleReceived);
|
||||
Assert.IsInstanceOfType(response, typeof(SimpleResponse));
|
||||
Assert.AreEqual(SimpleResponsePurport.Unauthorized, (response as SimpleResponse)?.Purport);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyHandlePingMessage()
|
||||
{
|
||||
var received = false;
|
||||
var simpleReceived = false;
|
||||
var message = new SimpleMessage(SimpleMessagePurport.Ping);
|
||||
|
||||
sut.OnReceiveStub = (m) => { received = true; return null; };
|
||||
sut.OnReceiveSimpleMessageStub = (m) => { simpleReceived = true; return null; };
|
||||
sut.OnConnectStub = (t) => { return true; };
|
||||
sut.Connect();
|
||||
|
||||
message.CommunicationToken = sut.GetCommunicationToken().Value;
|
||||
|
||||
var response = sut.Send(message);
|
||||
|
||||
Assert.IsFalse(received);
|
||||
Assert.IsFalse(simpleReceived);
|
||||
Assert.IsInstanceOfType(response, typeof(SimpleResponse));
|
||||
Assert.AreEqual(SimpleResponsePurport.Acknowledged, (response as SimpleResponse)?.Purport);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyReceiveSimpleMessage()
|
||||
{
|
||||
var received = false;
|
||||
var simpleReceived = false;
|
||||
var purport = default(SimpleMessagePurport);
|
||||
var message = new SimpleMessage(SimpleMessagePurport.ConfigurationNeeded);
|
||||
var simpleResponse = new SimpleResponse(SimpleResponsePurport.UnknownMessage);
|
||||
|
||||
sut.OnReceiveStub = (m) => { received = true; return null; };
|
||||
sut.OnReceiveSimpleMessageStub = (m) => { simpleReceived = true; purport = m; return simpleResponse; };
|
||||
sut.OnConnectStub = (t) => { return true; };
|
||||
sut.Connect();
|
||||
|
||||
message.CommunicationToken = sut.GetCommunicationToken().Value;
|
||||
|
||||
var response = sut.Send(message);
|
||||
|
||||
Assert.IsFalse(received);
|
||||
Assert.IsTrue(simpleReceived);
|
||||
Assert.IsInstanceOfType(response, typeof(SimpleResponse));
|
||||
Assert.AreEqual(SimpleMessagePurport.ConfigurationNeeded, purport);
|
||||
Assert.AreSame(simpleResponse, response);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyReceiveMessage()
|
||||
{
|
||||
var received = false;
|
||||
var simpleReceived = false;
|
||||
var message = new ReconfigurationMessage(null, null);
|
||||
var configurationResponse = new ConfigurationResponse();
|
||||
|
||||
sut.OnReceiveStub = (m) => { received = true; return configurationResponse; };
|
||||
sut.OnReceiveSimpleMessageStub = (m) => { simpleReceived = true; return null; };
|
||||
sut.OnConnectStub = (t) => { return true; };
|
||||
sut.Connect();
|
||||
|
||||
message.CommunicationToken = sut.GetCommunicationToken().Value;
|
||||
|
||||
var response = sut.Send(message);
|
||||
|
||||
Assert.IsTrue(received);
|
||||
Assert.IsFalse(simpleReceived);
|
||||
Assert.IsInstanceOfType(response, typeof(ConfigurationResponse));
|
||||
Assert.AreSame(configurationResponse, response);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustLogStatusChangesOfHost()
|
||||
{
|
||||
sut.Start();
|
||||
|
||||
hostObject.Raise(h => h.Closed += null, It.IsAny<EventArgs>());
|
||||
hostObject.Raise(h => h.Closing += null, It.IsAny<EventArgs>());
|
||||
hostObject.Raise(h => h.Faulted += null, It.IsAny<EventArgs>());
|
||||
hostObject.Raise(h => h.Opened += null, It.IsAny<EventArgs>());
|
||||
hostObject.Raise(h => h.Opening += null, It.IsAny<EventArgs>());
|
||||
|
||||
logger.Verify(l => l.Debug(It.IsAny<string>()), Times.AtLeast(4));
|
||||
logger.Verify(l => l.Error(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("SafeExamBrowser.Communication.UnitTests")]
|
||||
[assembly: AssemblyDescription("Safe Exam Browser")]
|
||||
[assembly: AssemblyCompany("ETH Zürich")]
|
||||
[assembly: AssemblyProduct("SafeExamBrowser.Communication.UnitTests")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024 ETH Zürich, IT Services")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
[assembly: Guid("21137d66-7d01-4327-92d2-0304c25cd7df")]
|
||||
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyInformationalVersion("1.0.0.0")]
|
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using SafeExamBrowser.Communication.Proxies;
|
||||
using SafeExamBrowser.Communication.Contracts;
|
||||
using SafeExamBrowser.Communication.Contracts.Data;
|
||||
using SafeExamBrowser.Communication.Contracts.Proxies;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
|
||||
namespace SafeExamBrowser.Communication.UnitTests.Proxies
|
||||
{
|
||||
internal class BaseProxyImpl : BaseProxy
|
||||
{
|
||||
public BaseProxyImpl(string address, IProxyObjectFactory factory, ILogger logger, Interlocutor owner) : base(address, factory, logger, owner)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool Connect(Guid? token = null, bool autoPing = false)
|
||||
{
|
||||
return base.Connect(token, autoPing);
|
||||
}
|
||||
|
||||
public override bool Disconnect()
|
||||
{
|
||||
return base.Disconnect();
|
||||
}
|
||||
|
||||
public new Response Send(Message message)
|
||||
{
|
||||
return base.Send(message);
|
||||
}
|
||||
|
||||
public new Response Send(SimpleMessagePurport purport)
|
||||
{
|
||||
return base.Send(purport);
|
||||
}
|
||||
|
||||
public new bool IsAcknowledged(Response response)
|
||||
{
|
||||
return base.IsAcknowledged(response);
|
||||
}
|
||||
|
||||
public new void TestConnection()
|
||||
{
|
||||
base.TestConnection();
|
||||
}
|
||||
|
||||
public new string ToString(Message message)
|
||||
{
|
||||
return base.ToString(message);
|
||||
}
|
||||
|
||||
public new string ToString(Response response)
|
||||
{
|
||||
return base.ToString(response);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,388 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.ServiceModel;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts;
|
||||
using SafeExamBrowser.Communication.Contracts.Data;
|
||||
using SafeExamBrowser.Communication.Contracts.Proxies;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
|
||||
namespace SafeExamBrowser.Communication.UnitTests.Proxies
|
||||
{
|
||||
[TestClass]
|
||||
public class BaseProxyTests
|
||||
{
|
||||
private Mock<IProxyObjectFactory> proxyObjectFactory;
|
||||
private Mock<ILogger> logger;
|
||||
private BaseProxyImpl sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
proxyObjectFactory = new Mock<IProxyObjectFactory>();
|
||||
logger = new Mock<ILogger>();
|
||||
|
||||
sut = new BaseProxyImpl("net.pipe://some/address/here", proxyObjectFactory.Object, logger.Object, default(Interlocutor));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustConnectCorrectly()
|
||||
{
|
||||
var proxy = new Mock<IProxyObject>();
|
||||
var response = new ConnectionResponse
|
||||
{
|
||||
CommunicationToken = Guid.NewGuid(),
|
||||
ConnectionEstablished = true
|
||||
};
|
||||
|
||||
proxy.Setup(p => p.Connect(It.IsAny<Guid>())).Returns(response);
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Returns(proxy.Object);
|
||||
|
||||
var token = Guid.NewGuid();
|
||||
var connected = sut.Connect(token);
|
||||
|
||||
proxy.Verify(p => p.Connect(token), Times.Once);
|
||||
proxyObjectFactory.Verify(f => f.CreateObject(It.IsAny<string>()), Times.Once);
|
||||
|
||||
Assert.IsTrue(connected);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustDisconnectCorrectly()
|
||||
{
|
||||
var proxy = new Mock<IProxyObject>();
|
||||
var connectionResponse = new ConnectionResponse
|
||||
{
|
||||
CommunicationToken = Guid.NewGuid(),
|
||||
ConnectionEstablished = true
|
||||
};
|
||||
var disconnectionResponse = new DisconnectionResponse
|
||||
{
|
||||
ConnectionTerminated = true
|
||||
};
|
||||
|
||||
proxy.Setup(p => p.Connect(It.IsAny<Guid>())).Returns(connectionResponse);
|
||||
proxy.Setup(p => p.Disconnect(It.IsAny<DisconnectionMessage>())).Returns(disconnectionResponse);
|
||||
proxy.Setup(o => o.State).Returns(CommunicationState.Opened);
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Returns(proxy.Object);
|
||||
|
||||
var token = Guid.NewGuid();
|
||||
var connected = sut.Connect(token);
|
||||
var disconnected = sut.Disconnect();
|
||||
|
||||
proxy.Verify(p => p.Disconnect(It.Is<DisconnectionMessage>(m => m.CommunicationToken == connectionResponse.CommunicationToken)), Times.Once);
|
||||
|
||||
Assert.IsTrue(connected);
|
||||
Assert.IsTrue(disconnected);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustHandleConnectionRefusalCorrectly()
|
||||
{
|
||||
var proxy = new Mock<IProxyObject>();
|
||||
var response = new ConnectionResponse
|
||||
{
|
||||
CommunicationToken = Guid.NewGuid(),
|
||||
ConnectionEstablished = false
|
||||
};
|
||||
|
||||
proxy.Setup(p => p.Connect(It.IsAny<Guid>())).Returns(response);
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Returns(proxy.Object);
|
||||
|
||||
var token = Guid.NewGuid();
|
||||
var connected = sut.Connect(token);
|
||||
|
||||
proxy.Verify(p => p.Connect(token), Times.Once);
|
||||
proxyObjectFactory.Verify(f => f.CreateObject(It.IsAny<string>()), Times.Once);
|
||||
|
||||
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 MustHandleMissingEndpointCorrectly()
|
||||
{
|
||||
var proxy = new Mock<IProxyObject>();
|
||||
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Throws<EndpointNotFoundException>();
|
||||
|
||||
var token = Guid.NewGuid();
|
||||
var connected = sut.Connect(token);
|
||||
|
||||
logger.Verify(l => l.Warn(It.IsAny<string>()), Times.AtLeastOnce());
|
||||
logger.Verify(l => l.Error(It.IsAny<string>()), Times.Never());
|
||||
logger.Verify(l => l.Error(It.IsAny<string>(), It.IsAny<Exception>()), Times.Never());
|
||||
proxyObjectFactory.Verify(f => f.CreateObject(It.IsAny<string>()), Times.Once);
|
||||
|
||||
Assert.IsFalse(connected);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailToDisconnectIfNotConnected()
|
||||
{
|
||||
var success = sut.Disconnect();
|
||||
|
||||
Assert.IsFalse(success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailToDisconnectIfChannelNotOpen()
|
||||
{
|
||||
var proxy = new Mock<IProxyObject>();
|
||||
var response = new ConnectionResponse
|
||||
{
|
||||
CommunicationToken = Guid.NewGuid(),
|
||||
ConnectionEstablished = true
|
||||
};
|
||||
|
||||
proxy.Setup(p => p.Connect(It.IsAny<Guid>())).Returns(response);
|
||||
proxy.Setup(o => o.State).Returns(CommunicationState.Faulted);
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Returns(proxy.Object);
|
||||
|
||||
var token = Guid.NewGuid();
|
||||
|
||||
sut.Connect(token);
|
||||
|
||||
var success = sut.Disconnect();
|
||||
|
||||
Assert.IsFalse(success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(InvalidOperationException))]
|
||||
public void MustFailToSendIfNotConnected()
|
||||
{
|
||||
sut.Send(new Mock<Message>().Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(InvalidOperationException))]
|
||||
public void MustFailToSendIfChannelNotOpen()
|
||||
{
|
||||
var proxy = new Mock<IProxyObject>();
|
||||
var response = new ConnectionResponse
|
||||
{
|
||||
CommunicationToken = Guid.NewGuid(),
|
||||
ConnectionEstablished = true
|
||||
};
|
||||
|
||||
proxy.Setup(p => p.Connect(It.IsAny<Guid>())).Returns(response);
|
||||
proxy.Setup(o => o.State).Returns(CommunicationState.Faulted);
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Returns(proxy.Object);
|
||||
|
||||
var token = Guid.NewGuid();
|
||||
|
||||
sut.Connect(token);
|
||||
sut.Send(new Mock<Message>().Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void MustNotAllowSendingNull()
|
||||
{
|
||||
sut.Send(null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustSendCorrectly()
|
||||
{
|
||||
var proxy = new Mock<IProxyObject>();
|
||||
var connectionResponse = new ConnectionResponse
|
||||
{
|
||||
CommunicationToken = Guid.NewGuid(),
|
||||
ConnectionEstablished = true
|
||||
};
|
||||
var message = new SimpleMessage(SimpleMessagePurport.Authenticate);
|
||||
var response = new Mock<Response>();
|
||||
|
||||
proxy.Setup(p => p.Connect(It.IsAny<Guid>())).Returns(connectionResponse);
|
||||
proxy.Setup(p => p.Send(message)).Returns(response.Object);
|
||||
proxy.Setup(o => o.State).Returns(CommunicationState.Opened);
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Returns(proxy.Object);
|
||||
|
||||
var token = Guid.NewGuid();
|
||||
var connected = sut.Connect(token);
|
||||
var received = sut.Send(message);
|
||||
|
||||
Assert.AreEqual(response.Object, received);
|
||||
Assert.AreEqual(connectionResponse.CommunicationToken, message.CommunicationToken);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustSendSimpleMessageCorrectly()
|
||||
{
|
||||
var proxy = new Mock<IProxyObject>();
|
||||
var connectionResponse = new ConnectionResponse
|
||||
{
|
||||
CommunicationToken = Guid.NewGuid(),
|
||||
ConnectionEstablished = true
|
||||
};
|
||||
var purport = SimpleMessagePurport.Authenticate;
|
||||
var response = new Mock<Response>();
|
||||
|
||||
proxy.Setup(p => p.Connect(It.IsAny<Guid>())).Returns(connectionResponse);
|
||||
proxy.Setup(p => p.Send(It.IsAny<Message>())).Returns(response.Object);
|
||||
proxy.Setup(o => o.State).Returns(CommunicationState.Opened);
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Returns(proxy.Object);
|
||||
|
||||
var token = Guid.NewGuid();
|
||||
var connected = sut.Connect(token);
|
||||
var received = sut.Send(purport);
|
||||
|
||||
proxy.Verify(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == purport)));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustTestAcknowledgeResponsesCorrectly()
|
||||
{
|
||||
var nullResponse = sut.IsAcknowledged(null);
|
||||
var notAcknowledge = sut.IsAcknowledged(new SimpleResponse(SimpleResponsePurport.Unauthorized));
|
||||
var acknowledge = sut.IsAcknowledged(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
Assert.IsFalse(nullResponse);
|
||||
Assert.IsFalse(notAcknowledge);
|
||||
Assert.IsTrue(acknowledge);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustToStringSafely()
|
||||
{
|
||||
var message = new Mock<Message>();
|
||||
var response = new Mock<Response>();
|
||||
|
||||
message.Setup(m => m.ToString()).Returns(nameof(Message));
|
||||
response.Setup(r => r.ToString()).Returns(nameof(Response));
|
||||
|
||||
var nullStringMessage = sut.ToString(null as Message);
|
||||
var nullStringResponse = sut.ToString(null as Response);
|
||||
var messageString = sut.ToString(message.Object);
|
||||
var responseString = sut.ToString(response.Object);
|
||||
|
||||
Assert.IsNotNull(nullStringMessage);
|
||||
Assert.IsNotNull(nullStringResponse);
|
||||
Assert.IsNotNull(messageString);
|
||||
Assert.IsNotNull(responseString);
|
||||
Assert.AreEqual(message.Object.ToString(), messageString);
|
||||
Assert.AreEqual(response.Object.ToString(), responseString);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestConnectionMustPingHost()
|
||||
{
|
||||
var proxy = new Mock<IProxyObject>();
|
||||
var connectionResponse = new ConnectionResponse
|
||||
{
|
||||
CommunicationToken = Guid.NewGuid(),
|
||||
ConnectionEstablished = true
|
||||
};
|
||||
|
||||
proxy.Setup(p => p.Connect(It.IsAny<Guid>())).Returns(connectionResponse);
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.Ping))).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
proxy.Setup(o => o.State).Returns(CommunicationState.Opened);
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Returns(proxy.Object);
|
||||
|
||||
var token = Guid.NewGuid();
|
||||
var connected = sut.Connect(token);
|
||||
|
||||
sut.TestConnection();
|
||||
|
||||
proxy.Verify();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestConnectionMustInvokeConnectionLostEvent()
|
||||
{
|
||||
var lost = false;
|
||||
var proxy = new Mock<IProxyObject>();
|
||||
var connectionResponse = new ConnectionResponse
|
||||
{
|
||||
CommunicationToken = Guid.NewGuid(),
|
||||
ConnectionEstablished = true
|
||||
};
|
||||
|
||||
sut.ConnectionLost += () => lost = true;
|
||||
|
||||
proxy.Setup(p => p.Connect(It.IsAny<Guid>())).Returns(connectionResponse);
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.Ping))).Returns(new SimpleResponse(SimpleResponsePurport.UnknownMessage));
|
||||
proxy.Setup(o => o.State).Returns(CommunicationState.Opened);
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Returns(proxy.Object);
|
||||
|
||||
var token = Guid.NewGuid();
|
||||
var connected = sut.Connect(token);
|
||||
|
||||
sut.TestConnection();
|
||||
|
||||
Assert.IsTrue(lost);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestConnectionMustNotFail()
|
||||
{
|
||||
var lost = false;
|
||||
var proxy = new Mock<IProxyObject>();
|
||||
var connectionResponse = new ConnectionResponse
|
||||
{
|
||||
CommunicationToken = Guid.NewGuid(),
|
||||
ConnectionEstablished = true
|
||||
};
|
||||
|
||||
sut.ConnectionLost += () => lost = true;
|
||||
|
||||
proxy.Setup(p => p.Connect(It.IsAny<Guid>())).Returns(connectionResponse);
|
||||
proxy.Setup(p => p.Send(It.IsAny<Message>())).Throws<Exception>();
|
||||
proxy.Setup(o => o.State).Returns(CommunicationState.Opened);
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Returns(proxy.Object);
|
||||
|
||||
var token = Guid.NewGuid();
|
||||
var connected = sut.Connect(token);
|
||||
|
||||
sut.TestConnection();
|
||||
|
||||
Assert.IsTrue(lost);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustLogStatusChanges()
|
||||
{
|
||||
var proxy = new Mock<IProxyObject>();
|
||||
var connectionLost = false;
|
||||
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Returns(proxy.Object);
|
||||
sut.ConnectionLost += () => connectionLost = true;
|
||||
sut.Connect(Guid.Empty);
|
||||
|
||||
proxy.Raise(p => p.Closed += null, It.IsAny<EventArgs>());
|
||||
proxy.Raise(p => p.Closing += null, It.IsAny<EventArgs>());
|
||||
proxy.Raise(p => p.Faulted += null, It.IsAny<EventArgs>());
|
||||
proxy.Raise(p => p.Opened += null, It.IsAny<EventArgs>());
|
||||
proxy.Raise(p => p.Opening += null, It.IsAny<EventArgs>());
|
||||
|
||||
logger.Verify(l => l.Debug(It.IsAny<string>()), Times.AtLeast(4));
|
||||
logger.Verify(l => l.Warn(It.IsAny<string>()), Times.AtLeastOnce);
|
||||
|
||||
Assert.IsTrue(connectionLost);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.ServiceModel;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Communication.Contracts;
|
||||
using SafeExamBrowser.Communication.Contracts.Data;
|
||||
using SafeExamBrowser.Communication.Contracts.Proxies;
|
||||
using SafeExamBrowser.Communication.Proxies;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
|
||||
namespace SafeExamBrowser.Communication.UnitTests.Proxies
|
||||
{
|
||||
[TestClass]
|
||||
public class ClientProxyTests
|
||||
{
|
||||
private Mock<ILogger> logger;
|
||||
private Mock<IProxyObjectFactory> proxyObjectFactory;
|
||||
private Mock<IProxyObject> proxy;
|
||||
private ClientProxy sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
var response = new ConnectionResponse
|
||||
{
|
||||
CommunicationToken = Guid.NewGuid(),
|
||||
ConnectionEstablished = true
|
||||
};
|
||||
|
||||
logger = new Mock<ILogger>();
|
||||
proxyObjectFactory = new Mock<IProxyObjectFactory>();
|
||||
proxy = new Mock<IProxyObject>();
|
||||
|
||||
proxy.Setup(p => p.Connect(It.IsAny<Guid>())).Returns(response);
|
||||
proxy.Setup(o => o.State).Returns(CommunicationState.Opened);
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Returns(proxy.Object);
|
||||
|
||||
sut = new ClientProxy("net.pipe://random/address/here", proxyObjectFactory.Object, logger.Object, default(Interlocutor));
|
||||
sut.Connect(Guid.NewGuid());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyInitiateShutdown()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.Shutdown))).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.InitiateShutdown();
|
||||
|
||||
proxy.Verify(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.Shutdown)), Times.Once);
|
||||
Assert.IsTrue(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfShutdownCommandNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.Shutdown))).Returns<Response>(null);
|
||||
|
||||
var communication = sut.InitiateShutdown();
|
||||
|
||||
Assert.IsFalse(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyRequestAuthentication()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.Authenticate))).Returns(new AuthenticationResponse());
|
||||
|
||||
var communication = sut.RequestAuthentication();
|
||||
var response = communication.Value;
|
||||
|
||||
proxy.Verify(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.Authenticate)), Times.Once);
|
||||
|
||||
Assert.IsTrue(communication.Success);
|
||||
Assert.IsInstanceOfType(response, typeof(AuthenticationResponse));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfAuthenticationCommandNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.Authenticate))).Returns<Response>(null);
|
||||
|
||||
var communication = sut.RequestAuthentication();
|
||||
|
||||
Assert.AreEqual(default(AuthenticationResponse), communication.Value);
|
||||
Assert.IsFalse(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyInformAboutReconfigurationAbortion()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.ReconfigurationAborted))).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.InformReconfigurationAborted();
|
||||
|
||||
proxy.Verify(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.ReconfigurationAborted)), Times.Once);
|
||||
Assert.IsTrue(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfReconfigurationAbortionNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<SimpleMessage>())).Returns<Response>(null);
|
||||
|
||||
var communication = sut.InformReconfigurationAborted();
|
||||
|
||||
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 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()
|
||||
{
|
||||
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 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()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<MessageBoxRequestMessage>())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.ShowMessage(default(string), default(string), default(int), default(int), default(Guid));
|
||||
|
||||
proxy.Verify(p => p.Send(It.IsAny<MessageBoxRequestMessage>()), Times.Once);
|
||||
Assert.IsTrue(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfMessageBoxRequestNotAchnowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<MessageBoxRequestMessage>())).Returns<Response>(null);
|
||||
|
||||
var communication = sut.ShowMessage(default(string), default(string), default(int), default(int), default(Guid));
|
||||
|
||||
Assert.IsFalse(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustExecuteAllOperationsFailsafe()
|
||||
{
|
||||
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 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(reconfigurationAborted.Success);
|
||||
Assert.IsFalse(reconfigurationDenied.Success);
|
||||
Assert.IsFalse(serverFailure.Success);
|
||||
Assert.IsFalse(shutdown.Success);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,268 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.ServiceModel;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
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;
|
||||
|
||||
namespace SafeExamBrowser.Communication.UnitTests.Proxies
|
||||
{
|
||||
[TestClass]
|
||||
public class RuntimeProxyTests
|
||||
{
|
||||
private Mock<ILogger> logger;
|
||||
private Mock<IProxyObjectFactory> proxyObjectFactory;
|
||||
private Mock<IProxyObject> proxy;
|
||||
private RuntimeProxy sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
var response = new ConnectionResponse
|
||||
{
|
||||
CommunicationToken = Guid.NewGuid(),
|
||||
ConnectionEstablished = true
|
||||
};
|
||||
|
||||
logger = new Mock<ILogger>();
|
||||
proxyObjectFactory = new Mock<IProxyObjectFactory>();
|
||||
proxy = new Mock<IProxyObject>();
|
||||
|
||||
proxy.Setup(p => p.Connect(It.IsAny<Guid>())).Returns(response);
|
||||
proxy.Setup(o => o.State).Returns(CommunicationState.Opened);
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Returns(proxy.Object);
|
||||
|
||||
sut = new RuntimeProxy("net.pipe://random/address/here", proxyObjectFactory.Object, logger.Object, default(Interlocutor));
|
||||
sut.Connect(Guid.NewGuid());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyRetrieveConfiguration()
|
||||
{
|
||||
var response = new ConfigurationResponse
|
||||
{
|
||||
Configuration = new ClientConfiguration()
|
||||
};
|
||||
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.ConfigurationNeeded))).Returns(response);
|
||||
|
||||
var communication = sut.GetConfiguration();
|
||||
var configuration = communication.Value.Configuration;
|
||||
|
||||
proxy.Verify(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.ConfigurationNeeded)), Times.Once);
|
||||
|
||||
Assert.IsTrue(communication.Success);
|
||||
Assert.IsInstanceOfType(configuration, typeof(ClientConfiguration));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfConfigurationNotRetrieved()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.ConfigurationNeeded))).Returns<Response>(null);
|
||||
|
||||
var communication = sut.GetConfiguration();
|
||||
|
||||
Assert.IsFalse(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyInformClientReady()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.ClientIsReady))).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.InformClientReady();
|
||||
|
||||
Assert.IsTrue(communication.Success);
|
||||
proxy.Verify(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.ClientIsReady)), Times.Once);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfClientReadyNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.ClientIsReady))).Returns<Response>(null);
|
||||
|
||||
var communication = sut.InformClientReady();
|
||||
|
||||
Assert.IsFalse(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyRequestReconfiguration()
|
||||
{
|
||||
var path = "file:///C:/Some/file/url.seb";
|
||||
var url = @"https://www.host.abc/someresource.seb";
|
||||
|
||||
proxy.Setup(p => p.Send(It.Is<ReconfigurationMessage>(m => m.ConfigurationPath == path))).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.RequestReconfiguration(path, url);
|
||||
|
||||
Assert.IsTrue(communication.Success);
|
||||
proxy.Verify(p => p.Send(It.Is<ReconfigurationMessage>(m => m.ConfigurationPath == path && m.ResourceUrl == url)), Times.Once);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfReconfigurationRequestNotAcknowledged()
|
||||
{
|
||||
var path = "file:///C:/Some/file/url.seb";
|
||||
var url = @"https://www.host.abc/someresource.seb";
|
||||
|
||||
proxy.Setup(p => p.Send(It.Is<ReconfigurationMessage>(m => m.ConfigurationPath == path))).Returns<Response>(null);
|
||||
|
||||
var communication = sut.RequestReconfiguration(path, url);
|
||||
|
||||
Assert.IsFalse(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyRequestShutdown()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.RequestShutdown))).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.RequestShutdown();
|
||||
|
||||
Assert.IsTrue(communication.Success);
|
||||
proxy.Verify(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.RequestShutdown)), Times.Once);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfShutdownRequestNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.RequestShutdown))).Returns<Response>(null);
|
||||
|
||||
var communication = sut.RequestShutdown();
|
||||
|
||||
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()
|
||||
{
|
||||
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 MustCorrectlySubmitMessageBoxResult()
|
||||
{
|
||||
var result = 1234;
|
||||
var requestId = Guid.NewGuid();
|
||||
|
||||
proxy.Setup(p => p.Send(It.IsAny<MessageBoxReplyMessage>())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.SubmitMessageBoxResult(requestId, result);
|
||||
|
||||
Assert.IsTrue(communication.Success);
|
||||
proxy.Verify(p => p.Send(It.Is<MessageBoxReplyMessage>(m => m.Result == result && m.RequestId == requestId)), Times.Once);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfMessageBoxResultTransmissionNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<MessageBoxReplyMessage>())).Returns<Response>(null);
|
||||
|
||||
var communication = sut.SubmitMessageBoxResult(default(Guid), default(int));
|
||||
|
||||
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()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<Message>())).Throws<Exception>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
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;
|
||||
|
||||
namespace SafeExamBrowser.Communication.UnitTests.Proxies
|
||||
{
|
||||
[TestClass]
|
||||
public class ServiceProxyTests
|
||||
{
|
||||
private Mock<ILogger> logger;
|
||||
private Mock<IProxyObjectFactory> proxyObjectFactory;
|
||||
private Mock<IProxyObject> proxy;
|
||||
private ServiceProxy sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
var response = new ConnectionResponse
|
||||
{
|
||||
CommunicationToken = Guid.NewGuid(),
|
||||
ConnectionEstablished = true
|
||||
};
|
||||
|
||||
logger = new Mock<ILogger>();
|
||||
proxyObjectFactory = new Mock<IProxyObjectFactory>();
|
||||
proxy = new Mock<IProxyObject>();
|
||||
|
||||
proxy.Setup(p => p.Connect(null)).Returns(response);
|
||||
proxy.Setup(o => o.State).Returns(System.ServiceModel.CommunicationState.Opened);
|
||||
proxyObjectFactory.Setup(f => f.CreateObject(It.IsAny<string>())).Returns(proxy.Object);
|
||||
|
||||
sut = new ServiceProxy("net.pipe://random/address/here", proxyObjectFactory.Object, logger.Object, default(Interlocutor));
|
||||
sut.Connect();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlySendSystemConfigurationUpdate()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.UpdateSystemConfiguration))).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.RunSystemConfigurationUpdate();
|
||||
|
||||
proxy.Verify(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.UpdateSystemConfiguration)), Times.Once);
|
||||
|
||||
Assert.IsTrue(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfSystemConfigurationUpdateNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.Is<SimpleMessage>(m => m.Purport == SimpleMessagePurport.UpdateSystemConfiguration))).Returns<Response>(null);
|
||||
|
||||
var communication = sut.RunSystemConfigurationUpdate();
|
||||
|
||||
Assert.IsFalse(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyStartSession()
|
||||
{
|
||||
var configuration = new ServiceConfiguration { SessionId = Guid.NewGuid() };
|
||||
|
||||
proxy.Setup(p => p.Send(It.IsAny<SessionStartMessage>())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.StartSession(configuration);
|
||||
|
||||
proxy.Verify(p => p.Send(It.Is<SessionStartMessage>(m => m.Configuration.SessionId == configuration.SessionId)), Times.Once);
|
||||
|
||||
Assert.IsTrue(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfSessionStartNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<SessionStartMessage>())).Returns<Response>(null);
|
||||
|
||||
var communication = sut.StartSession(new ServiceConfiguration());
|
||||
|
||||
Assert.IsFalse(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustCorrectlyStopSession()
|
||||
{
|
||||
var sessionId = Guid.NewGuid();
|
||||
|
||||
proxy.Setup(p => p.Send(It.IsAny<SessionStopMessage>())).Returns(new SimpleResponse(SimpleResponsePurport.Acknowledged));
|
||||
|
||||
var communication = sut.StopSession(sessionId);
|
||||
|
||||
proxy.Verify(p => p.Send(It.Is<SessionStopMessage>(m => m.SessionId == sessionId)), Times.Once);
|
||||
|
||||
Assert.IsTrue(communication.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustFailIfSessionStopNotAcknowledged()
|
||||
{
|
||||
proxy.Setup(p => p.Send(It.IsAny<SessionStopMessage>())).Returns<Response>(null);
|
||||
|
||||
var communication = sut.StopSession(Guid.Empty);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,192 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\MSTest.TestAdapter.3.2.2\build\net462\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.3.2.2\build\net462\MSTest.TestAdapter.props')" />
|
||||
<Import Project="..\packages\Microsoft.Testing.Extensions.Telemetry.1.0.2\build\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.props" Condition="Exists('..\packages\Microsoft.Testing.Extensions.Telemetry.1.0.2\build\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.props')" />
|
||||
<Import Project="..\packages\Microsoft.Testing.Platform.MSBuild.1.0.2\build\netstandard2.0\Microsoft.Testing.Platform.MSBuild.props" Condition="Exists('..\packages\Microsoft.Testing.Platform.MSBuild.1.0.2\build\netstandard2.0\Microsoft.Testing.Platform.MSBuild.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{21137D66-7D01-4327-92D2-0304C25CD7DF}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SafeExamBrowser.Communication.UnitTests</RootNamespace>
|
||||
<AssemblyName>SafeExamBrowser.Communication.UnitTests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||
<IsCodedUITest>False</IsCodedUITest>
|
||||
<TestProjectType>UnitTest</TestProjectType>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Castle.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Castle.Core.5.1.1\lib\net462\Castle.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.ApplicationInsights, Version=2.22.0.997, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.ApplicationInsights.2.22.0\lib\net46\Microsoft.ApplicationInsights.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Microsoft.Testing.Extensions.Telemetry, Version=1.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Testing.Extensions.Telemetry.1.0.2\lib\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Testing.Extensions.TrxReport.Abstractions, Version=1.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Testing.Extensions.TrxReport.Abstractions.1.0.2\lib\netstandard2.0\Microsoft.Testing.Extensions.TrxReport.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Testing.Extensions.VSTestBridge, Version=1.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Testing.Extensions.VSTestBridge.1.0.2\lib\netstandard2.0\Microsoft.Testing.Extensions.VSTestBridge.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Testing.Platform, Version=1.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Testing.Platform.MSBuild.1.0.2\lib\netstandard2.0\Microsoft.Testing.Platform.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Testing.Platform.MSBuild, Version=1.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Testing.Platform.MSBuild.1.0.2\lib\netstandard2.0\Microsoft.Testing.Platform.MSBuild.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.TestPlatform.ObjectModel.17.9.0\lib\net462\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.TestPlatform.PlatformAbstractions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.TestPlatform.ObjectModel.17.9.0\lib\net462\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.TestPlatform.ObjectModel.17.9.0\lib\net462\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MSTest.TestFramework.3.2.2\lib\net462\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MSTest.TestFramework.3.2.2\lib\net462\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Moq, Version=4.20.70.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Moq.4.20.70\lib\net462\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NuGet.Frameworks, Version=6.9.1.3, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NuGet.Frameworks.6.9.1\lib\net472\NuGet.Frameworks.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Collections.Immutable, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Collections.Immutable.8.0.0\lib\net462\System.Collections.Immutable.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Diagnostics.DiagnosticSource, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.8.0.0\lib\net462\System.Diagnostics.DiagnosticSource.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Reflection.Metadata, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Reflection.Metadata.8.0.0\lib\net462\System.Reflection.Metadata.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Hosts\BaseHostStub.cs" />
|
||||
<Compile Include="Hosts\BaseHostTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Proxies\BaseProxyImpl.cs" />
|
||||
<Compile Include="Proxies\BaseProxyTests.cs" />
|
||||
<Compile Include="Proxies\ClientProxyTests.cs" />
|
||||
<Compile Include="Proxies\RuntimeProxyTests.cs" />
|
||||
<Compile Include="Proxies\ServiceProxyTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SafeExamBrowser.Communication.Contracts\SafeExamBrowser.Communication.Contracts.csproj">
|
||||
<Project>{0cd2c5fe-711a-4c32-afe0-bb804fe8b220}</Project>
|
||||
<Name>SafeExamBrowser.Communication.Contracts</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\SafeExamBrowser.Communication\SafeExamBrowser.Communication.csproj">
|
||||
<Project>{c9416a62-0623-4d38-96aa-92516b32f02f}</Project>
|
||||
<Name>SafeExamBrowser.Communication</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\SafeExamBrowser.Configuration.Contracts\SafeExamBrowser.Configuration.Contracts.csproj">
|
||||
<Project>{7d74555e-63e1-4c46-bd0a-8580552368c8}</Project>
|
||||
<Name>SafeExamBrowser.Configuration.Contracts</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\SafeExamBrowser.Logging.Contracts\SafeExamBrowser.Logging.Contracts.csproj">
|
||||
<Project>{64ea30fb-11d4-436a-9c2b-88566285363e}</Project>
|
||||
<Name>SafeExamBrowser.Logging.Contracts</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Microsoft.Testing.Platform.MSBuild.1.0.2\build\netstandard2.0\Microsoft.Testing.Platform.MSBuild.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Testing.Platform.MSBuild.1.0.2\build\netstandard2.0\Microsoft.Testing.Platform.MSBuild.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.Testing.Platform.MSBuild.1.0.2\build\netstandard2.0\Microsoft.Testing.Platform.MSBuild.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Testing.Platform.MSBuild.1.0.2\build\netstandard2.0\Microsoft.Testing.Platform.MSBuild.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.Testing.Extensions.Telemetry.1.0.2\build\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Testing.Extensions.Telemetry.1.0.2\build\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.props'))" />
|
||||
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.3.2.2\build\net462\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.3.2.2\build\net462\MSTest.TestAdapter.props'))" />
|
||||
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.3.2.2\build\net462\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.3.2.2\build\net462\MSTest.TestAdapter.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\packages\Microsoft.Testing.Platform.MSBuild.1.0.2\build\netstandard2.0\Microsoft.Testing.Platform.MSBuild.targets" Condition="Exists('..\packages\Microsoft.Testing.Platform.MSBuild.1.0.2\build\netstandard2.0\Microsoft.Testing.Platform.MSBuild.targets')" />
|
||||
<Import Project="..\packages\MSTest.TestAdapter.3.2.2\build\net462\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.3.2.2\build\net462\MSTest.TestAdapter.targets')" />
|
||||
</Project>
|
43
SafeExamBrowser.Communication.UnitTests/app.config
Normal file
43
SafeExamBrowser.Communication.UnitTests/app.config
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="NuGet.Frameworks" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.11.3.1" newVersion="5.11.3.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.22.0.997" newVersion="2.22.0.997" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /></startup></configuration>
|
24
SafeExamBrowser.Communication.UnitTests/packages.config
Normal file
24
SafeExamBrowser.Communication.UnitTests/packages.config
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Castle.Core" version="5.1.1" targetFramework="net48" />
|
||||
<package id="Microsoft.ApplicationInsights" version="2.22.0" targetFramework="net48" />
|
||||
<package id="Microsoft.Testing.Extensions.Telemetry" version="1.0.2" targetFramework="net48" />
|
||||
<package id="Microsoft.Testing.Extensions.TrxReport.Abstractions" version="1.0.2" targetFramework="net48" />
|
||||
<package id="Microsoft.Testing.Extensions.VSTestBridge" version="1.0.2" targetFramework="net48" />
|
||||
<package id="Microsoft.Testing.Platform" version="1.0.2" targetFramework="net48" />
|
||||
<package id="Microsoft.Testing.Platform.MSBuild" version="1.0.2" targetFramework="net48" />
|
||||
<package id="Microsoft.TestPlatform.ObjectModel" version="17.9.0" targetFramework="net48" />
|
||||
<package id="Moq" version="4.20.70" targetFramework="net48" />
|
||||
<package id="MSTest.TestAdapter" version="3.2.2" targetFramework="net48" />
|
||||
<package id="MSTest.TestFramework" version="3.2.2" targetFramework="net48" />
|
||||
<package id="NuGet.Frameworks" version="6.9.1" targetFramework="net48" />
|
||||
<package id="System.Buffers" version="4.5.1" targetFramework="net48" />
|
||||
<package id="System.Collections.Immutable" version="8.0.0" targetFramework="net48" />
|
||||
<package id="System.Diagnostics.DiagnosticSource" version="8.0.0" targetFramework="net48" />
|
||||
<package id="System.Memory" version="4.5.5" targetFramework="net48" />
|
||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
|
||||
<package id="System.Reflection.Metadata" version="8.0.0" targetFramework="net48" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net48" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net48" />
|
||||
</packages>
|
Reference in New Issue
Block a user