public async Task StubIntegration_RegularGet_Dynamic_RootUrl() { // arrange const string query = "?var1=value1&var2=value2"; var url = $"{TestServer.BaseAddress}dynamic-root-url.txt{query}"; var baseUrl = TestServer.BaseAddress.OriginalString.TrimEnd('/'); var expectedResult = $"URL: {baseUrl}"; ClientIpResolverMock .Setup(m => m.GetHost()) .Returns("localhost"); var request = new HttpRequestMessage(HttpMethod.Get, url); // act / assert using var response = await Client.SendAsync(request); var content = await response.Content.ReadAsStringAsync(); Assert.AreEqual(expectedResult, content); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.AreEqual(Constants.TextMime, response.Content.Headers.ContentType.ToString()); Assert.AreEqual(baseUrl, response.Headers.Single(h => h.Key == "X-Header").Value.Single()); }
public async Task StubIntegration_RegularGet_IsHttps_Ok() { // arrange var url = $"{TestServer.BaseAddress}ishttps-ok"; var request = new HttpRequestMessage { RequestUri = new Uri(url) }; ClientIpResolverMock .Setup(m => m.GetClientIp()) .Returns("127.0.0.1"); ClientIpResolverMock .Setup(m => m.IsHttps()) .Returns(true); // act / assert using var response = await Client.SendAsync(request); var content = await response.Content.ReadAsStringAsync(); Assert.AreEqual("ishttps-ok OK", content); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.AreEqual(Constants.TextMime, response.Content.Headers.ContentType.ToString()); }
public async Task StubIntegration_RegularGet_ClientIp_IpRange() { // arrange var url = $"{TestServer.BaseAddress}client-ip-2"; var request = new HttpRequestMessage { RequestUri = new Uri(url) }; ClientIpResolverMock .Setup(m => m.GetClientIp()) .Returns("127.0.0.5"); // act / assert using var response = await Client.SendAsync(request); var content = await response.Content.ReadAsStringAsync(); Assert.AreEqual("client-ip-2 OK", content); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }
public async Task StubIntegration_RegularGet_Host() { // arrange var url = $"{TestServer.BaseAddress}client-ip-1"; var request = new HttpRequestMessage { RequestUri = new Uri(url) }; request.Headers.Add("X-Forwarded-Host", "httplaceholder.com"); ClientIpResolverMock .Setup(m => m.GetClientIp()) .Returns("127.0.0.1"); // act / assert using var response = await Client.SendAsync(request); var content = await response.Content.ReadAsStringAsync(); Assert.AreEqual("client-ip-1 OK", content); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }
public async Task StubIntegration_RegularGet_Dynamic_ClientIp() { // arrange const string ip = "11.22.33.44"; var url = $"{TestServer.BaseAddress}dynamic-client-ip.txt"; var expectedResult = $"IP: {ip}"; ClientIpResolverMock .Setup(m => m.GetClientIp()) .Returns(ip); var request = new HttpRequestMessage(HttpMethod.Get, url); // act / assert using var response = await Client.SendAsync(request); var content = await response.Content.ReadAsStringAsync(); Assert.AreEqual(expectedResult, content); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.AreEqual("text/plain", response.Content.Headers.ContentType.ToString()); Assert.AreEqual(ip, response.Headers.Single(h => h.Key == "X-Header").Value.Single()); }