Esempio n. 1
0
        public void ShouldThrowAnExceptionWhenPokemonFavoriteAlreadyExists()
        {
            #region Given

            PokemonId       pokemonId       = PokemonIdMother.PokemonId();
            PokemonFavorite pokemonFavorite = new PokemonFavorite(pokemonId);
            string          userId          = UserIdMother.Id();
            string          expectedMessage = $"The pokemon with Id '{pokemonId.Id}' already exists in user favorites list";
            User            user            = UserMother.UserWithFavorites(userId, pokemonId.Id);

            var userRepository = new Mock <UserRepository>();

            userRepository
            .Setup(r => r.Find(It.IsAny <UserId>()))
            .ReturnsAsync(UserMother.UserWithFavorites(userId, pokemonId.Id));

            userRepository
            .Setup(r => r.SaveFavorites(It.IsAny <User>()));

            PokemonFavoriteCreator pokemonFavoriteCreator = new PokemonFavoriteCreator(userRepository.Object);

            #endregion

            #region When
            var exception = Record.ExceptionAsync(async() => await pokemonFavoriteCreator.Execute(user, pokemonFavorite));

            #endregion

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

            #endregion
        }
Esempio n. 2
0
 private void GuardPokemonFavoriteExistsInUser(PokemonFavorite favorite)
 {
     if (Favorites.Any(pokemonFavorite => pokemonFavorite.PokemonId.Id == favorite.PokemonId.Id))
     {
         throw new PokemonFavoriteExistsException(favorite);
     }
 }
Esempio n. 3
0
        public async Task ShouldCreatePokemonFavorite()
        {
            #region Given

            PokemonId       pokemonId       = PokemonIdMother.PokemonId();
            PokemonFavorite pokemonFavorite = new PokemonFavorite(pokemonId);
            string          userId          = UserIdMother.Id();
            User            user            = new User(new UserId(userId));
            var             userRepository  = new Mock <UserRepository>();

            userRepository
            .Setup(r => r.SaveFavorites(It.IsAny <User>()));

            PokemonFavoriteCreator pokemonFavoriteCreator = new PokemonFavoriteCreator(userRepository.Object);

            #endregion

            #region When

            await pokemonFavoriteCreator.Execute(user, pokemonFavorite);

            #endregion

            #region Then

            userRepository.Verify(r => r.SaveFavorites(It.IsAny <User>()), Times.Once());

            #endregion
        }
Esempio n. 4
0
        public void AddFavorite(PokemonFavorite favorite)
        {
            GuardPokemonFavoriteExistsInUser(favorite);

            Favorites.Add(favorite);
        }
Esempio n. 5
0
 public void AddPokemonFavorite(PokemonFavorite favorite)
 {
     PokemonFavorites.AddFavorite(favorite);
 }
Esempio n. 6
0
 public PokemonFavoriteExistsException(PokemonFavorite pokemonName)
 {
     _pokemonFavorite = pokemonName;
 }
 public async Task Execute(User user, PokemonFavorite pokemonFavorite)
 {
     user.AddPokemonFavorite(pokemonFavorite);
     await _userRepository.SaveFavorites(user);
 }