public void ShouldRespondToRequests() { var mockProcessor = new Mock<IProcessor>(); mockProcessor.Setup(p => p.Process(It.IsAny<Request>())).Returns(() => new SuccessResponse()); processor = mockProcessor.Object; var stepServer = new StepServer(IPAddress.Any, arguments, processor); stepServer.Init(); client = new TcpClient(); client.ReceiveTimeout = 1000; client.Connect(new IPEndPoint(IPAddress.Loopback, 54321)); Assert.IsTrue(client.Connected); stream = client.GetStream(); var strRequest = "[\"begin_scenario\"]\n"; var buffer = new byte[65535]; var length = Encoding.ASCII.GetBytes(strRequest, 0, strRequest.Length, buffer, 0); stream.Write(buffer, 0, length); length = stream.Read(buffer, 0, buffer.Length); var strReply = Encoding.ASCII.GetString(buffer, 0, length); Assert.AreEqual("[\"success\"]\n", strReply); stepServer.Stop(); }
public void ShouldAcceptTcpConnections() { var mockProcessor = new Mock<IProcessor>(); processor = mockProcessor.Object; var stepServer = new StepServer(IPAddress.Any, arguments, processor); stepServer.Init(); client = new TcpClient(); client.Connect(new IPEndPoint(IPAddress.Loopback, 54321)); Assert.IsTrue(client.Connected); stream = client.GetStream(); stepServer.Stop(); }