예제 #1
0
        public async Task CanRetrieveBasicInformationFromTestData()
        {
            // Arrange
            var testDataContents = await File.ReadAllTextAsync("mewtwo.json");

            var testData = JsonSerializer.Deserialize <PokemonSpecies>(
                testDataContents, new JsonSerializerOptions
            {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
            });

            var query = new Mock <IPokemonQuery>();

            query.Setup(q => q.Get(It.IsAny <string>()))
            .ReturnsAsync((true, testData));

            var retriever = new BasicPokemonInformationRetriever(query.Object);

            // Act
            var(ok, basicPokemonInfo) = await retriever.Get("mewtwo");

            // Assert
            Assert.True(ok);
            Assert.NotNull(basicPokemonInfo);
            Assert.Equal("mewtwo", basicPokemonInfo.Name);
            Assert.Equal("It was created by\na scientist after\nyears of horrific\fgene splicing and\nDNA engineering\nexperiments.", basicPokemonInfo.Description);
            Assert.Equal("rare", basicPokemonInfo.Habitat);
            Assert.True(basicPokemonInfo.IsLegendary);
        }
예제 #2
0
        public async Task <IActionResult> Get([FromRoute] string pokemonName)
        {
            pokemonName = pokemonName?.ToLower();
            var(ok, basicPokemonInfo) = await _basicRetriever.Get(pokemonName);

            if (!ok)
            {
                return(NotFound());
            }

            return(Ok(basicPokemonInfo));
        }
예제 #3
0
        public async Task IfNoFlavorTextEntryInEnglishThenEmptyDescription()
        {
            // Arrange
            var flavorTextEntries = new List <FlavorTextEntry>
            {
                new FlavorTextEntry("Un Pokémon conçu en réorganisant\nles gènes de Mew. On raconte qu’il\ns’agit du Pokémon le plus féroce.", new Resource("fr", "https://pokeapi.co/api/v2/language/5/"))
            };
            var testData = new PokemonSpecies("name", true, flavorTextEntries, new Resource("rare", "https://pokeapi.co/api/v2/pokemon-habitat/5/"));

            var query = new Mock <IPokemonQuery>();

            query.Setup(q => q.Get(It.IsAny <string>()))
            .ReturnsAsync((true, testData));

            var retriever = new BasicPokemonInformationRetriever(query.Object);

            // Act
            var(ok, basicPokemonInfo) = await retriever.Get("mewtwo");

            // Assert
            Assert.True(ok);
            Assert.NotNull(basicPokemonInfo);
            Assert.Equal(string.Empty, basicPokemonInfo.Description);
        }