public async Task Given_A_Valid_Card_ISuccessful_Should_Be_True()
        {
            // Arrange
            var command = new AddCardCommand
            {
                Card = new CardInputModel
                {
                    CardType    = YgoCardType.Spell,
                    Name        = "Monster Reborn",
                    Description = "Special Summon a monster from any graveyard",
                    ImageUrl    = new Uri("http://cardimageurl.com/card/image.jpg")
                }
            };

            _cardService.Add(Arg.Any <CardModel>()).Returns(new Card {
                Id = 23424
            });
            _settings.Value.Returns(new AppSettings
            {
                CardImageFolderPath = "C:/cards/images"
            });


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

            // Assert
            result.IsSuccessful.Should().BeTrue();
        }
        public async Task Given_A_Valid_Card_With_An_ImageUrl_Should_Invoke_DownloadImageCommand()
        {
            // Arrange
            var command = new AddCardCommand
            {
                Card = new CardInputModel
                {
                    CardType    = YgoCardType.Spell,
                    Name        = "Monster Reborn",
                    Description = "Special Summon a monster from any graveyard",
                    ImageUrl    = new Uri("http://cardimageurl.com/card/image.jpg")
                }
            };

            _cardService.Add(Arg.Any <CardModel>()).Returns(new Card {
                Id = 23424
            });
            _settings.Value.Returns(new AppSettings
            {
                CardImageFolderPath = "C:/cards/images"
            });

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

            // Assert
            await _mediator.Received(1).Send(Arg.Any <DownloadImageCommand>(), Arg.Any <CancellationToken>());
        }
        public async Task Given_An_Invalid_Card_AddCardCommand_Should_Return_A_List_Of_Errors()
        {
            // Arrange
            var command = new AddCardCommand();

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

            // Assert
            result.Errors.Should().NotBeEmpty();
        }
        public async Task Given_An_Invalid_Card_AddCardCommand_Should_Not_Be_Successful()
        {
            // Arrange
            var command = new AddCardCommand();

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

            // Assert
            result.IsSuccessful.Should().BeFalse();
        }
        public async Task <AddCardCommand> MapToAddCommand(YugiohCard yugiohCard)
        {
            ICollection <Category> categories = await _categoryService.AllCategories();

            ICollection <SubCategory> subCategories = await _subCategoryService.AllSubCategories();

            var command = new AddCardCommand
            {
                Card = await MapToCardInputModel(yugiohCard, new CardInputModel(), categories, subCategories)
            };

            return(command);
        }
示例#6
0
        public async Task <IActionResult> Add(
            [FromServices] IMediator mediator,
            [FromBody] BusinessCardDto cardDto)
        {
            int.TryParse(User.Identity.Name, out var userId);
            cardDto.ProfileId = userId;

            var command = new AddCardCommand(cardDto);

            var data = await mediator.Send(command);

            return(new JsonResult(data.Card));
        }
        public async Task Given_An_Invalid_Card_And_Validation_Fails_Should_Return_Error_List()
        {
            // Arrange
            var command = new AddCardCommand
            {
                Card = new CardInputModel()
            };

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

            // Assert
            result.Errors.Should().NotBeEmpty();
        }
        public async Task Given_A_Valid_Card_And_AddCardCommand_Fails_Should_Return_Error_List()
        {
            // Arrange
            var command = new AddCardCommand
            {
                Card = new CardInputModel
                {
                    CardType    = YgoCardType.Spell,
                    Name        = "Monster Reborn",
                    Description = "Special Summon a monster from any graveyard"
                }
            };

            _cardService.Add(Arg.Any <CardModel>()).Returns((Card)null);

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

            // Assert
            result.Errors.Should().NotBeEmpty();
        }
        public async Task <Card> Add(AddCardCommand command)
        {
            var createdUri = await _restClient.Post($"{_config.ApiUrl}/api/Cards", command);

            return(await _restClient.Get <Card>(createdUri.AbsoluteUri));
        }
示例#10
0
 public async Task <IActionResult> Add([FromBody] AddCardCommand command) => await HandleCommand(command);