コード例 #1
0
        public async Task PokemonFinder_ReturnsPokemon()
        {
            #region Arrange
            PokemonId pokemonId         = new PokemonId(PokemonIdMother.Id());
            var       pokemonRepository = new Mock <PokemonRepository>();

            pokemonRepository
            .Setup(r => r.Find(It.IsAny <PokemonId>()))
            .ReturnsAsync(PokemonMother.Pokemon());

            pokemonRepository
            .Setup(r => r.Exists(It.IsAny <PokemonId>()))
            .ReturnsAsync(true);

            var pokemonFinder = new PokemonFinder(pokemonRepository.Object);

            #endregion

            #region Act
            Pokemon pokemon = await pokemonFinder.Execute(pokemonId);

            #endregion

            #region Assert
            Assert.Equal(pokemon.PokemonId.Id, PokemonMother.Pokemon().PokemonId.Id);
            Assert.Equal(pokemon.PokemonName.Name, PokemonMother.Pokemon().PokemonName.Name);
            Assert.Equal(pokemon.PokemonTypes.Types.Select(s => s.Type).ToArray(), PokemonMother.Pokemon().PokemonTypes.Types.Select(s => s.Type).ToArray());

            #endregion
        }
コード例 #2
0
        public void PokemonFinder_ReturnsException()
        {
            #region Arrange
            PokemonId pokemonId         = new PokemonId(PokemonIdMother.Id());
            var       pokemonRepository = new Mock <PokemonRepository>();
            string    expectedMessage   = $"Pokemon with Id '{pokemonId.Id}' does not exist";

            pokemonRepository
            .Setup(r => r.Find(It.IsAny <PokemonId>()))
            .ReturnsAsync(PokemonMother.Pokemon());

            var pokemonFinder = new PokemonFinder(pokemonRepository.Object);

            #endregion

            #region Act
            var exception = Record.ExceptionAsync(async() => await pokemonFinder.Execute(pokemonId));

            #endregion

            #region Assert
            Assert.Equal(expectedMessage, exception.Result.Message);

            #endregion
        }
コード例 #3
0
        public async Task Search_Found_ReturnsPokemonDetail()
        {
            #region Arrange

            PokeApiPokemonRepository pokemonRepository = new PokeApiPokemonRepository();
            PokemonId pokemonId = new PokemonId(PokemonIdMother.Id());

            #endregion

            #region Act
            Pokemon pokemon = await pokemonRepository.Find(pokemonId);

            #endregion

            #region Assert
            var typesArray = pokemon.PokemonTypes.Types.Select(s => s.Type).ToArray();

            Assert.Equal(pokemon.PokemonId.Id, PokemonMother.Pokemon().PokemonId.Id);
            Assert.Equal(pokemon.PokemonName.Name, PokemonMother.Pokemon().PokemonName.Name);
            Assert.Equal(typesArray, PokemonMother.Pokemon().PokemonTypes.Types.Select(s => s.Type).ToArray(), StringComparer.InvariantCultureIgnoreCase);

            #endregion
        }