static async Task Main(string[] args) { var apiService = new ExternalAPIService(); var formattedJokeService = new FormattedJokeService(apiService); Console.WriteLine(await formattedJokeService.GetFormattedJokeAsync()); }
public async Task TestPatientExistsIdInvalid() { // Arrange var mockHandler = new Mock <HttpMessageHandler>(MockBehavior.Strict); mockHandler .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.NotFound }) .Verifiable(); var httpClient = new HttpClient(mockHandler.Object) { BaseAddress = new Uri("http://demographics_api:80") }; var service = new ExternalAPIService(httpClient); var expectedUri = new Uri("http://demographics_api:80/api/Patient/Exists/1"); // Act var result = await service.PatientExists(1); // Assert Assert.False(result); mockHandler .Protected() .Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get && req.RequestUri == expectedUri ), ItExpr.IsAny <CancellationToken>() ); }
public ExternalAPIServiceTests() { _externalAPIService = new ExternalAPIService(base.Settings); }