Ejemplo n.º 1
0
        public async Task Handle_BoardIdExists_ReturnsCardsInOrder()
        {
            var dbName = $"{nameof(GetBoardQueryHandlerTests)}_{nameof(Handle_BoardIdExists_ReturnsCardsInOrder)}";

            using var context = TestApplicationDbContext.Create(dbName);
            var cancellationToken = new CancellationToken();

            var boardFactory = new BoardFactory();
            var board        = boardFactory.Create("board-title");
            var card1        = Card.Create("card1-title", 1);
            var card2        = Card.Create("card2-title", 0);

            board.AddCard(card1);
            board.AddCard(card2);
            context.Boards.Add(board);
            await context.SaveChangesAsync(cancellationToken);

            var orderedCardIds = await context.Cards
                                 .Where(c => c.BoardId == board.Id)
                                 .OrderBy(c => c.Order)
                                 .Select(c => c.Id)
                                 .ToListAsync(cancellationToken);

            var handler = new GetBoardQueryHandler(context);
            var request = new GetBoardQuery(1);

            var dto = await handler.Handle(request, cancellationToken);

            var dtoCardIds = dto.Cards.Select(c => c.Id).ToList();

            Assert.Equal(orderedCardIds, dtoCardIds);
        }
Ejemplo n.º 2
0
        public async Task Handle_BoardIdExists_ReturnDto()
        {
            var dbName = $"{nameof(GetBoardQueryHandlerTests)}_{nameof(Handle_BoardIdExists_ReturnDto)}";

            using var context = TestApplicationDbContext.Create(dbName);
            var cancellationToken = new CancellationToken();

            var boardFactory = new BoardFactory();
            var board        = boardFactory.Create("board-title");
            var card         = Card.Create("card-title");
            var activity     = Activity.Create("activity-title");

            board.AddCard(card);
            card.AddActivity(activity);
            context.Boards.Add(board);
            await context.SaveChangesAsync(cancellationToken);

            var handler = new GetBoardQueryHandler(context);
            var request = new GetBoardQuery(1);

            var dto = await handler.Handle(request, cancellationToken);

            var dtoCard     = dto.Cards.FirstOrDefault();
            var dtoActivity = dtoCard.Activities.FirstOrDefault();

            Assert.NotNull(dto);
            Assert.Equal(1, dto.Id);
            Assert.NotNull(dto.Cards);
            Assert.Single(dto.Cards);
            Assert.Equal(1, dtoCard.Id);
            Assert.NotNull(dtoCard.Activities);
            Assert.Single(dtoCard.Activities);
            Assert.Equal(1, dtoActivity.Id);
        }
Ejemplo n.º 3
0
        public async Task Handle_BoardIdExists_ReturnsBoardUserType()
        {
            var dbName = $"{nameof(GetBoardQueryHandlerTests)}_{nameof(Handle_BoardIdExists_ReturnsBoardUserType)}";

            using var context = TestApplicationDbContext.Create(dbName);
            var cancellationToken = new CancellationToken();

            var boardFactory     = new BoardFactory();
            var boardUserFactory = new BoardUserFactory();
            var userId           = "user-id";
            var board            = boardFactory.Create("board-title");
            var boardUser        = boardUserFactory.CreateOwner(1, userId);
            var boardUserType    = boardUser.Type.ToString().ToLower();

            context.Boards.Add(board);
            context.BoardUsers.Add(boardUser);
            await context.SaveChangesAsync(cancellationToken);

            var handler = new GetBoardQueryHandler(context);
            var request = new GetBoardQuery(1);

            var dto = await handler.Handle(request, cancellationToken);

            Assert.Equal(boardUserType, dto.BoardUserType);
        }
        public void Handle_OnExistingBoard_ReturnsBoardViewModel()
        {
            var board = new Board
            {
                Id          = 1,
                Name        = "Board May 2020",
                NoteCounter = 123,
                NotePrefix  = "BM2020"
            };

            var boardRepositoryMock = new Mock <IBoardRepository>();

            boardRepositoryMock
            .Setup(x => x.Get(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(board));

            var sut = new GetBoardQueryHandler(boardRepositoryMock.Object);

            var result = sut.Handle(ExampleQuery, new CancellationToken()).GetAwaiter().GetResult();

            result.Should().NotBeNull();
            result.Board.Should().NotBeNull();
            result.Board.Id.Should().Be(1);
            result.Board.Name.Should().Be("Board May 2020");
        }
Ejemplo n.º 5
0
        public async Task Handle_BoardIdNotExists_ThrowsNotFoundApplicationException()
        {
            var dbName = $"{nameof(GetBoardQueryHandlerTests)}_{nameof(Handle_BoardIdNotExists_ThrowsNotFoundApplicationException)}";

            using var context = TestApplicationDbContext.Create(dbName);
            var cancellationToken = new CancellationToken();
            var handler           = new GetBoardQueryHandler(context);
            var request           = new GetBoardQuery(1);

            Task <GetBoardDto> action() => handler.Handle(request, cancellationToken);

            await Assert.ThrowsAsync <NotFoundApplicationException>(action);
        }
        public void Handle_OnNotExistingBoard_ThrowsNotFoundException()
        {
            var boardRepositoryMock = new Mock <IBoardRepository>();

            boardRepositoryMock
            .Setup(x => x.Get(It.IsAny <int>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <Board>(null));

            var sut = new GetBoardQueryHandler(boardRepositoryMock.Object);

            Action act = () => sut.Handle(ExampleQuery, new CancellationToken()).GetAwaiter().GetResult();

            act.Should().ThrowExactly <NotFoundException>();
        }