public void Should_Move_Item_To_Another_Column() { // Given var board = context.KanbanBoards.Include(x => x.Columns).ThenInclude(x => x.Items).First(); var user = context.AppUsers.FirstOrDefault(); var handler = new MoveItem(repository, CreateAccessServiceMock().Object); var firstColumn = board.Columns.Where(x => x.Items.Any()).First(); var lastColumn = board.Columns.Where(x => x.Items.Any()).Last(); var items = firstColumn.Items.OrderBy(x => x.Index); var itemToMove = items.First(); var lastIndex = lastColumn.Items.Count() - 1; var newIndex = 0; var expectedIndexes = lastColumn.Items.OrderBy(x => x.Index).Select(x => x.Index); expectedIndexes.Append(expectedIndexes.Count()); // When handler.HandleAsync( new MoveItem.Command(user.ID, board.ID, itemToMove.ID, newIndex, lastColumn.ID, board.Timestamp)).Wait(); // Then var actualIndexes = lastColumn.Items.OrderBy(x => x.Index).Select(x => x.Index); CollectionAssert.AreEqual(expectedIndexes, actualIndexes); Assert.AreEqual(newIndex, itemToMove.Index); Assert.AreEqual(lastColumn.ID, itemToMove.ColumnID); Assert.IsFalse(firstColumn.Items.Any(x => x.ID == itemToMove.ID)); }
public void Should_Throw_Exception_On_Moving_Item_With_Old_Timestamp() { // Given var board = context.KanbanBoards.Include(x => x.Columns).ThenInclude(x => x.Items).First(); var user = context.AppUsers.FirstOrDefault(); var handler = new MoveItem(repository, CreateAccessServiceMock().Object); var srcColumn = board.Columns.Where(x => x.Items.Any()).First(); var itemToMove = srcColumn.Items.OrderBy(x => x.Index).First(); var newIndex = 0; // When Assert.CatchAsync <ConflictException>( async() => await handler.HandleAsync( new MoveItem.Command(user.ID, board.ID, itemToMove.ID, newIndex, srcColumn.ID, DateTime.Now))); }
public void Should_Throw_Exception_On_Moving_Item_To_Column_From_Another_Board() { // Given var srcBoard = context.KanbanBoards.Include(x => x.Columns).ThenInclude(x => x.Items).First(); var destBoard = context.KanbanBoards.Include(x => x.Columns).ThenInclude(x => x.Items).Last(); var user = context.AppUsers.FirstOrDefault(); var handler = new MoveItem(repository, CreateAccessServiceMock().Object); var srcColumn = srcBoard.Columns.Where(x => x.Items.Any()).First(); var destColumn = destBoard.Columns.Where(x => x.Items.Any()).Last(); var itemToMove = srcColumn.Items.OrderBy(x => x.Index).First(); var newIndex = 0; // When Assert.CatchAsync <ArgumentException>( async() => await handler.HandleAsync( new MoveItem.Command(user.ID, srcBoard.ID, itemToMove.ID, newIndex, destColumn.ID, srcBoard.Timestamp))); }