Ejemplo n.º 1
0
        public async Task <IActionResult> Delete([FromQuery] long id)
        {
            var user = await GetCurrentUserAsync();

            if (user != null)
            {
                var command = new DeleteDeckCommand
                {
                    Deck = new DeckInputModel
                    {
                        Id     = id,
                        UserId = user.Id
                    }
                };

                var result = await _mediator.Send(command);

                if (result.IsSuccessful)
                {
                    return(Ok(new { id = result.Data }));
                }

                return(BadRequest(result.Errors));
            }

            return(BadRequest());
        }
Ejemplo n.º 2
0
        public async Task Given_A_Deck_If_User_Is_Not_Owner_Should_Return_Errors()
        {
            // Arrange
            var deck = new DeckInputModel
            {
                MainDeck = new List <CardInputModel>()
            };

            var command = new DeleteDeckCommand {
                Deck = deck
            };

            _userService.IsUserDeckOwner(Arg.Any <string>(), Arg.Any <long>()).Returns(false);

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

            // Assert
            result.Errors.Should().NotBeEmpty();
        }
Ejemplo n.º 3
0
        public async Task Given_A_Deck_If_User_Is_Not_Owner_Should_Not_Invoke_DeleteDeckByIdAndUserId()
        {
            // Arrange
            var deck = new DeckInputModel
            {
                MainDeck = new List <CardInputModel>()
            };

            var command = new DeleteDeckCommand {
                Deck = deck
            };

            _userService.IsUserDeckOwner(Arg.Any <string>(), Arg.Any <long>()).Returns(false);

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

            // Assert
            await _deckService.DidNotReceive().DeleteDeckByIdAndUserId(Arg.Any <string>(), Arg.Any <long>());
        }