public void GiveAObjWhenIsABoardColumnThenReturnsTrue() { // Arrange SetupState(); var boardColumn = new BoardColumn(); // Act var isAppliable = state.IsAppliable(boardColumn); // Assert Assert.True(isAppliable); }
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)); }
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); }
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); }
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(); } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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(); } }