public void Subscribe_to_Publisher_twice_on_same_endpoint(RedFoxTransport transport) { for (var i = 0; i < 2; i++) { using (var publisher = new Publisher()) using (var subscriber = new TestSubscriber()) { var endpoint = TestHelpers.CreateEndpointForTransport(transport); publisher.Bind(endpoint); subscriber.Connect(endpoint); var broadcastedMessage = new TestMessage { Text = "Hello" }; publisher.Broadcast(broadcastedMessage); } } }
public void Subscribe_to_Responder_should_cause_protocol_exception(RedFoxTransport transport) { using (var responder = TestHelpers.CreateTestResponder()) using (var subscriber = new TestSubscriber()) { var endpoint = TestHelpers.CreateEndpointForTransport(transport); responder.Bind(endpoint); try { subscriber.Connect(endpoint); } catch (AggregateException ex) { throw ex.InnerExceptions.First(); } } }
public void Subscribe_to_Publisher_receive_single_broadcasted_message(RedFoxTransport transport) { using (var publisher = new Publisher()) using (var subscriber = new TestSubscriber()) { var endpoint = TestHelpers.CreateEndpointForTransport(transport); publisher.Bind(endpoint); subscriber.Connect(endpoint); Thread.Sleep(100); var broadcastedMessage = new TestMessage { Text = "Hello" }; publisher.Broadcast(broadcastedMessage); Assert.AreEqual(broadcastedMessage, subscriber.TestMustReceiveMessageWithin(Timeout)); } }
public void one_subscriber_connects_to_one_publisher_receives_message_then_second_subscriber_connects_both_receive_message(RedFoxTransport transport) { using (var publisher = new Publisher()) using (var subscriber1 = new TestSubscriber()) using (var subscriber2 = new TestSubscriber()) { var endpoint = TestHelpers.CreateEndpointForTransport(transport); publisher.Bind(endpoint); subscriber1.Connect(endpoint); Thread.Sleep(100); var broadcastMessage = new TestMessage { Text = "Hello" }; publisher.Broadcast(broadcastMessage); Assert.AreEqual(broadcastMessage, subscriber1.TestMustReceiveMessageWithin(Timeout)); subscriber2.Connect(endpoint); Thread.Sleep(100); publisher.Broadcast(broadcastMessage); Assert.AreEqual(broadcastMessage, subscriber1.TestMustReceiveMessageWithin(Timeout)); Assert.AreEqual(broadcastMessage, subscriber2.TestMustReceiveMessageWithin(Timeout)); } }
public void Subscriber_IsDisconnected_should_be_true_when_disconnected(RedFoxTransport transport) { using (var publisher = new Publisher()) using (var subscriber = new TestSubscriber()) { var endpoint = TestHelpers.CreateEndpointForTransport(transport); publisher.Bind(endpoint); subscriber.Connect(endpoint); subscriber.Disconnect(); Assert.IsTrue(subscriber.IsDisconnected); } }
public void Subscriber_Disconnect_doesnt_hang(RedFoxTransport transport) { using (var publisher = new Publisher()) using (var subscriber = new TestSubscriber()) { var endpoint = TestHelpers.CreateEndpointForTransport(transport); publisher.Bind(endpoint); subscriber.Connect(endpoint); subscriber.Disconnect(true, Timeout); } }
public void Publisher_Unbound_Subscriber_Disconnected_event_fires(RedFoxTransport transport) { using (var publisher = new Publisher()) using (var subscriber = new TestSubscriber()) { var endpoint = TestHelpers.CreateEndpointForTransport(transport); var eventFired = new ManualResetEventSlim(); publisher.Bind(endpoint); subscriber.Disconnected += eventFired.Set; subscriber.Connect(endpoint); publisher.Unbind(endpoint); Assert.IsTrue(eventFired.Wait(Timeout)); Assert.IsTrue(subscriber.IsDisconnected); } }
public void Subscriber_sends_message_Publisher_receives_message(RedFoxTransport transport) { using (var publisher = new Publisher()) using (var subscriber = new TestSubscriber()) { var endpoint = TestHelpers.CreateEndpointForTransport(transport); var eventFired = new ManualResetEventSlim(); IMessage messageReceived = null; ISocket messageSocket = null; publisher.MessageReceived += (s, m) => { messageSocket = s; messageReceived = m; eventFired.Set(); }; ISocket connectedSocket = null; publisher.ClientConnected += (s, m) => { connectedSocket = s; }; publisher.Bind(endpoint); subscriber.Connect(endpoint); IMessage messageSent = new TestMessage("test"); subscriber.SendMessage(messageSent); Assert.IsTrue(eventFired.Wait(Timeout)); Assert.AreEqual(messageSent, messageReceived); Assert.AreEqual(connectedSocket, messageSocket); } }