public void CreateNewPublisher_ReturnsPublisher() { // Arrange var factory = new NetMQFactory(requestDispatcher, topicDispatcher, monitor, messageFactory); // Act var publisher = factory.CreatePublisher(TcpAddress.Wildcard(5555)); // Assert Assert.That(publisher, Is.Not.Null); }
public static void Run() { var router = UnityBuilder.Named("TestServer") .WithTransport <NetMQTransport>(t => t.WithReceiver(TcpAddress.Wildcard(5555))) .WithHandlers(h => h.WithAsyncRequestHandler <TestMessage, TestMessage>(Handler)) .BuildAndStart(); Console.WriteLine("Press enter to stop server"); Console.ReadLine(); router.Stop(); }
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 AddPublisher_WithExistingPublisherForAddress_ThrowsInvalidOperationException() { // Arrange var address = TcpAddress.Wildcard(5555); // Doesn't seem to work when using the mockAddress var cache = new PublisherCache(monitorCache); cache.AddFactory(factory); cache.AddPublisher <IPublisher>(address); // Act TestDelegate addPublisher = () => cache.AddPublisher <IPublisher>(address); // Assert Assert.That(addPublisher, Throws.InvalidOperationException); }
public void AddReceiver_WithExistingReceiverForAddress_ThrowsInvalidOperationException() { // Arrange var address = TcpAddress.Wildcard(5555); var cache = new ReceiverCache(monitorCache); cache.AddFactory(receiverFactory); cache.AddReceiver <IReceiver>(address); // Act TestDelegate addReceiver = () => cache.AddReceiver <IReceiver>(address); // Assert Assert.That(addReceiver, Throws.InvalidOperationException); }
public void Remove_WithUnaddedAddress_DoesNothing() { // Arrange var socket = new RouterSocket(); var receiver = new NetMQReceiver(socket, messageFactory, requestDispatcher); // Act TestDelegate test = () => receiver.RemoveAddress(TcpAddress.Wildcard(5555)); // Assert Assert.That(test, Throws.Nothing); // Cleanup receiver.Dispose(); }
public void AddAddress_WithNewAddress_AddsToAddresses() { // Arrange var socket = new RouterSocket(); var receiver = new NetMQReceiver(socket, messageFactory, requestDispatcher); var address = TcpAddress.Wildcard(5555); // Act receiver.AddAddress(address); // Assert CollectionAssert.Contains(receiver.Addresses, address); // Cleanup receiver.Dispose(); }
public void RemoveAllAddresses_WithAddedAddresses_ClearsAddresses() { // Arrange var socket = new SubscriberSocket(); var subscriber = new NetMQSubscriber(socket, messageFactory, topicDispatcher); subscriber.AddAddress(TcpAddress.Wildcard(5555)); // Act subscriber.RemoveAllAddresses(); // Assert CollectionAssert.IsEmpty(subscriber.Addresses); // Cleanup subscriber.Dispose(); }
public void RemoveAllAddresses_WithAddedAddresses_IsConnectedFalse() { // Arrange var socket = new PublisherSocket(); var publisher = new NetMQPublisher(socket, messageFactory); publisher.AddAddress(TcpAddress.Wildcard(5555)); // Act publisher.RemoveAllAddresses(); // Assert Assert.That(publisher.IsConnected, Is.False); // Cleanup publisher.Dispose(); }
public void RemoveAllAddresses_WithAddedAddresses_ClearsAddresses() { // Arrange var socket = new PublisherSocket(); var publisher = new NetMQPublisher(socket, messageFactory); publisher.AddAddress(TcpAddress.Wildcard(5555)); // Act publisher.RemoveAllAddresses(); // Assert CollectionAssert.IsEmpty(publisher.Addresses); // Cleanup publisher.Dispose(); }
public void RemoveAllAddresses_WithAddedAddresses_ClearsAddresses() { // Arrange var socket = new RouterSocket(); var receiver = new NetMQReceiver(socket, messageFactory, requestDispatcher); receiver.AddAddress(TcpAddress.Wildcard(5555)); // Act receiver.RemoveAllAddresses(); // Assert CollectionAssert.IsEmpty(receiver.Addresses); // Cleanup receiver.Dispose(); }
public void RemoveAllAddresses_WithAddedAddresses_IsConnectedFalse() { // Arrange var socket = new SubscriberSocket(); var subscriber = new NetMQSubscriber(socket, messageFactory, topicDispatcher); subscriber.AddAddress(TcpAddress.Wildcard(5555)); // Act subscriber.RemoveAllAddresses(); // Assert Assert.That(subscriber.IsConnected, Is.False); // Cleanup subscriber.Dispose(); }
public void RemoveAllAddresses_WithAddedAddresses_IsConnectedFalse() { // Arrange var socket = new RouterSocket(); var receiver = new NetMQReceiver(socket, messageFactory, requestDispatcher); receiver.AddAddress(TcpAddress.Wildcard(5555)); // Act receiver.RemoveAllAddresses(); // Assert Assert.That(receiver.IsConnected, Is.False); // Cleanup receiver.Dispose(); }
public void Remove_WithAddedAddress_IsConnectedFalse() { // Arrange var socket = new DealerSocket(); var sender = new NetMQSender(socket, messageFactory); var address = TcpAddress.Wildcard(5555); sender.AddAddress(address); // Act sender.RemoveAddress(address); // Assert Assert.That(sender.IsConnected, Is.False); // Cleanup sender.Dispose(); }
public void Addresses_WhenDisposed_ThrowsInvalidOperationException() { // Arrange var socket = new DealerSocket(); var sender = new NetMQSender(socket, messageFactory); var address = TcpAddress.Wildcard(5555); sender.Dispose(); // Act void AddAddress() => sender.AddAddress(address); // Assert Assert.That(AddAddress, Throws.TypeOf <InvalidOperationException>()); // Cleanup sender.Dispose(); }
public void AddAddress_WithAlreadyAddedAddress_DoesNotAddTwice() { // Arrange var socket = new RouterSocket(); var receiver = new NetMQReceiver(socket, messageFactory, requestDispatcher); var address = TcpAddress.Wildcard(5555); receiver.AddAddress(address); // Act receiver.AddAddress(address); // Assert Assert.That(receiver.Addresses, Has.Count.EqualTo(1)); // Cleanup receiver.Dispose(); }
public void Addresses_WhenDisposed_ThrowsInvalidOperationException() { // Arrange var socket = new RouterSocket(); var receiver = new NetMQReceiver(socket, messageFactory, requestDispatcher); var address = TcpAddress.Wildcard(5555); receiver.Dispose(); // Act void AddAddress() => receiver.AddAddress(address); // Assert Assert.That(AddAddress, Throws.TypeOf <InvalidOperationException>()); // Cleanup socket.Dispose(); }
public void Remove_WithAddedAddress_RemovesAddress() { // Arrange var socket = new RouterSocket(); var receiver = new NetMQReceiver(socket, messageFactory, requestDispatcher); var address = TcpAddress.Wildcard(5555); receiver.AddAddress(address); // Act receiver.RemoveAddress(address); // Assert CollectionAssert.DoesNotContain(receiver.Addresses, address); // 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(); }
public void Remove_WithAddedAddress_IsConnectedTrue() { // Arrange var socket = new DealerSocket(); var sender = new NetMQSender(socket, messageFactory); var address = TcpAddress.Wildcard(5555); var address2 = TcpAddress.Wildcard(5556); sender.AddAddress(address); sender.AddAddress(address2); sender.InitializeConnection(); // Act sender.RemoveAddress(address); // Assert Assert.That(sender.IsConnected, Is.True); // Cleanup sender.TerminateConnection(); sender.Dispose(); }
public Publisher() { router = UnityBuilder.Named("Publisher") .WithTransport <NetMQTransport>(t => t.WithPublisher(TcpAddress.Wildcard(5556))) .Build(); }