Пример #1
0
        public async Task Given_A_Good_Url_Should_Return_Invoke_CreateClient_Once()
        {
            // Arrange
            const string url = "http://good.uri";
            var          fakeHttpMessageHandler = new FakeHttpMessageHandler(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent("response", Encoding.UTF8, "application/json")
            });
            var fakeHttpClient = new HttpClient(fakeHttpMessageHandler);

            _httpClientFactory.CreateClient().Returns(fakeHttpClient);

            // Act
            await _sut.GetString(url);

            // Assert
            _httpClientFactory.Received(1).CreateClient();
        }
Пример #2
0
        public async Task Given_A_Good_Url_Should_Return_String_Response()
        {
            // Arrange
            const string url      = "http://good.uri";
            const string expected = "response";
            var          fakeHttpMessageHandler = new FakeHttpMessageHandler(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent("response", Encoding.UTF8, "application/json")
            });
            var fakeHttpClient = new HttpClient(fakeHttpMessageHandler);

            _httpClientFactory.CreateClient().Returns(fakeHttpClient);

            // Act
            var result = await _sut.GetString(url);

            // Assert
            result.Should().BeEquivalentTo(expected);
        }