2018-03-16 15:46:53 +01:00
|
|
|
|
/*
|
2022-01-21 16:33:52 +01:00
|
|
|
|
* Copyright (c) 2022 ETH Zürich, Educational Development and Technology (LET)
|
2018-03-16 15:46:53 +01:00
|
|
|
|
*
|
|
|
|
|
* 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;
|
2019-06-18 10:18:56 +02:00
|
|
|
|
using System.Linq;
|
2018-08-31 10:06:27 +02:00
|
|
|
|
using SafeExamBrowser.Communication.Hosts;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Communication.Contracts;
|
|
|
|
|
using SafeExamBrowser.Communication.Contracts.Data;
|
|
|
|
|
using SafeExamBrowser.Communication.Contracts.Hosts;
|
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
2018-03-16 15:46:53 +01:00
|
|
|
|
|
2018-08-31 10:06:27 +02:00
|
|
|
|
namespace SafeExamBrowser.Communication.UnitTests.Hosts
|
2018-03-16 15:46:53 +01:00
|
|
|
|
{
|
2018-06-27 14:02:16 +02:00
|
|
|
|
internal class BaseHostStub : BaseHost
|
2018-03-16 15:46:53 +01:00
|
|
|
|
{
|
|
|
|
|
public Func<Guid?, bool> OnConnectStub { get; set; }
|
2019-06-18 10:18:56 +02:00
|
|
|
|
public Action<Interlocutor> OnDisconnectStub { get; set; }
|
2018-03-16 15:46:53 +01:00
|
|
|
|
public Func<Message, Response> OnReceiveStub { get; set; }
|
|
|
|
|
public Func<SimpleMessagePurport, Response> OnReceiveSimpleMessageStub { get; set; }
|
|
|
|
|
|
2018-10-02 08:02:48 +02:00
|
|
|
|
public BaseHostStub(string address, IHostObjectFactory factory, ILogger logger, int timeout_ms) : base(address, factory, logger, timeout_ms)
|
2018-03-16 15:46:53 +01:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Guid? GetCommunicationToken()
|
|
|
|
|
{
|
2019-06-18 10:18:56 +02:00
|
|
|
|
return CommunicationToken.Any() ? CommunicationToken.First() : default(Guid?);
|
2018-03-16 15:46:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnConnect(Guid? token)
|
|
|
|
|
{
|
|
|
|
|
return OnConnectStub?.Invoke(token) == true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-18 10:18:56 +02:00
|
|
|
|
protected override void OnDisconnect(Interlocutor interlocutor)
|
2018-03-16 15:46:53 +01:00
|
|
|
|
{
|
2019-06-18 10:18:56 +02:00
|
|
|
|
OnDisconnectStub?.Invoke(interlocutor);
|
2018-03-16 15:46:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Response OnReceive(Message message)
|
|
|
|
|
{
|
|
|
|
|
return OnReceiveStub?.Invoke(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Response OnReceive(SimpleMessagePurport message)
|
|
|
|
|
{
|
|
|
|
|
return OnReceiveSimpleMessageStub?.Invoke(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|