コード例 #1
0
        public void AddNewItemsCommandTests()
        {
            // arrange
            var vm = new SpreadsheetColumnBase();

            var view = new SpreadsheetView();
            Mock.Arrange(() => view.KeyNavigationByDemand(Key.Insert, true)).MustBeCalled();
            Mock.Arrange(() => vm.Owner).Returns(view);

            // act
            vm.AddNewItemsCommand.Execute(null);

            // assert
            Mock.Assert(view);
        }
コード例 #2
0
        public void KeyNavigationByDemandMethodTest()
        {
            var spreadsheet = new SpreadsheetView();

            //Move right
            Mock.Arrange(() => spreadsheet.MoveRight()).DoNothing();
            spreadsheet.KeyNavigationByDemand(Key.Right);
            Mock.Assert(() => spreadsheet.MoveRight());

            //Move left
            Mock.Arrange(() => spreadsheet.MoveLeft()).DoNothing();
            spreadsheet.KeyNavigationByDemand(Key.Left);
            Mock.Assert(() => spreadsheet.MoveLeft());

            //Move up
            Mock.Arrange(() => spreadsheet.MoveUp()).DoNothing();
            spreadsheet.KeyNavigationByDemand(Key.Up);
            Mock.Assert(() => spreadsheet.MoveUp());

            //Move Down
            Mock.Arrange(() => spreadsheet.MoveDown()).DoNothing();
            spreadsheet.KeyNavigationByDemand(Key.Down);
            Mock.Assert(() => spreadsheet.MoveDown());

            //Start Editing
            Mock.NonPublic.Arrange(spreadsheet, "StartEditing").DoNothing();
            spreadsheet.KeyNavigationByDemand(Key.Enter);
            Mock.NonPublic.Assert(spreadsheet, "StartEditing");

            //Insert multiple records (there are cells in edit mode)
            Mock.Arrange(() => Keyboard.Modifiers).Returns(ModifierKeys.Shift);
            Mock.Arrange(() => spreadsheet.GetEditedCells()).Returns(new CellBase[1]);
            Mock.Arrange(() => spreadsheet.InsertMultipleRecords()).DoNothing();
            spreadsheet.KeyNavigationByDemand(Key.Insert, true);
            Mock.Assert(() => spreadsheet.InsertMultipleRecords(), Occurs.Never());

            //Insert multiple records (there are no cells in edit mode)
            Mock.Arrange(() => spreadsheet.GetEditedCells()).Returns(new CellBase[0]);
            spreadsheet.KeyNavigationByDemand(Key.Insert, true);
            Mock.Assert(() => spreadsheet.InsertMultipleRecords(), Occurs.Once());

            //Insert new (there are cells in edit mode)
            Mock.Arrange(() => spreadsheet.GetEditedCells()).Returns(new CellBase[1]);
            Mock.Arrange(() => Keyboard.Modifiers).Returns(ModifierKeys.None);
            Mock.Arrange(() => spreadsheet.InsertRecord()).DoNothing();
            spreadsheet.KeyNavigationByDemand(Key.Insert);
            Mock.Assert(() => spreadsheet.InsertRecord(), Occurs.Never());

            //Insert new (there are no cells in edit mode)
            Mock.Arrange(() => spreadsheet.GetEditedCells()).Returns(new CellBase[0]);
            Mock.Arrange(() => Keyboard.Modifiers).Returns(ModifierKeys.None);
            Mock.Arrange(() => spreadsheet.InsertRecord()).DoNothing();
            spreadsheet.KeyNavigationByDemand(Key.Insert);
            Mock.Assert(() => spreadsheet.InsertRecord(), Occurs.Once());

            //Delete record (there are cells in edit mode)
            Mock.Arrange(() => spreadsheet.GetEditedCells()).Returns(new CellBase[1]);
            Mock.Arrange(() => Keyboard.Modifiers).Returns(ModifierKeys.Shift);
            Mock.Arrange(() => spreadsheet.DeleteRecord()).DoNothing();
            spreadsheet.KeyNavigationByDemand(Key.Delete, true);
            Mock.Assert(() => spreadsheet.DeleteRecord(), Occurs.Never());

            //Delete record (there are no cells in edit mode)
            Mock.Arrange(() => spreadsheet.GetEditedCells()).Returns(new CellBase[0]);
            Mock.Arrange(() => Keyboard.Modifiers).Returns(ModifierKeys.Shift);
            Mock.Arrange(() => spreadsheet.DeleteRecord()).DoNothing();
            spreadsheet.KeyNavigationByDemand(Key.Delete, true);
            Mock.Assert(() => spreadsheet.DeleteRecord(), Occurs.Once());

            //Delete values from selected cells (there are cells in edit mode)
            var cell1 = Mock.Create<Cell>(Constructor.Mocked);
            var cell2 = Mock.Create<StackCell>(Constructor.Mocked);
            Mock.Arrange(() => spreadsheet.GetSelectedCells()).Returns(new CellBase[] {cell1, cell2});
            Mock.Arrange(() => spreadsheet.GetEditedCells()).Returns(new CellBase[1]);
            Mock.Arrange(() => Keyboard.Modifiers).Returns(ModifierKeys.None);
            spreadsheet.KeyNavigationByDemand(Key.Delete);
            Mock.Assert(() => cell1.ClearValue(), Occurs.Never());
            Mock.Assert(() => cell2.ClearValue(), Occurs.Never());

            //Delete values from selected cells (there are no cells in edit mode)
            Mock.Arrange(() => spreadsheet.GetEditedCells()).Returns(new CellBase[0]);
            spreadsheet.KeyNavigationByDemand(Key.Delete);
            Mock.Assert(() => cell1.ClearValue(), Occurs.Once());
            Mock.Assert(() => cell2.ClearValue(), Occurs.Once());
        }