Ejemplo n.º 1
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
        }
Ejemplo n.º 2
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
        }
Ejemplo n.º 3
0
        public async Task Execute(string userId, int pokemonId)
        {
            User user = await _userFinder.Execute(new UserId(userId));

            await _pokemonFavoriteCreator.Execute(user, new PokemonFavorite(new PokemonId(pokemonId)));

            _publisher.Publish(new DomainEvent(new MessageEvent(pokemonId.ToString())));
        }
        public async Task Execute(string userId, int pokemonId)
        {
            User user = await _userFinder.Execute(new UserId(userId));

            await _pokemonFavoriteCreator.Execute(user, new PokemonFavorite(new PokemonId(pokemonId)));
        }