public void GiveAObjWhenIsABoardThenReturnsTrue()
        {
            // Arrange
            SetupState();
            var board = new Board();

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

            // Assert
            Assert.True(isAppliable);
        }
        public void GivenAObjWhenIsABoardThenSelfLinkAdded()
        {
            // Arrange
            SetupState();
            mockLinkFactory.Setup(x => x.Build("BoardsGet", It.IsAny<object>())).Returns("http://fake-url/");
            var board = new Board();

            // Act
            state.Apply(board);

            // Assert
            Assert.NotNull(board.Links);
            Assert.NotNull(board.Links.FirstOrDefault(x => x.Rel == Link.SELF));
        }
            public async void GivenABoardWhenDataIsValidThenCreatedOkResultReturned()
            {
                // Arrange
                SetupController();

                var board = new Board
                {
                    Name = "new board"
                };

                mockCommandDispatcher.Setup(
                    x => x.HandleAsync<CreateBoardCommand, Board>(It.IsAny<CreateBoardCommand>()))
                    .ReturnsAsync(new Board());
                mockHyperMediaFactory.Setup(x => x.GetLink(It.IsAny<IHyperMediaItem>(), It.IsAny<string>()))
                    .Returns("http://fake-url/");

                // Act
                var createdNegotiatedContentResult =
                    await controller.Post(board) as CreatedNegotiatedContentResult<Board>;

                // Assert
                Assert.NotNull(createdNegotiatedContentResult);
            }
        public async Task<IHttpActionResult> Post(Board board)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                var result = await commandDispatcher.HandleAsync<CreateBoardCommand, Board>(
                    new CreateBoardCommand
                    {
                        Board = board
                    });

                hyperMediaFactory.Apply(result);

                return Created(hyperMediaFactory.GetLink(result, Link.SELF), result);
            }
            catch (CreateBoardCommandSlugExistsException)
            {
                return Conflict();
            }
        }
            public async void GivenABoardWhenDataIsNotValidThenInvalidModelStateResultReturned()
            {
                // Arrange
                SetupController();

                var board = new Board();

                // force a validation error
                controller.ModelState.AddModelError("error", "error");

                // Act
                var invalidModelStateResult = await controller.Post(board) as InvalidModelStateResult;

                // Assert
                Assert.NotNull(invalidModelStateResult);
            }
            public async void GivenABoardWhenBoardSlugAlreadyExistsThenReturnReturnsConflict()
            {
                // Arrange
                SetupController();

                var board = new Board
                {
                    Name = "new board"
                };

                mockCommandDispatcher.Setup(
                    x => x.HandleAsync<CreateBoardCommand, Board>(It.IsAny<CreateBoardCommand>()))
                    .Throws<CreateBoardCommandSlugExistsException>();

                // Act
                var conflictResult = await controller.Post(board) as ConflictResult;

                // Act
                Assert.NotNull(conflictResult);
            }