Send() public method

public Send ( IConnection connection, string data, string connectionData ) : Task
connection IConnection
data string
connectionData string
return Task
Esempio n. 1
0
        public async Task SendWritesToWebSocketOutputStream()
        {
            var fakeOutputStream = new FakeOutputStream();
            var fakeWebSocket    = new FakeWebSocket {
                OutputStream = fakeOutputStream
            };

            await WebSocketTransport.Send(fakeWebSocket, "42.42");

            var writeAsyncInvocations = fakeOutputStream.GetInvocations("WriteAsync").ToArray();

            Assert.Equal(1, writeAsyncInvocations.Length);
            Assert.Equal(5u, ((IBuffer)writeAsyncInvocations[0][0]).Length);
        }
Esempio n. 2
0
        public void WebSocketSendReturnsAFaultedTaskWhenNotConnected(WebSocketState state)
        {
            var mockConnection = new Mock<Client.IConnection>(MockBehavior.Strict);
            var mockWebSocket = new Mock<WebSocket>(MockBehavior.Strict);
            var mockWebSocketHandler = new Mock<ClientWebSocketHandler>();

            mockWebSocket.SetupGet(ws => ws.State).Returns(state);
            mockConnection.Setup(c => c.OnError(It.IsAny<InvalidOperationException>()));
            mockWebSocketHandler.Object.WebSocket = mockWebSocket.Object;
            
            var wsTransport = new WebSocketTransport(mockWebSocketHandler.Object);

            var task = wsTransport.Send(mockConnection.Object, "", "");

            Assert.True(task.IsFaulted);
            Assert.IsType(typeof(InvalidOperationException), task.Exception.InnerException);

            mockConnection.VerifyAll();
            mockWebSocket.VerifyAll();
        }