Exemplo n.º 1
0
        public async void ShouldReturnFactListWithMock()
        {
            var handlerMock = new Mock <HttpMessageHandler>();
            var httpClient  = this.GetMockHttpClient(handlerMock, this.factListText);

            using var animalFactsEndpoint = new AnimalFacts(httpClient);

            var facts = await animalFactsEndpoint.GetRandomFactsAsync(amount : 2);

            var factList = facts.ToList();

            Assert.Equal(2, factList.Count);

            for (int i = 0; i < 2; i++)
            {
                var fact = factList[i];
                Assert.NotNull(fact);
                Assert.Equal($"factId{i + 1}", fact.Id);
                Assert.Equal($"userId{i + 1}", fact.UserId);
                Assert.Equal($"Test Text: {i + 1}.", fact.Text);
                Assert.Equal(i + 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>());
        }
Exemplo n.º 2
0
        public async void ShouldReturnFactListLive(string animal, int amount)
        {
            using var animalFactsEndpoint = new AnimalFacts();

            var facts = await animalFactsEndpoint.GetRandomFactsAsync(animal : animal, amount : amount);

            var factList = facts.ToList();

            Assert.Equal(amount, factList.Count);

            for (int i = 0; i < amount; i++)
            {
                var fact = factList[i];
                Assert.NotNull(fact);
                Assert.NotNull(fact.Id);
                Assert.NotNull(fact.UserId);
                Assert.NotNull(fact.Text);
                Assert.Equal(animal, fact.Type);
            }
        }