public void can_send_command()
        {
            var handler = new WoftamCommandHandler(_longProp);

            _subscriptions.Add(_localBus.Subscribe(handler));

            // First send the command to server so it knows where to send the response.
            _tcpBusClientSide.Handle(MessageBuilder.New(() => new WoftamCommand(ShortProp)));

            // expect to receive it on the client side
            var gotMessage = _tcs.Task.Wait(TimeSpan.FromMilliseconds(1000));

            Assert.True(gotMessage);
            Assert.IsType <Success>(_tcs.Task.Result);
        }
Exemplo n.º 2
0
        public void can_filter_out_message_types()
        {
            // server side
            var serverInbound = new QueuedHandler(
                new AdHocHandler <IMessage>(_tcs.SetResult),
                "InboundMessageQueuedHandler",
                true,
                TimeSpan.FromMilliseconds(1000));

            var tcpBusServerSide = new TcpBusServerSide(
                _hostAddress,
                port,
                inboundNondiscardingMessageTypes: new[] { typeof(WoftamEvent) },
                inboundNondiscardingMessageQueuedHandler: serverInbound);

            serverInbound.Start();

            // client side
            var tcpBusClientSide = new TcpBusClientSide(_hostAddress, port);

            // wait for tcp connection to be established
            AssertEx.IsOrBecomesTrue(() => tcpBusClientSide.IsConnected, 200);

            // put disallowed message into client
            tcpBusClientSide.Handle(new WoftamCommand("abc"));

            // expect to receive it in the server but drop it on the floor
            var gotMessage = _tcs.Task.Wait(TimeSpan.FromMilliseconds(1000));

            Assert.False(gotMessage);

            tcpBusClientSide.Dispose();
            tcpBusServerSide.Dispose();
        }
Exemplo n.º 3
0
        public void can_handle_split_frames()
        {
            // 16kb large enough to cause the transport to split up the frame.
            // it would be better if we did the splitting manually so we were sure it really happened.
            // would require mocking more things.
            var prop1 = "prop1";
            var prop2 = string.Join("", Enumerable.Repeat("a", 16 * 1024));

            // server side
            var serverInbound = new QueuedHandler(
                new AdHocHandler <IMessage>(_tcs.SetResult),
                "InboundMessageQueuedHandler",
                true,
                TimeSpan.FromMilliseconds(1000));

            var tcpBusServerSide = new TcpBusServerSide(
                _hostAddress,
                port,
                inboundNondiscardingMessageTypes: new[] { typeof(WoftamEvent) },
                inboundNondiscardingMessageQueuedHandler: serverInbound);

            serverInbound.Start();

            // client side
            var tcpBusClientSide = new TcpBusClientSide(_hostAddress, port);

            // wait for tcp connection to be established
            AssertEx.IsOrBecomesTrue(() => tcpBusClientSide.IsConnected, 200);

            // put message into client
            tcpBusClientSide.Handle(new WoftamEvent(prop1, prop2));

            // expect to receive it in the server
            var gotMessage = _tcs.Task.Wait(TimeSpan.FromMilliseconds(1000));

            Assert.True(gotMessage);
            var evt = Assert.IsType <WoftamEvent>(_tcs.Task.Result);

            Assert.Equal(prop1, evt.Property1);
            Assert.Equal(prop2, evt.Property2);

            tcpBusClientSide.Dispose();
            tcpBusServerSide.Dispose();
        }
        public void can_handle_split_frames()
        {
            // 16kb large enough to cause the transport to split up the frame.
            // it would be better if we did the splitting manually so we were sure it really happened.
            // would require mocking more things.
            var hostAddress = IPAddress.Loopback;
            var prop1       = "prop1";
            var prop2       = string.Join("", Enumerable.Repeat("a", 16 * 1024));
            var port        = 10000;
            var tcs         = new TaskCompletionSource <IMessage>();

            // server side
            var serverInbound = new QueuedHandler(
                new AdHocHandler <IMessage>(tcs.SetResult),
                "InboundMessageQueuedHandler",
                true,
                TimeSpan.FromMilliseconds(1000));

            var tcpBusServerSide = new TcpBusServerSide(hostAddress, port, null)
            {
                InboundMessageQueuedHandler = serverInbound,
                InboundSpamMessageTypes     = new List <Type>(),
            };

            serverInbound.Start();

            // client side
            var tcpBusClientSide = new TcpBusClientSide(null, hostAddress, port);

            // wait for tcp connection to be established (maybe an api to detect this would be nice)
            Thread.Sleep(TimeSpan.FromMilliseconds(200));

            // put message into client
            tcpBusClientSide.Handle(new WoftamEvent(prop1, prop2));

            // expect to receive it in the server
            var gotMessage = tcs.Task.Wait(TimeSpan.FromMilliseconds(1000));

            Assert.True(gotMessage);
            var evt = Assert.IsType <WoftamEvent>(tcs.Task.Result);

            Assert.Equal(prop1, evt.Property1);
            Assert.Equal(prop2, evt.Property2);
        }