60 lines
No EOL
1.8 KiB
C#
60 lines
No EOL
1.8 KiB
C#
using System;
|
|
using JD.Interfaces.Remoting;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
|
|
namespace JD.Remoting.Tests
|
|
{
|
|
/*[TestFixture]
|
|
public class PluginTests
|
|
{
|
|
[Test]
|
|
public void Test_handler_is_called_when_a_command_of_the_given_name_is_sent_by_the_connection()
|
|
{
|
|
var connection = Substitute.For<IConnection>();
|
|
var plugin = new Plugin("MyPlugin", connection);
|
|
|
|
int timesCalled = 0;
|
|
plugin.RegisterHandler("MyMessage", blob => timesCalled++);
|
|
|
|
connection.Received += Raise.EventWith(new MessageReceivedEventArgsTest(new Message("MyMessage")));
|
|
|
|
Assert.AreEqual(1, timesCalled);
|
|
}
|
|
|
|
[Test]
|
|
public void Test_2_handlers_can_read_the_content_of_a_single_message()
|
|
{
|
|
var connection = Substitute.For<IConnection>();
|
|
var plugin = new Plugin("MyPlugin", connection);
|
|
var message = new Message("MyMessage");
|
|
message.Content.Push(12);
|
|
|
|
int timesCalled = 0;
|
|
Action<IBlob> handler = blob =>
|
|
{
|
|
Assert.AreEqual(12, blob.ExtractInt());
|
|
timesCalled++;
|
|
};
|
|
|
|
plugin.RegisterHandler(message.CommandName, handler);
|
|
plugin.RegisterHandler(message.CommandName, handler);
|
|
|
|
connection.Received += Raise.EventWith(new MessageReceivedEventArgs(message));
|
|
Assert.AreEqual(2, timesCalled);
|
|
}
|
|
}
|
|
|
|
public class MessageReceivedEventArgsTest : EventArgs, IMessageReceivedEventArgs
|
|
{
|
|
private Message message;
|
|
|
|
public MessageReceivedEventArgsTest(Message message)
|
|
{
|
|
this.message = message;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public IMessage Message => message;
|
|
}*/
|
|
} |