コード例 #1
0
        public void GiveAObjWhenIsABoardColumnThenReturnsTrue()
        {
            // Arrange
            SetupState();
            var boardColumn = new BoardColumn();

            // Act
            var isAppliable = state.IsAppliable(boardColumn);

            // Assert
            Assert.True(isAppliable);
        }
コード例 #2
0
        public void GivenAObjWhenIsABoardColumnThenSelfLinkAdded()
        {
            // Arrange
            SetupState();
            mockLinkFactory.Setup(x => x.Build("BoardColumnsGet", It.IsAny<object>())).Returns("http://fake-url/");
            var boardColumn = new BoardColumn();

            // Act
            state.Apply(boardColumn);

            // Assert
            Assert.NotNull(boardColumn.Links);
            Assert.NotNull(boardColumn.Links.FirstOrDefault(x => x.Rel == Link.SELF));
        }
コード例 #3
0
            public async void GivenABoardSlugAndBoardColumnWhenBoardExistsThenHyperMediaSet()
            {
                // Arrange
                SetupController();
                var boardSlug = "test";
                var column = new BoardColumn();
                mockCommandDispatcher.Setup(
                    x => x.HandleAsync<CreateBoardColumnCommand, BoardColumn>(It.IsAny<CreateBoardColumnCommand>()))
                    .ReturnsAsync(new BoardColumn());
                mockHyperMediaFactory.Setup(x => x.GetLink(It.IsAny<IHyperMediaItem>(), It.IsAny<string>()))
                    .Returns("http://fake-url/");

                // Act
                await controller.Post(boardSlug, column);

                // Assert
                mockHyperMediaFactory.Verify(x => x.Apply(It.IsAny<BoardColumn>()), Times.Once);
            }
コード例 #4
0
            public async void GivenABoardSlugAndBoardColumnWhenBoardExistsThenCreateColumnOnBoard()
            {
                // Arrange
                SetupController();
                var boardSlug = "test";
                var column = new BoardColumn();
                mockCommandDispatcher.Setup(
                    x => x.HandleAsync<CreateBoardColumnCommand, BoardColumn>(It.IsAny<CreateBoardColumnCommand>()))
                    .ReturnsAsync(new BoardColumn());
                mockHyperMediaFactory.Setup(x => x.GetLink(It.IsAny<IHyperMediaItem>(), It.IsAny<string>()))
                    .Returns("http://fake-url/");

                // Act
                var createdNegotiatedContentResult =
                    await controller.Post(boardSlug, column) as CreatedNegotiatedContentResult<BoardColumn>;

                // Assert
                Assert.NotNull(createdNegotiatedContentResult);
            }
コード例 #5
0
        public async Task<IHttpActionResult> Put(string boardSlug, string boardColumnSlug, BoardColumn boardColumn)
        {
            try
            {
                var result = await commandDispatcher.HandleAsync<UpdateBoardColumnCommand, BoardColumn>(new UpdateBoardColumnCommand
                {
                    BoardSlug = boardSlug,
                    BoardColumnSlug = boardColumnSlug,
                    BoardColumn = boardColumn
                });

                hyperMediaFactory.Apply(result);

                return Ok(result);
            }
            catch (BoardNotFoundException)
            {
                return NotFound();
            }
            catch (BoardColumnNotFoundException)
            {
                return NotFound();
            }
        }
コード例 #6
0
            public async void GivenABoardSlugAndBoardColumnWhenBoardColumnIsInvalidThenReturnInvalidModelState()
            {
                // Arrange
                SetupController();
                var boardSlug = "test";
                var column = new BoardColumn();
                controller.ModelState.AddModelError("error", "error");

                // Act
                var invalidModelStateResult = await controller.Post(boardSlug, column) as InvalidModelStateResult;

                // Assert
                Assert.NotNull(invalidModelStateResult);
            }
コード例 #7
0
            public async void GivenBoardSlugAndBoardColumnSlugAndBoardColumnWhenOkThenHyperMediaApplied()
            {
                // Arrange
                SetupController();
                const string boardSlug = "board-name";
                const string boardColumnSlug = "board-column-name";
                var boardColumn = new BoardColumn();

                mockCommandDispatcher.Setup(
                    x => x.HandleAsync<UpdateBoardColumnCommand, BoardColumn>(It.IsAny<UpdateBoardColumnCommand>()))
                    .ReturnsAsync(boardColumn);

                // Act
                await controller.Put(boardSlug, boardColumnSlug, boardColumn);

                // Assert
                mockHyperMediaFactory.Verify(x => x.Apply(It.IsAny<BoardColumn>()), Times.Once);
            }
コード例 #8
0
            public async void GivenBoardSlugAndBoardColumnSlugAndBoardWhenUpdatedThenUpdateBoardColumnCommandCalled()
            {
                // Arrange
                SetupController();
                const string boardSlug = "board-name";
                const string boardColumnSlug = "board-column-name";
                var boardColumn = new BoardColumn();

                mockCommandDispatcher.Setup(
                    x => x.HandleAsync<UpdateBoardColumnCommand, BoardColumn>(It.IsAny<UpdateBoardColumnCommand>()))
                    .ReturnsAsync(boardColumn);

                // Act
                await controller.Put(boardSlug, boardColumnSlug, boardColumn);

                // Assert
                mockCommandDispatcher.Verify(
                    x => x.HandleAsync<UpdateBoardColumnCommand, BoardColumn>(
                        It.Is<UpdateBoardColumnCommand>(y => y.BoardSlug == boardSlug && y.BoardColumnSlug == boardColumnSlug && y.BoardColumn == boardColumn)),
                    Times.Once);

            }
コード例 #9
0
            public async void GivenBoardSlugAndBoardColumnSlugAndBoardWhenUpdatedThenOkResultReturned()
            {
                // Arrange
                SetupController();
                const string boardSlug = "board-name";
                const string boardColumnSlug = "board-column-name";
                var boardColumn = new BoardColumn();

                mockCommandDispatcher.Setup(
                    x => x.HandleAsync<UpdateBoardColumnCommand, BoardColumn>(It.IsAny<UpdateBoardColumnCommand>()))
                    .ReturnsAsync(boardColumn);

                // Act
                var okNegotiatedContentResult = await controller.Put(boardSlug, boardColumnSlug, boardColumn) as OkNegotiatedContentResult<BoardColumn>;

                // Assert
                Assert.NotNull(okNegotiatedContentResult);
            }
コード例 #10
0
            public async void GivenBoardSlugAndBoardColumnSlugAndBoardWhenBoardColumnDoesNotExistThenNotFonndReturned()
            {
                // Arrange
                SetupController();
                const string boardSlug = "board-name";
                const string boardColumnSlug = "board-column-name";
                var boardColumn = new BoardColumn();

                mockCommandDispatcher.Setup(
                    x => x.HandleAsync<UpdateBoardColumnCommand, BoardColumn>(It.IsAny<UpdateBoardColumnCommand>()))
                    .Throws<BoardColumnNotFoundException>();

                // Act
                var notFoundResult = await controller.Put(boardSlug, boardColumnSlug, boardColumn) as NotFoundResult;

                // Assert
                Assert.NotNull(notFoundResult);
            }
コード例 #11
0
            public async void GivenABoardSlugAndBoardColumnWhenBoardDoesNotExistThenNotFound()
            {
                // Arrange
                SetupController();
                var boardSlug = "test";
                var column = new BoardColumn();
                mockCommandDispatcher.Setup(
                    x => x.HandleAsync<CreateBoardColumnCommand, BoardColumn>(It.IsAny<CreateBoardColumnCommand>()))
                    .Throws<BoardNotFoundException>();

                // Act
                var notFoundResult = await controller.Post(boardSlug, column) as NotFoundResult;

                // Assert
                Assert.NotNull(notFoundResult);
            }
コード例 #12
0
            public async void GivenABoardSlugAndBoardColumnWhenSlugForBoardColumnExistsThenConflictReturned()
            {
                // Arrange
                SetupController();
                var boardSlug = "test";
                var column = new BoardColumn();
                mockCommandDispatcher.Setup(
                    x => x.HandleAsync<CreateBoardColumnCommand, BoardColumn>(It.IsAny<CreateBoardColumnCommand>()))
                    .Throws<CreateBoardColumnCommandSlugExistsException>();

                // Act
                var conflictResult = await controller.Post(boardSlug, column) as ConflictResult;

                // Assert
                Assert.NotNull(conflictResult);
            }
コード例 #13
0
            public async void GivenABoardSlugAndBoardColumnWhenBoardIsNotFoundThenReturnNotFound()
            {
                // Arrange
                SetupController();
                var boardSlug = "test";
                var column = new BoardColumn();

                // Act
                var notFoundResult = await controller.Post(boardSlug, column) as NotFoundResult;

                // Assert
                Assert.NotNull(notFoundResult);
            }
コード例 #14
0
        public async Task<IHttpActionResult> Post(string boardSlug, BoardColumn boardColumn)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            try
            {
                var result =
                    await
                        commandDispatcher.HandleAsync<CreateBoardColumnCommand, BoardColumn>(new CreateBoardColumnCommand
                        {
                            BoardSlug = boardSlug,
                            BoardColumn = boardColumn
                        });

                if (result == null)
                {
                    return NotFound();
                }

                hyperMediaFactory.Apply(result);

                return Created(hyperMediaFactory.GetLink(result, Link.SELF), result);
            }
            catch (CreateBoardColumnCommandSlugExistsException)
            {
                return Conflict();
            }
            catch (BoardNotFoundException)
            {
                return NotFound();
            }
        }