protected override void OnPreviewKeyDown(KeyEventArgs e) { base.OnPreviewKeyDown(e); DataGridCell senderCell = e.OriginalSource as DataGridCell; bool ctrlDown = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl); if (e.Key == Key.Return) { if (senderCell != null && !senderCell.IsEditing) { // Enter edit mode if current cell is not in edit mode senderCell.Focus(); this.BeginEdit(); e.Handled = true; } } else if (e.Key == Key.Space) { if (senderCell != null && !senderCell.IsEditing) { object item = senderCell.DataContext; // In some cases senderCell is not selected. This can happen after multi selection over all items. if (!senderCell.IsSelected) { item = SelectedItem; // simply use first selected item } ToggleEnabledForItem(item); e.Handled = true; } } else if (ctrlDown && e.Key == Key.Up) { if (MoveUpCommand != null && MoveUpCommand.CanExecute(null)) { var focusedCellItem = (Keyboard.FocusedElement as DataGridCell)?.DataContext; MoveUpCommand.Execute(null); // DataGrid loses keyboard focus after moving items FocusCellAfterDelay(focusedCellItem); } e.Handled = true; } else if (ctrlDown && e.Key == Key.Down) { if (MoveDownCommand != null && MoveDownCommand.CanExecute(null)) { var focusedCellItem = (Keyboard.FocusedElement as DataGridCell)?.DataContext; MoveDownCommand.Execute(null); // DataGrid loses keyboard focus after moving items FocusCellAfterDelay(focusedCellItem); } e.Handled = true; } }
public void MoveUpCommandAndUndo_When_NewDesk_Then_NoMoving() { var desk = _helper.GenerateDesk(4); var moveCommand = new MoveUpCommand(desk); bool res = moveCommand.Execute(); Assert.False(res); }
public void MoveUpCommandAndUndo_When_NewDesk_Then_DeskDoesntChange() { var newDesk = _helper.GenerateDesk(4); var desk = _helper.GenerateDesk(4); var moveCommand = new MoveUpCommand(desk); moveCommand.Execute(); Assert.Equal(newDesk.GetDesk(), desk.GetDesk()); }
public void MoveUpCommand_Execute(int posX, int posY, int expectedX, int expectedY) { robot.SetPosX(posX); robot.SetPosY(posY); cmd.Execute(); Assert.IsTrue(robot.GetPosY == expectedY); Assert.IsTrue(robot.GetPosX == expectedX); }
public void HoverCommand_ShouldExecuteClientMoveUp() { // arrange moveUpCommand = new MoveUpCommand(DroneClientMock.Object); // act moveUpCommand.Execute(); // assert DroneClientMock.Verify(x => x.MoveUp(), Times.Once); }
public void ShouldInvokeMoveUpAndSetStateToHandled() { var slnControl = new Mock <ISolutionExplorerControl>(); slnControl.Setup(x => x.MoveUp()); var command = new MoveUpCommand(slnControl.Object); var context = new Context(); var result = command.Execute(context, Keys.K); Assert.Equal(CommandState.Handled, result.State); slnControl.VerifyAll(); }
public void TestCommandMoveUp() { //arrange int originalYLocation = fakeGameComponent.Y; Command moveUp = new MoveUpCommand(); int finalLocationY; int expectedMoveAmount = 1; //act moveUp.Execute(fakeGameComponent); finalLocationY = fakeGameComponent.Y; //assert Assert.AreEqual(originalYLocation, finalLocationY + expectedMoveAmount); }
public void TestCommandMoveUp() { // Arrange int originalLocationY = fakeGameComponent.Y; Command moveUp = new MoveUpCommand(); int finalLocationY; // The amount the game object should move in one command int expectedMoveAmount = 1; // Act moveUp.Execute(fakeGameComponent); finalLocationY = fakeGameComponent.Y; // Assert Assert.AreEqual(finalLocationY, originalLocationY + expectedMoveAmount); }