Exemple #1
0
        public void ExceptionCaughtAndReportedIfThrownWhenReadingMessage()
        {
            var exception      = new Exception();
            var fakeDataReader = new FakeDataReader();

            fakeDataReader.Setup <string>("ReadString", () => { throw exception; });

            var fakeWebSocketResponse = new FakeWebSocketResponse();

            fakeWebSocketResponse.Setup("GetDataReader", () => fakeDataReader);

            var transport = new WebSocketTransport();

            transport.Start(
                new FakeConnection
            {
                TransportConnectTimeout = new TimeSpan(0, 0, 0, 0, 100)
            },
                string.Empty, CancellationToken.None);

            var fakeConnection = new FakeConnection();

            transport.MessageReceived(fakeWebSocketResponse, fakeConnection);

            fakeConnection.Verify("OnError", new List <object[]> {
                new object[] { exception }
            });
        }
Exemple #2
0
        public void MessageReceivedReadsAndProcessesMessages()
        {
            var fakeDataReader = new FakeDataReader
            {
                UnicodeEncoding        = (UnicodeEncoding)(-1),
                UnconsumedBufferLength = 42
            };

            fakeDataReader.Setup("ReadString", () => "MessageBody");

            var fakeWebSocketResponse = new FakeWebSocketResponse();

            fakeWebSocketResponse.Setup("GetDataReader", () => fakeDataReader);

            var transport = new WebSocketTransport();

            transport.Start(new FakeConnection(), string.Empty, CancellationToken.None);

            var fakeConnection = new FakeConnection();

            transport.MessageReceived(fakeWebSocketResponse, fakeConnection);

            Assert.Equal(UnicodeEncoding.Utf8, fakeDataReader.UnicodeEncoding);
            fakeDataReader.Verify("ReadString", new List <object[]> {
                new object[] { 42u }
            });

            // invoked by ProcessResponse
            Assert.Equal(1, fakeConnection.GetInvocations("MarkLastMessage").Count());
            Assert.Equal(1, fakeConnection.GetInvocations("Trace").Count());
        }
        public void ExceptionCaughtAndReportedIfThrownWhenReadingMessage()
        {
            var exception = new Exception();
            var fakeDataReader = new FakeDataReader();

            fakeDataReader.Setup<string>("ReadString", () => { throw exception; });

            var fakeWebSocketResponse = new FakeWebSocketResponse();
            fakeWebSocketResponse.Setup("GetDataReader", () => fakeDataReader);

            var transport = new WebSocketTransport();
            transport.Start(
                new FakeConnection
                {
                    TransportConnectTimeout = new TimeSpan(0, 0, 0, 0, 100)
                },
                string.Empty, CancellationToken.None);

            var fakeConnection = new FakeConnection();
            transport.MessageReceived(fakeWebSocketResponse, fakeConnection);

            fakeConnection.Verify("OnError", new List<object[]> { new object[] { exception } });
        }
        public void MessageReceivedReadsAndProcessesMessages()
        {
            var fakeDataReader = new FakeDataReader
            {
                UnicodeEncoding = (UnicodeEncoding)(-1),
                UnconsumedBufferLength = 42
            };
            fakeDataReader.Setup("ReadString", () => "MessageBody");

            var fakeWebSocketResponse = new FakeWebSocketResponse();
            fakeWebSocketResponse.Setup("GetDataReader", () => fakeDataReader);

            var transport = new WebSocketTransport();
            transport.Start(new FakeConnection(), string.Empty, CancellationToken.None);

            var fakeConnection = new FakeConnection();
            transport.MessageReceived(fakeWebSocketResponse, fakeConnection);

            Assert.Equal(UnicodeEncoding.Utf8, fakeDataReader.UnicodeEncoding);
            fakeDataReader.Verify("ReadString", new List<object[]> {new object[] { 42u}});

            // invoked by ProcessResponse
            Assert.Equal(1, fakeConnection.GetInvocations("MarkLastMessage").Count());
            Assert.Equal(1, fakeConnection.GetInvocations("Trace").Count());
        }