Пример #1
0
        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;
            }
        }
Пример #2
0
        public void MoveUpCommandAndUndo_When_NewDesk_Then_NoMoving()
        {
            var  desk        = _helper.GenerateDesk(4);
            var  moveCommand = new MoveUpCommand(desk);
            bool res         = moveCommand.Execute();

            Assert.False(res);
        }
Пример #3
0
        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());
        }
Пример #4
0
        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);
        }
Пример #5
0
        public void HoverCommand_ShouldExecuteClientMoveUp()
        {
            // arrange
            moveUpCommand = new MoveUpCommand(DroneClientMock.Object);

            // act
            moveUpCommand.Execute();

            // assert
            DroneClientMock.Verify(x => x.MoveUp(), Times.Once);
        }
Пример #6
0
        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();
        }
Пример #7
0
        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);
        }