public async Task Headers() { // ARRANGE var ts = new TestState(); var request = new HttpRequestMessage(HttpMethod.Get, "http://httpbin.org/headers"); request.Headers.UserAgent.Add(new ProductInfoHeaderValue("Foo", "Bar")); request.Headers.Add("x-sockettome-test", new[] { "ABBF9526-C07F-45A6-BE6C-2BE7E7B616F6", "CE8E3A72-9D2A-4284-966E-124713DE967F" }); var expectedHeaders = new Dictionary <string, string> { { "Host", "httpbin.org" }, { "User-Agent", "Foo/Bar" }, { "X-Sockettome-Test", "ABBF9526-C07F-45A6-BE6C-2BE7E7B616F6,CE8E3A72-9D2A-4284-966E-124713DE967F" } }; // ACT var response = await ts.GetJsonResponse <JObject>(request); // ASSERT var headers = response.Content["headers"].ToObject <IDictionary <string, string> >(); foreach (var header in expectedHeaders) { headers.Should().ContainKey(header.Key); headers[header.Key].Should().Be(header.Value); } }
public async Task BasicFunctionality() { // ARRANGE var ts = new TestState(); var request = new HttpRequestMessage(HttpMethod.Get, "http://httpbin.org/ip"); // ACT var o = await ts.GetJsonResponse <IDictionary <string, string> >(request); // ASSERT o.Message.Should().NotBeNull(); o.Message.StatusCode.Should().Be(HttpStatusCode.OK); o.Message.ReasonPhrase.Should().Be("OK"); o.Message.Version.ToString().Should().Be("1.1"); o.Message.Headers.Should().NotBeNull(); o.Message.Headers.Date.Should().HaveValue(); o.Message.Headers.Date.Should().BeAfter(DateTime.MinValue); o.Content.Should().NotBeNull(); o.Message.Content.Headers.ContentType.ToString().Should().Be("application/json"); o.Content.Should().HaveCount(1); o.Content.Should().ContainKey("origin"); IPAddress.Parse(o.Content["origin"]); }
public async Task Cookies() { // ARRANGE var ts = new TestState { CookieHandler = new CookieHandler(), RedirectingHandler = new RedirectingHandler() }; // ACT await ts.GetJsonResponse <JObject>(new HttpRequestMessage(HttpMethod.Get, "http://httpbin.org/cookies/set?a=1&b=2A")); await ts.GetJsonResponse <JObject>(new HttpRequestMessage(HttpMethod.Get, "http://httpbin.org/cookies/set?b=2B")); await ts.GetJsonResponse <JObject>(new HttpRequestMessage(HttpMethod.Get, "http://httpbin.org/cookies/set?c=3")); await ts.GetJsonResponse <JObject>(new HttpRequestMessage(HttpMethod.Get, "http://httpbin.org/cookies/delete?c")); await ts.GetJsonResponse <JObject>(new HttpRequestMessage(HttpMethod.Get, "http://httpbin.org/cookies/delete?d")); var response = await ts.GetJsonResponse <JObject>(new HttpRequestMessage(HttpMethod.Get, "http://httpbin.org/cookies")); // ASSERT var cookies = response.Content["cookies"].ToObject <IDictionary <string, string> >(); cookies.ShouldBeEquivalentTo(new Dictionary <string, string> { { "a", "1" }, { "b", "2B" } }); }
public async Task IpAddressDestination() { // ARRANGE var ts = new TestState(); var request = new HttpRequestMessage(HttpMethod.Get, "http://54.175.219.8/ip"); request.Headers.Host = "httpbin.org"; // ACT var o = await ts.GetJsonResponse <IDictionary <string, string> >(request); // ASSERT o.Message.StatusCode.Should().Be(HttpStatusCode.OK); IPAddress.Parse(o.Content["origin"]); }
public async Task Redirect() { // ARRANGE var ts = new TestState { RedirectingHandler = new RedirectingHandler() }; var request = new HttpRequestMessage(HttpMethod.Get, "http://httpbin.org/redirect/10"); // ACT var response = await ts.GetJsonResponse <JObject>(request); // ASSERT response.Message.RequestMessage.RequestUri.Should().Be(new Uri("http://httpbin.org/get")); response.Message.StatusCode.Should().Be(HttpStatusCode.OK); }
public async Task FileUpload() { // ARRANGE var ts = new TestState(); var request = new HttpRequestMessage(HttpMethod.Post, "http://httpbin.org/post"); var content = new MultipartFormDataContent(); var expectedForm = new Dictionary <string, string> { { "foo", "9FEF809B-C5B6-4CDC-8F06-79C122BD71D5" }, { "bar", "A400DB56-AFED-474B-A515-B371F29D78D9" } }; foreach (var pair in expectedForm) { content.Add(new StringContent(pair.Value), pair.Key); } var fileContent = new MemoryStream(Encoding.ASCII.GetBytes("This is the file content.")); content.Add(new StreamContent(fileContent) { Headers = { ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = "FileName.txt", Name = "Name.txt" } } }); request.Content = content; // ACT var response = await ts.GetJsonResponse <JObject>(request); // ASSERT var actualForm = response.Content["form"].ToObject <IDictionary <string, string> >(); actualForm.ShouldBeEquivalentTo(expectedForm); var actualFiles = response.Content["files"].ToObject <IDictionary <string, string> >(); actualFiles.ShouldBeEquivalentTo(new Dictionary <string, string> { { "Name.txt", "This is the file content." } }); }
public async Task Gzip() { // ARRANGE var ts = new TestState { DecompressingHandler = new DecompressingHandler { AutomaticDecompression = DecompressionMethods.GZip } }; var request = new HttpRequestMessage(HttpMethod.Get, "http://httpbin.org/gzip"); // ACT var response = await ts.GetJsonResponse <JObject>(request); // ASSERT response.Message.StatusCode.Should().Be(HttpStatusCode.OK); response.Content["gzipped"].ToObject <bool>().Should().BeTrue(); }
public async Task Form() { // ARRANGE var ts = new TestState(); var request = new HttpRequestMessage(HttpMethod.Post, "http://httpbin.org/post"); var expectedForm = new Dictionary <string, string> { { "foo", "9FEF809B-C5B6-4CDC-8F06-79C122BD71D5" }, { "bar", "A400DB56-AFED-474B-A515-B371F29D78D9" } }; request.Content = new FormUrlEncodedContent(expectedForm); // ACT var response = await ts.GetJsonResponse <JObject>(request); // ASSERT var actualForm = response.Content["form"].ToObject <IDictionary <string, string> >(); actualForm.ShouldBeEquivalentTo(expectedForm); }
public async Task Post() { // ARRANGE var ts = new TestState(); var form = new Dictionary <string, string> { { "foo", "7A0D6A40-8DCE-4F6F-B372-ADC12B7FB222" }, { "bar", "9C025D9D-9880-4C03-A251-A29D5EC4BF16" } }; var request = new HttpRequestMessage(HttpMethod.Post, "http://httpbin.org/post") { Content = new FormUrlEncodedContent(form) }; // ACT var o = await ts.GetJsonResponse <JObject>(request); // ASSERT o.Message.StatusCode.Should().Be(HttpStatusCode.OK); o.Content.Should().ContainKey("form"); o.Content["form"].ToObject <IDictionary <string, string> >().ShouldBeEquivalentTo(form); }