Beispiel #1
0
        public void MustBeInvalidGameByDescriptionError()
        {
            //Given
            var game = new InsertGameCommand("Super Bomberman 4", string.Empty);

            //Then
            game.IsValid().Should().BeFalse();
        }
Beispiel #2
0
        public void MustBeInvalidGameByNameError()
        {
            //Given
            var game = new InsertGameCommand(string.Empty, "Joguinho danado de bom.");

            //Then
            game.IsValid().Should().BeFalse();
        }
Beispiel #3
0
        public void MustBeValidGame()
        {
            //Given
            var game = new InsertGameCommand("Super Bomberman 4", "Joguinho danado de bom.");

            //Then
            game.IsValid().Should().BeTrue();
        }
Beispiel #4
0
        public void MustGameDescriptionExceedMaxLength()
        {
            //Given
            string description = string.Empty;

            for (int i = 0; i < 256; i++)
            {
                description += "a";
            }

            //When
            var game = new InsertGameCommand("Super Bomberman 4", description);

            //Then
            game.IsValid().Should().BeFalse();
            Assert.Contains("A descrição do jogo deve conter no maximo 255 caracteres.", game.ValidationResult.Errors.Select(x => x.ErrorMessage));
        }
Beispiel #5
0
        public void MustGameNameExceedMaxLength()
        {
            //Given
            string name = string.Empty;

            for (int i = 0; i < 102; i++)
            {
                name += "a";
            }

            //When
            var game = new InsertGameCommand(name, "Um jogo muito bom");

            //Then
            game.IsValid().Should().BeFalse();
            Assert.Contains("O nome do jogo deve conter entre 2 a 100 caracteres.", game.ValidationResult.Errors.Select(x => x.ErrorMessage));
        }
Beispiel #6
0
        public Task <bool> Handle(InsertGameCommand command, CancellationToken cancellationToken)
        {
            if (!command.IsValid())
            {
                NotifyValidationErrors(command);
                return(Task.FromResult(false));
            }

            var game = new Game(command.Name, command.Description);

            gameWriteRepository.Insert(game);

            if (Commit())
            {
                command.SetId(game.Id);
                mediator.RaiseEventAsync(new InsertGameEvent(game.Name, game.Description));
            }

            return(Task.FromResult(true));
        }