public void HttpSocketAdapter_GetResponseStatusCode_MalformedStatusCode() { // Arrange MockSocketAdapter serverSocket = new MockSocketAdapter(); serverSocket.SendString("HTTP/1.1 NOTANUMBER OK\r\n", Encoding.ASCII); HttpSocketAdapter clientSocket = new HttpSocketAdapter("GET", new Uri("http://bing.com"), serverSocket); // Act Task <int> result = clientSocket.GetResponseStatusCode(); // Assert TaskAssert.ResultEquals(result, 500); }
public void HttpSocketAdapter_GetResponseStatusCode_ReturnsStatusCode() { // Arrange MockSocketAdapter serverSocket = new MockSocketAdapter(); HttpSocketAdapter clientSocket = new HttpSocketAdapter("GET", new Uri("http://bing.com"), serverSocket); // Act Task <int> result = clientSocket.GetResponseStatusCode(); // Assert TaskAssert.NotCompleted(result, "Before status line was sent."); // Act serverSocket.SendString("HTTP/1.1 200 OK\r\n", Encoding.ASCII); // Assert TaskAssert.ResultEquals(result, 200, "After status line was sent."); }
public void HttpSocketAdapter_GetResponseStatusCode_SocketException() { // Arrange MockSocketAdapter serverSocket = new MockSocketAdapter(); HttpSocketAdapter clientSocket = new HttpSocketAdapter("GET", new Uri("http://bing.com"), serverSocket); Task <int> responseCodeTask = clientSocket.GetResponseStatusCode(); Task <string> responseHeaderTask = clientSocket.GetResponseHeader("test header"); Task responseCompleteTask = clientSocket.WaitForResponseComplete(); // Act serverSocket.ThrowExceptionFromReceiveAsync(); // Assert TaskAssert.Faulted(responseCodeTask, "GetResponseStatusCode should have failed."); TaskAssert.Faulted(responseHeaderTask, "GetResponseHeader should have failed."); TaskAssert.Faulted(responseCompleteTask, "WaitForResponseComplete should have failed."); AssertWithMessage.Equal("An error occurred.", responseCodeTask.Exception.InnerException.Message, "Wrong exception for GetResponseStatusCode"); AssertWithMessage.Equal("An error occurred.", responseHeaderTask.Exception.InnerException.Message, "Wrong exception for GetResponseHeader"); AssertWithMessage.Equal("An error occurred.", responseCompleteTask.Exception.InnerException.Message, "Wrong exception for WaitForResponseComplete"); }