Beispiel #1
0
        public void TestServer_ClientHandler_ExecuteRequest()
        {
            // arrange
            var    mockedTcpHandler = new Mock <ITcpHandler>();
            var    mockedTcpClient  = new Mock <TcpClient>();
            Stream stream           = new MemoryStream();
            var    writer           = new StreamWriter(stream)
            {
                AutoFlush = true
            };

            var requestReceived = "GET / HTTP/1.1\r\n" +
                                  "Host: localhost:10001\r\n" +
                                  "User-Agent: curl/7.55.1\r\n" +
                                  "Accept: */*\r\n" +
                                  "\r\n";

            writer.Write(requestReceived);
            stream.Position = 0;

            mockedTcpHandler.Setup(x => x.AcceptTcpClient()).Returns(mockedTcpClient.Object);
            mockedTcpHandler.Setup(x => x.GetStream(mockedTcpClient.Object)).Returns(stream);

            // act
            ClientHandler clientHandler = new ClientHandler(mockedTcpHandler.Object);

            clientHandler.ExecuteRequest();

            // assert
            mockedTcpHandler.Verify(x => x.AcceptTcpClient());
            mockedTcpHandler.Verify(x => x.GetStream(mockedTcpClient.Object));
        }