Beispiel #1
0
        public async Task Basics()
        {
            OperationInfo       opInfo;
            HttpResponseMessage response;

            using (var fixture = new ProxyTestFixture())
            {
                // Verify that receiving a small response works.

                opInfo = await fixture.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/"), "Hello World!");

                response = opInfo.ProxyResponse;

                Assert.Equal(200, (int)response.StatusCode);
                Assert.Equal("OK", response.ReasonPhrase);
                Assert.Equal("Hello World!", response.Content.ReadAsStringAsync().Result);

                // Verify that receiving a large response works.

                opInfo = await fixture.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/"), largeContent);

                response = opInfo.ProxyResponse;

                Assert.Equal(200, (int)response.StatusCode);
                Assert.Equal("OK", response.ReasonPhrase);
                Assert.Equal(largeContent, response.Content.ReadAsStringAsync().Result);

                // Verify that custom server headers are returned.

                opInfo = await fixture.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/"), "Hello World!",
                                                 headers : new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("X-Foo", "BAR"),
                    new KeyValuePair <string, string>("X-Hello", "WORLD!")
                });

                response = opInfo.ProxyResponse;

                Assert.Equal(200, (int)response.StatusCode);
                Assert.Equal("OK", response.ReasonPhrase);
                Assert.Equal("Hello World!", response.Content.ReadAsStringAsync().Result);
                Assert.Equal("BAR", response.Headers.GetValues("X-Foo").First());
                Assert.Equal("WORLD!", response.Headers.GetValues("X-Hello").First());
            }
        }
Beispiel #2
0
        public async Task Load()
        {
            // Perform some load testing with parallel requests.

            using (var fixture = new ProxyTestFixture())
            {
                var tasks     = new List <Task>();
                var timeLimit = DateTime.UtcNow + TimeSpan.FromSeconds(60);

                // Small requests task.

                tasks.Add(
                    Task.Run(
                        async() =>
                {
                    while (DateTime.UtcNow < timeLimit)
                    {
                        var opInfo   = await fixture.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/"), "Hello World!");
                        var response = opInfo.ProxyResponse;

                        Assert.Equal(200, (int)response.StatusCode);
                        Assert.Equal("OK", response.ReasonPhrase);
                        Assert.Equal("Hello World!", response.Content.ReadAsStringAsync().Result);
                    }
                }));

                // Large requests task.

                tasks.Add(
                    Task.Run(
                        async() =>
                {
                    var opInfo   = await fixture.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/"), largeContent);
                    var response = opInfo.ProxyResponse;

                    Assert.Equal(200, (int)response.StatusCode);
                    Assert.Equal("OK", response.ReasonPhrase);
                    Assert.Equal(largeContent, response.Content.ReadAsStringAsync().Result);
                }));

                await Task.WhenAll(tasks);
            }
        }