コード例 #1
0
        public async Task HttpTestAsserterDoesNotContainKeywordInBody_Success()
        {
            using (var client = new HttpTesterClient())
            {
                var response = await client
                               .CreateHttpRequest(new Uri("https://qatoolkitapi.azurewebsites.net"))
                               .WithQueryParams(new Dictionary <string, string>()
                {
                    { "api-version", "1" }
                })
                               .WithMethod(HttpMethod.Get)
                               .WithPath("/api/bicycles")
                               .Start();

                var msg = await response.GetResponseJsonBody <List <Bicycle> >();

                var asserter = new HttpTestAsserter(response);

                var assertResults = asserter
                                    .ResponseContentContains("giant")
                                    .AssertAll();

                foreach (var result in assertResults)
                {
                    Assert.False(result.IsTrue, result.Message);
                }
            }
        }
コード例 #2
0
        public async Task HttpTestAsserterAlternativeDurationPredicate_Success()
        {
            using (var client = new HttpTesterClient())
            {
                var response = await client
                               .CreateHttpRequest(new Uri("https://qatoolkitapi.azurewebsites.net"))
                               .WithQueryParams(new Dictionary <string, string>()
                {
                    { "api-version", "1" }
                })
                               .WithMethod(HttpMethod.Get)
                               .WithPath("/api/bicycles")
                               .Start();

                var msg = await response.GetResponseJsonBody <List <Bicycle> >();

                var asserter      = new HttpTestAsserter(response);
                var duration      = client.Duration;
                var assertResults = asserter
                                    .ResponseContentContains("scott")
                                    .ResponseContentContains("id")
                                    .RequestDurationEquals(duration, (x) => (x > 100 && x < 1000))
                                    .ResponseStatusCodeEquals(HttpStatusCode.OK)
                                    .ResponseContentTypeEquals("application/json")
                                    .ResponseStatusCodeIsSuccess()
                                    .AssertAll();

                Assert.Equal(6, assertResults.ToList().Count);
                foreach (var result in assertResults)
                {
                    Assert.True(result.IsTrue, result.Message);
                }
            }
        }
コード例 #3
0
        public async Task HttpTestAsserterDeleteIsBodyEmpty_Success()
        {
            using (var client = new HttpTesterClient())
            {
                var response = await client
                               .CreateHttpRequest(new Uri("https://qatoolkitapi.azurewebsites.net"))
                               .WithQueryParams(new Dictionary <string, string>()
                {
                    { "api-version", "1" }
                })
                               .WithMethod(HttpMethod.Delete)
                               .WithPath("/api/bicycles/1")
                               .Start();

                var asserter      = new HttpTestAsserter(response);
                var duration      = client.Duration;
                var assertResults = asserter
                                    .ResponseBodyIsEmpty()
                                    .RequestDurationEquals(duration, (x) => (x > 100 && x < 2000))
                                    .ResponseStatusCodeIsSuccess()
                                    .AssertAll();

                Assert.Equal(3, assertResults.ToList().Count);
                foreach (var result in assertResults)
                {
                    Assert.True(result.IsTrue, result.Message);
                }
            }
        }
コード例 #4
0
        public async Task HttpTestAsserterBodyNull_Fails()
        {
            using (var client = new HttpTesterClient())
            {
                var response = await client
                               .CreateHttpRequest(new Uri("https://qatoolkitapi.azurewebsites.net"))
                               .WithQueryParams(new Dictionary <string, string>()
                {
                    { "api-version", "1" }
                })
                               .WithMethod(HttpMethod.Get)
                               .WithPath("/api/bicycles")
                               .Start();

                var msg = await response.GetResponseJsonBody <List <Bicycle> >();

                var asserter = new HttpTestAsserter(response);

                var duration = client.Duration;
                Assert.Throws <ArgumentNullException>(() => asserter
                                                      .ResponseContentContains(null)
                                                      .RequestDurationEquals(duration, (x) => x < 1000)
                                                      .ResponseContentTypeEquals("application/json")
                                                      .ResponseStatusCodeEquals(HttpStatusCode.OK)
                                                      .AssertAll());
            }
        }