Ejemplo n.º 1
0
        public void ShouldValidateWhenCommandIsValid()
        {
            var command = new LendCommand()
            {
                IdGame   = Guid.NewGuid(),
                IdFriend = Guid.NewGuid()
            };

            Assert.True(command.Valid());
        }
Ejemplo n.º 2
0
        public void ShouldLendGameWhenCommandIsValid()
        {
            var command = new LendCommand()
            {
                IdFriend = Guid.NewGuid(),
                IdGame   = Guid.NewGuid()
            };

            var result = _handler.Handle(command);

            Assert.NotEqual(null, result);
            Assert.True(_handler.Valid);
        }
Ejemplo n.º 3
0
        public ICommandResult Handle(LendCommand command)
        {
            var game   = _repository.Get(command.IdGame);
            var friend = _friendRepository.Get(command.IdFriend);

            var loan = new Loan(friend);

            game.Lend(loan);
            AddNotifications(game.Notifications);

            if (Invalid)
            {
                return(ErrorResult());
            }

            _repository.Update(game);
            return(new GameCommandResult(true, "Jogo emprestado com sucesso", game.Id));
        }
Ejemplo n.º 4
0
        public async Task <ICommandResult> Post([FromBody] LendCommand command)
        {
            var result = _handler.Handle(command);

            return(await Response(result));
        }