예제 #1
0
        public async Task ThenOffersAreReturned()
        {
            var options = new Mock <IOptions <HttpOfferReaderOptions> >();

            options.Setup(_ => _.Value).Returns(new HttpOfferReaderOptions
            {
                Url = "https://localhost/foobar"
            });

            var httpClientFactory  = new Mock <IHttpClientFactory>();
            var httpMessageHandler = new MockHttpMessageHandler();
            var httpClient         = new HttpClient(httpMessageHandler);

            httpClientFactory.Setup(_ => _.CreateClient(It.IsAny <string>()))
            .Returns(httpClient);

            var sut = new HttpOfferReader
                      (
                httpClientFactory.Object,
                options.Object
                      );

            var results = await sut.ReadAsync();

            results.Should().BeEquivalentTo(MockOffers.Get());
        }
예제 #2
0
        protected override Task <HttpResponseMessage> SendAsync
        (
            HttpRequestMessage request,
            CancellationToken cancellationToken
        )
        {
            var responseBody       = MockOffers.Get();
            var responseBodyText   = JsonSerializer.Serialize(responseBody);
            var responseBodyBytes  = Encoding.UTF8.GetBytes(responseBodyText);
            var responseBodyStream = new MemoryStream(responseBodyBytes);
            var response           = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StreamContent(responseBodyStream)
            };

            return(Task.FromResult(response));
        }