public async Task SenderReceiver_WhenBoundAndConnected_PassesMessage() { // Arrange var responseStr = "Hello, World!"; var requestStr = "Hello"; var receivedRequest = string.Empty; ushort port = 6555; var called = false; mockRequestDispatcher .Setup(m => m.Handle(ref It.Ref <RequestTask> .IsAny)) .Callback(new Handler((ref RequestTask task) => { called = true; receivedRequest = (string)task.Request; task.ResponseSender(responseStr); })); var packageFactory = new PackageFactory(); var serializer = new DotNetSerializer(); var serializerCache = new SerializerCache(); var messageFactory = new NetMQMessageFactory(serializerCache, packageFactory); var sender = new NetMQSender(new DealerSocket(), messageFactory); var receiver = new NetMQReceiver(new RouterSocket(), messageFactory, requestDispatcher); var poller = new NetMQPoller(); serializerCache.AddSerializer(serializer); sender.AddAddress(TcpAddress.Localhost(port)); sender.InitializeConnection(); receiver.AddAddress(TcpAddress.Wildcard(port)); receiver.InitializeConnection(); poller.Add(sender.PollableSocket); poller.Add(receiver.PollableSocket); poller.RunAsync(); var package = new DataPackage <string>(new GuidPackageId(), requestStr); // Act var response = await sender.SendAndReceive(package, TimeSpan.FromSeconds(5)); // Cleanup poller.StopAsync(); sender.TerminateConnection(); receiver.TerminateConnection(); // Assert Assert.That(called, Is.True); Assert.That(receivedRequest, Is.EqualTo(requestStr)); Assert.That((string)response, Is.EqualTo(responseStr)); }
public void Bind_WithNoAddresses_DoesNothing() { // Arrange var socket = new RouterSocket(); var receiver = new NetMQReceiver(socket, messageFactory, requestDispatcher); // Act TestDelegate test = () => receiver.InitializeConnection(); // Assert Assert.That(test, Throws.Nothing); // Cleanup receiver.Dispose(); }
public void Bind_WhenCalled_SetsIsBound() { // Arrange var socket = new RouterSocket(); var receiver = new NetMQReceiver(socket, messageFactory, requestDispatcher); // Act receiver.InitializeConnection(); // Assert Assert.That(receiver.IsConnected, Is.True); // Cleanup receiver.TerminateConnection(); receiver.Dispose(); }
public void IsConnected_OnceBindIsCalled_IsTrue() { // Arrange var socket = new RouterSocket(); var receiver = new NetMQReceiver(socket, messageFactory, requestDispatcher); receiver.InitializeConnection(); // Act var isConnected = receiver.IsConnected; // Assert Assert.That(isConnected, Is.True); // Cleanup receiver.Dispose(); }
public void Remove_WithAddedAddress_IsConnectedTrue() { // Arrange var socket = new RouterSocket(); var receiver = new NetMQReceiver(socket, messageFactory, requestDispatcher); var address = TcpAddress.Wildcard(5555); var address2 = TcpAddress.Wildcard(5556); receiver.AddAddress(address); receiver.AddAddress(address2); receiver.InitializeConnection(); // Act receiver.RemoveAddress(address); // Assert Assert.That(receiver.IsConnected, Is.True); // Cleanup receiver.Dispose(); }