Esempio n. 1
0
        public ClientConnectionWrapperBase GetClientConnectionWrapper()
        {
            var clientConnection = new MockWebSocket();
            var serverConnection = new MockWebSocket();

            return(new MockClientConnectionWrapper(AlphaWrapper.Startup?.Context, clientConnection, serverConnection));
        }
        public async Task TestWebsocket()
        {
            var leftWebsocket  = new MockWebSocket();
            var rightWebsocket = new MockWebSocket();

            leftWebsocket.Connect(rightWebsocket);
            rightWebsocket.Connect(leftWebsocket);

            var receiveData = XdrBufferFactory.Rent(1024);

            for (var i = 0; i < 100000; i++)
            {
                var data = GetTestData();
                await rightWebsocket.SendAsync(data, WebSocketMessageType.Binary, true, CancellationToken.None);

                var segment = receiveData.AsSegment(0, 1024);
                var res     = await leftWebsocket.ReceiveAsync(segment, CancellationToken.None);

                Assert.AreEqual(data.Length, res.Count);
                Assert.IsTrue(data.SequenceEqual(segment.Slice(0, res.Count).ToArray()));
            }
        }
 public MockClientConnectionWrapper(AlphaContext alphaContext, MockWebSocket webSocket, MockWebSocket webSocketServer)
     : base(webSocket)
 {
     this.alphaContext    = alphaContext;
     this.webSocketServer = webSocketServer;
 }
 public void Connect(MockWebSocket webSocket)
 {
     secondPartyWebsocket = webSocket;
     webSocket.AssignMessagePool(pendingMessages);
     state = WebSocketState.Open;
 }