Пример #1
0
        public void Test_HttpFakes_TestWithResponse()
        {
            // Arrange - setup client and fake response.
            var fakeHttpClient = new FakeHttpClient(FAKEAPIURL);

            fakeHttpClient.AddEndPoint("api/values", new HttpResponseMessage(HttpStatusCode.OK));
            var client = fakeHttpClient.GetHttpClient();

            // Act - make fake request.
            var response = client.GetAsync("api/values").GetAwaiter().GetResult();

            // Assert - response was as expected.
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
Пример #2
0
        public void Test_HttpFakes_DoesNotExist()
        {
            // Arrange - setup client and fake response.
            var fakeHttpClient = new FakeHttpClient(FAKEAPIURL);

            fakeHttpClient.AddEndPoint("api/values", HttpStatusCode.OK);
            var client = fakeHttpClient.GetHttpClient();

            // Act - make fake request.
            var response = client.GetAsync("anotherEndpoint").GetAwaiter().GetResult();

            // Assert - response was as expected.
            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
Пример #3
0
        public void Test_HttpFakes_VerifyResponseData()
        {
            // Arrange - setup client and fake response.
            var responseData   = "test";
            var fakeHttpClient = new FakeHttpClient(FAKEAPIURL);

            fakeHttpClient.AddEndPoint("api/values", HttpStatusCode.OK, responseData);
            var client = fakeHttpClient.GetHttpClient();

            // Act - make fake request and get response body.
            var response = client.GetAsync("api/values").GetAwaiter().GetResult();
            var content  = JsonConvert.DeserializeObject <string>(response.Content.ReadAsStringAsync().GetAwaiter().GetResult());

            // Assert - response was as expected.
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(content, responseData);
        }