public async Task Handle_BoardExists_ReturnsCardCreatedDtoWithCorrectPropValues() { var dbName = $"{nameof(AddCardToBoardCommandHandlerTests)}_{nameof(Handle_BoardExists_ReturnsCardCreatedDtoWithCorrectPropValues)}"; using var context = TestApplicationDbContext.Create(dbName); var boardFactory = new BoardFactory(); var board = boardFactory.Create("board-title"); var cancellationToken = new CancellationToken(); context.Boards.Add(board); await context.SaveChangesAsync(cancellationToken); var handler = new AddCardToBoardCommandHandler(context); var request = new AddCardToBoardCommand { BoardId = board.Id, Title = "card-title" }; var cardCreatedDto = await handler.Handle(request, cancellationToken); var card = await context.Cards.FirstOrDefaultAsync(c => c.BoardId == board.Id); Assert.NotNull(cardCreatedDto); Assert.Equal(card.Id, cardCreatedDto.CardId); Assert.Equal(card.BoardId, cardCreatedDto.BoardId); }
public async Task Handle_CardNotExists_ThrowsNotFoundApplicationException() { var dbName = $"{nameof(AddCardToBoardCommandHandlerTests)}_{nameof(Handle_CardNotExists_ThrowsNotFoundApplicationException)}"; using var context = TestApplicationDbContext.Create(dbName); var boardId = 1; var handler = new AddCardToBoardCommandHandler(context); var request = new AddCardToBoardCommand { BoardId = boardId, Title = "card-title" }; var cancellationToken = new CancellationToken(); Task <CardCreatedDto> action() => handler.Handle(request, cancellationToken); await Assert.ThrowsAsync <NotFoundApplicationException>(action); }