Example #1
0
        /// <summary>
        /// Supply a request call to the hosted site, and get back a response.
        /// This is done synchronously.
        /// </summary>
        /// <param name="request">Request from client</param>
        /// <returns>Response from server</returns>
        public SerialisableResponse DirectCall(SerialisableRequest request)
        {
            var conn = new MemoryConnection(request);

            GetHost()?.ProcessRequest(conn);
            return(conn.GenerateResponse());
        }
        public async Task ReadWrite_Success()
        {
            const string ClientTestValue = "ClientString1234";
            const string ServerTestValue = "ServerString5678";

            (Connection clientConnection, Connection serverConnection) = MemoryConnection.Create();

            await using (clientConnection)
                await using (serverConnection)
                {
                    await RunClientServer(async() =>
                    {
                        using (var writer = new StreamWriter(clientConnection.Stream))
                        {
                            await writer.WriteLineAsync(ClientTestValue);
                        }
                        await clientConnection.CompleteWritesAsync();

                        using (var reader = new StreamReader(clientConnection.Stream))
                        {
                            Assert.Equal(ServerTestValue, await reader.ReadLineAsync());
                            Assert.Null(await reader.ReadLineAsync());
                        }
                    },
                                          async() =>
                    {
                        using (var writer = new StreamWriter(serverConnection.Stream))
                        {
                            await writer.WriteLineAsync(ServerTestValue);
                        }
                        await serverConnection.CompleteWritesAsync();

                        using (var reader = new StreamReader(serverConnection.Stream))
                        {
                            Assert.Equal(ClientTestValue, await reader.ReadLineAsync());
                            Assert.Null(await reader.ReadLineAsync());
                        }
                    });
                }
        }