public async void GivenQueryWhenBoardExistsThenBoardColumnCollectionReturned()
        {
            // Arrange
            var boardEntity = new BoardEntity {Slug = "board-name"};
            SetupQueryHandler(new List<BoardEntity>
            {
                boardEntity
            },
            new List<BoardColumnEntity>
            {
                new BoardColumnEntity
                {
                    BoardEntity = boardEntity
                }
            });

            var query = new SearchBoardColumnsQuery
            {
                BoardSlug = "board-name"
            };

            // Act
            var boardColumnCollection = await handler.HandleAsync(query);

            // Assert
            Assert.NotNull(boardColumnCollection);
        }
        public async void GivenQueryWhenBoardExistsThenEachItemMapped()
        {
            // Arrange
            var boardEntity = new BoardEntity { Slug = "board-name" };
            SetupQueryHandler(new List<BoardEntity>
            {
                boardEntity
            },
            new List<BoardColumnEntity>
            {
                new BoardColumnEntity
                {
                    BoardEntity = boardEntity
                }
            });

            var query = new SearchBoardColumnsQuery
            {
                BoardSlug = "board-name"
            };

            // Act
            await handler.HandleAsync(query);

            // Assert
            mockMappingService.Verify(x => x.Map<BoardColumn>(It.IsAny<BoardColumnEntity>()), Times.Once);
        }
        public async void GivenCommandWhenTaskExistsThenAttachedSaveChangesCalled()
        {
            // Arrange
            var boardEntity = new BoardEntity { Slug = "board-name" };
            var boardColumnEntity = new BoardColumnEntity
            {
                Slug = "board-column-name",
                BoardEntity = boardEntity
            };

            SetupCommandHandler(new List<BoardEntity> { boardEntity }, new List<BoardColumnEntity> { boardColumnEntity });

            var command = new UpdateBoardColumnCommand
            {
                BoardSlug = "board-name",
                BoardColumnSlug = "board-column-name",
                BoardColumn = new BoardColumn()
            };

            // Act
            await handler.HandleAsync(command);

            // Assert
            mockDataContext.Verify(x => x.SetModified(boardColumnEntity), Times.Once);
            mockDataContext.Verify(x => x.SaveChangesAsync(), Times.Once);
        }
        public async void GivenCommandWhenBoardColumnDoesNotExistThenThrowBoardColumnNotFoundException()
        {
            // Arrange
            var boardEntity = new BoardEntity { Slug = "board-name" };

            SetupCommandHandler(new List<BoardEntity> { boardEntity }, new List<BoardColumnEntity> ());

            var command = new UpdateBoardColumnCommand
            {
                BoardSlug = "board-name",
                BoardColumnSlug = "board-column-name",
                BoardColumn = new BoardColumn()
            };

            // Act & Assert
            await Assert.ThrowsAsync<BoardColumnNotFoundException>(() => handler.HandleAsync(command));
        }
        public async void GivenCommandWhenBoardColumnHasTasksThenBoardColumnNotEmptyExceptionThrown()
        {
            // Arrange
            var boardEntity = new BoardEntity {Slug = "board-name"};
            var boardColumnEntity = new BoardColumnEntity { Id = 1, Slug = "board-column-name", BoardEntity = boardEntity };
            SetupHandler(new List<BoardEntity> { boardEntity }, new List<BoardColumnEntity>
            {
                boardColumnEntity
            }, new List<BoardTaskEntity>
            {
                new BoardTaskEntity {BoardColumnEntity = boardColumnEntity}
            });

            var command = new DeleteBoardColumnCommand
            {
                BoardSlug = "board-name",
                BoardColumnSlug = "board-column-name"
            };

            // Act & Assert
            await Assert.ThrowsAsync<BoardColumnNotEmptyException>(() => handler.HandleAsync(command));
        }
        public async void GivenABoardColumnWhenSlugAlreadyExistsThenThrowCreateBoardColumnCommandSlugExistsException()
        {
            // Arrange
            var boardEntity = new BoardEntity { Slug = "test" };
            SetupCommandHandler(new List<BoardColumnEntity>
            {
                new BoardColumnEntity
                {
                    Id = 1,
                    Name = "test",
                    Slug = "test",
                    BoardEntity = boardEntity
                }
            }, new List<BoardEntity>
            {
                boardEntity
            });

            var command = new CreateBoardColumnCommand
            {
                BoardSlug = "test",
                BoardColumn = new BoardColumn
                {
                    Slug = "test"
                }
            };

            mockMappingService.Setup(x => x.Map<BoardColumnEntity>(It.IsAny<BoardColumn>()))
                .Returns(new BoardColumnEntity
                {
                    Name = "test",
                    Slug = "test"
                });

            mockSlugService.Setup(x => x.Slugify(It.IsAny<string>())).Returns("test");

            // Act & Assert
            await Assert.ThrowsAsync<CreateBoardColumnCommandSlugExistsException>(() => handler.HandleAsync(command));
        }
        public async void GivenCommandWhenBoardColumnExisttsAndIsEmptyThenBoardColumnRemovedAndSaveChangesCalled()
        {
            // Arrange
            var boardEntity = new BoardEntity { Slug = "board-name" };
            var boardColumnEntity = new BoardColumnEntity { Id = 1, Slug = "board-column-name", BoardEntity = boardEntity };
            SetupHandler(new List<BoardEntity> { boardEntity }, new List<BoardColumnEntity>
            {
                boardColumnEntity
            }, new List<BoardTaskEntity>());

            var command = new DeleteBoardColumnCommand
            {
                BoardSlug = "board-name",
                BoardColumnSlug = "board-column-name"
            };

            // Act
            await handler.HandleAsync(command);

            // Assert
            mockDataContext.Verify(x => x.SaveChangesAsync(), Times.Once());
            mockDataContext.Verify(x => x.Delete(boardColumnEntity), Times.Once());
        }
        public async void GivenCommandWhenTaskExistsThenMappedBackToDto()
        {
            // Arrange
            var boardEntity = new BoardEntity { Slug = "board-name" };
            var boardColumnEntity = new BoardColumnEntity
            {
                Slug = "board-column-name",
                BoardEntity = boardEntity
            };

            SetupCommandHandler(new List<BoardEntity> { boardEntity }, new List<BoardColumnEntity> { boardColumnEntity });

            var command = new UpdateBoardColumnCommand
            {
                BoardSlug = "board-name",
                BoardColumnSlug = "board-column-name",
                BoardColumn = new BoardColumn()
            };

            // Act
            await handler.HandleAsync(command);

            // Assert
            mockMappingService.Verify(x => x.Map<BoardColumn>(It.IsAny<BoardColumnEntity>()), Times.Once);
        }