public async Task GetPathsReturnsPathModelResults() { using var httpResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new ObjectContent(typeof(List <AppRegistrationModel>), appRegistrationModels, new JsonMediaTypeFormatter()), }; var fakeHttpRequestSender = A.Fake <IFakeHttpRequestSender>(); A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Returns(httpResponse); using var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender); var logger = A.Fake <ILogger <AppRegistryService> >(); using var httpClient = new HttpClient(fakeHttpMessageHandler) { BaseAddress = new Uri("http://SomePathBaseAddress"), }; using var memoryCache = new MemoryCache(Options.Create(new MemoryCacheOptions())); var appRegistryService = new AppRegistryService(logger, httpClient, memoryCache); var result = await appRegistryService.GetPaths(); Assert.Equal(appRegistrationModels, result); }
public async Task GetPathsReturnsPathModelResults() { var responseContent = new List <AppRegistrationModel> { new AppRegistrationModel { IsOnline = true, Path = "SomeFakePath", }, }; var httpResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new ObjectContent(typeof(List <AppRegistrationModel>), responseContent, new JsonMediaTypeFormatter()), }; var fakeHttpRequestSender = A.Fake <IFakeHttpRequestSender>(); A.CallTo(() => fakeHttpRequestSender.Send(A <HttpRequestMessage> .Ignored)).Returns(httpResponse); var fakeHttpMessageHandler = new FakeHttpMessageHandler(fakeHttpRequestSender); var logger = A.Fake <ILogger <AppRegistryService> >(); var httpClient = new HttpClient(fakeHttpMessageHandler) { BaseAddress = new Uri("http://SomePathBaseAddress"), }; var appRegistryService = new AppRegistryService(logger, httpClient); var result = await appRegistryService.GetPaths().ConfigureAwait(false); Assert.Equal(responseContent, result); httpResponse.Dispose(); httpClient.Dispose(); fakeHttpMessageHandler.Dispose(); }