public void DispatchMessageTest() { var socket = new MockWebSocket(); var context = new MockWebSocketContext(socket); var transport = new BaseSocketTransport(PubSub, Serializer); var join = new Message("tests:join", "phx_join", null, 1); socket.InputQueue.Enqueue(join); Task.Factory.StartNew(() => transport.Init(context)); Message received; do { Thread.Sleep(500); } while (!socket.OutputQueue.TryDequeue(out received) && received == null); var message = new Message("tests:join", "event", new JObject { { "body", "hi" } }, null); socket.InputQueue.Enqueue(message); do { Thread.Sleep(500); } while (!socket.OutputQueue.TryDequeue(out received) && received == null); received.Event.Should().Be(message.Event); received.Topic.Should().Be(message.Topic); received.Payload.ToString().Should().Be(message.Payload.ToString()); }
public void JoinChannelTest() { var socket = new MockWebSocket(); var context = new MockWebSocketContext(socket); var transport = new BaseSocketTransport(PubSub, Serializer); var join = new Message("tests:join", "phx_join", null, 1); socket.InputQueue.Enqueue(join); Task.Factory.StartNew(() => transport.Init(context)); Message received; do { Thread.Sleep(500); } while (!socket.OutputQueue.TryDequeue(out received) && received == null); received.Event.Should().Be("phx_reply"); received.Topic.Should().Be(join.Topic); received.Ref.Should().Be(join.Ref); }