public async void ShouldReturnSingleFactLive(string animal) { using var animalFactsEndpoint = new AnimalFacts(); var fact = await animalFactsEndpoint.GetRandomFactAsync(animal : animal); Assert.NotNull(fact); Assert.NotNull(fact.Id); Assert.NotNull(fact.UserId); Assert.NotNull(fact.Text); Assert.Equal(animal, fact.Type); }
public async void ShouldReturnSingleFactWithMock() { var handlerMock = new Mock <HttpMessageHandler>(); var httpClient = this.GetMockHttpClient(handlerMock, this.factText); using var animalFactsEndpoint = new AnimalFacts(httpClient); var fact = await animalFactsEndpoint.GetRandomFactAsync(); Assert.NotNull(fact); Assert.Equal("factId", fact.Id); Assert.Equal("userId", fact.UserId); Assert.Equal("Test Text.", fact.Text); Assert.Equal(1, fact.Version); Assert.False(fact.Used); Assert.False(fact.IsDeleted); handlerMock.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get), ItExpr.IsAny <CancellationToken>()); }