public async Task ApiDataProcessorServiceGetReturnsNullForNoData() { // arrange ApiSummaryModel?expectedResult = null; A.CallTo(() => fakeApiService.GetAsync(A <HttpClient> .Ignored, A <Uri> .Ignored, A <string> .Ignored)).Returns(string.Empty); var apiDataProcessorService = new ApiDataProcessorService(fakeApiService); // act var result = await apiDataProcessorService.GetAsync <ApiSummaryModel>(A.Fake <HttpClient>(), new Uri("https://somewhere.com")).ConfigureAwait(false); // assert A.CallTo(() => fakeApiService.GetAsync(A <HttpClient> .Ignored, A <Uri> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly(); A.Equals(result, expectedResult); }
public async Task ApiDataProcessorServiceGetReturnsSuccess() { // arrange var expectedResult = new ApiSummaryModel { Url = new Uri("https://somewhere.com"), Title = "a-name", Published = DateTime.Now, CreatedDate = DateTime.Now, }; var jsonResponse = JsonConvert.SerializeObject(expectedResult); A.CallTo(() => fakeApiService.GetAsync(A <HttpClient> .Ignored, A <Uri> .Ignored, A <string> .Ignored)).Returns(jsonResponse); var apiDataProcessorService = new ApiDataProcessorService(fakeApiService); // act var result = await apiDataProcessorService.GetAsync <ApiSummaryModel>(A.Fake <HttpClient>(), new Uri("https://somewhere.com")).ConfigureAwait(false); // assert A.CallTo(() => fakeApiService.GetAsync(A <HttpClient> .Ignored, A <Uri> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly(); A.Equals(result, expectedResult); }
public async Task ApiDataProcessorServiceGetReturnsExceptionForNoHttpClient() { // arrange var apiDataProcessorService = new ApiDataProcessorService(fakeApiService); // act var exceptionResult = await Assert.ThrowsAsync <ArgumentNullException>(async() => await apiDataProcessorService.GetAsync <ApiSummaryModel>(null, new Uri("https://somewhere.com")).ConfigureAwait(false)).ConfigureAwait(false); // assert A.CallTo(() => fakeApiService.GetAsync(A <HttpClient> .Ignored, A <Uri> .Ignored, A <string> .Ignored)).MustNotHaveHappened(); Assert.Equal("Value cannot be null. (Parameter 'httpClient')", exceptionResult.Message); }