Пример #1
0
        public async Task RetrievedFromCacheIfAvailable()
        {
            // Arrange
            var cachedSpecies = new PokemonSpecies("", true, new List <FlavorTextEntry>(), new Resource("", ""));
            var cache         = new Mock <ICache <PokemonSpecies> >();

            cache.Setup(c => c.TryGet(It.IsAny <string>()))
            .ReturnsAsync((true, cachedSpecies));
            var client = new Mock <IPokeApiClient>();

            var query = new PokemonQuery(cache.Object, client.Object);

            // Act
            var(ok, result) = await query.Get("mewtwo");

            // Assert
            Assert.True(ok);
            Assert.Equal(cachedSpecies, result);
            cache.Verify(c => c.TryGet("mewtwo"), Times.Once);
            client.Verify(c => c.GetSpecies(It.IsAny <string>()), Times.Never);
        }
Пример #2
0
        public async Task ValueSetInCacheOnceRetrieved()
        {
            // Arrange
            var cache = new Mock <ICache <PokemonSpecies> >();

            cache.Setup(c => c.TryGet(It.IsAny <string>()))
            .ReturnsAsync((false, null));
            var species = new PokemonSpecies("", true, new List <FlavorTextEntry>(), new Resource("", ""));
            var client  = new Mock <IPokeApiClient>();

            client.Setup(c => c.GetSpecies(It.IsAny <string>()))
            .ReturnsAsync(species);

            var query = new PokemonQuery(cache.Object, client.Object);

            // Act
            var(ok, result) = await query.Get("mewtwo");

            // Assert
            Assert.True(ok);
            Assert.Equal(species, result);
            cache.Verify(c => c.Set("mewtwo", species), Times.Once);
        }