public async Task Given_An_Valid_Deck_Create_Command_Should_Be_Successful()
        {
            // Arrange
            var deck = new DeckInputModel
            {
                Name     = "deck tester",
                UserId   = Guid.NewGuid().ToString(),
                MainDeck = new List <CardInputModel>()
            };

            _fixture.RepeatCount = 40;

            deck.MainDeck =
                _fixture
                .Build <CardInputModel>()
                .With(c => c.BaseType, "monster")
                .Without(c => c.Types)
                .CreateMany()
                .ToList();


            var command = new CreateDeckCommand {
                Deck = deck
            };

            _deckService.Add(Arg.Any <DeckModel>()).Returns(new Deck {
                Id = 23424                                                      /*new deck id*/
            });

            // Act
            var result = await _sut.Handle(command, CancellationToken.None);

            // Assert
            result.IsSuccessful.Should().BeTrue();
        }
        public async Task <CommandResult> Handle(UploadYgoProDeckCommand request, CancellationToken cancellationToken)
        {
            var commandResult = new CommandResult();

            var commandValidationResult = _commandValidator.Validate(request);

            if (commandValidationResult.IsValid)
            {
                var ygoProDeck = YgoProDeckHelpers.MapToYgoProDeck(request.Deck);
                ygoProDeck.UserId = request.UserId;
                ygoProDeck.Name   = request.Name;

                var ygoProDeckValidationResult = _ygoProDeckValidator.Validate(ygoProDeck);

                if (ygoProDeckValidationResult.IsValid)
                {
                    var result = await _deckService.Add(ygoProDeck);

                    commandResult.IsSuccessful = true;
                    commandResult.Data         = result.Id;
                }
                else
                {
                    commandResult.Errors = ygoProDeckValidationResult.Errors.Select(err => err.ErrorMessage).ToList();
                }
            }
            else
            {
                commandResult.Errors = commandValidationResult.Errors.Select(err => err.ErrorMessage).ToList();
            }

            return(commandResult);
        }
Ejemplo n.º 3
0
        Given_An_Valid_YgoProDeck__Deck_Validation_Is_Successful_UploadYgoProDeck_Command_Should_Be_Successful()
        {
            // Arrange
            var deck = new StringBuilder();

            deck.Append("#created by ...");
            deck.AppendLine("#main");
            deck.AppendLine("16261341");
            deck.AppendLine("16261341");
            deck.AppendLine("16261341");
            deck.AppendLine("16261341");
            deck.AppendLine("#extra");
            deck.AppendLine("!side");

            var command = new UploadYgoProDeckCommand
            {
                UserId = Guid.NewGuid().ToString(),
                Name   = "Test deck",
                Deck   = deck.ToString()
            };

            commandValidator.Validate(Arg.Any <UploadYgoProDeckCommand>()).Returns(new ValidationResult());
            _ygoProDeckValidator.Validate(Arg.Any <YgoProDeck>()).Returns(new ValidationResult());

            _deckService.Add(Arg.Any <YgoProDeck>()).Returns(new Deck {
                Id = 3242342
            });

            // Act
            var result = await _sut.Handle(command, CancellationToken.None);

            // Assert
            result.IsSuccessful.Should().BeTrue();
        }
Ejemplo n.º 4
0
        public async Task <CommandResult> Handle(CreateDeckCommand request, CancellationToken cancellationToken)
        {
            var commandResult = new CommandResult();

            var validationResult = await _validator.ValidateAsync(request.Deck, ruleSet : $"default,{DeckValidator.InsertDeckRuleSet}", cancellationToken : cancellationToken);

            if (validationResult.IsValid)
            {
                var deckModel = _mapper.Map <DeckModel>(request.Deck);

                var result = await _deckService.Add(deckModel);

                commandResult.Data         = new { deckId = result.Id };
                commandResult.IsSuccessful = true;
            }
            else
            {
                commandResult.Errors = validationResult.Errors.Select(err => err.ErrorMessage).ToList();
            }

            return(commandResult);
        }