public void CancelEditTest()
        {
            ObservableCollection <TestData> dataList = new ObservableCollection <TestData>()
            {
                new TestData()
                {
                    StrValue = "A"
                },
                new TestData()
                {
                    StrValue = "B"
                },
                new TestData()
                {
                    StrValue = "C"
                }
            };

            var target      = new DataGridEditStateService();
            var serviceList = new UIServiceCollection();

            serviceList.Add(new ServiceFactoryMock(target));
            serviceList.Add(new ParameterlessUIServiceFactory()
            {
                ServiceType = typeof(DataGridCurrentCellService)
            });
            serviceList.Add(new ParameterlessUIServiceFactory()
            {
                ServiceType = typeof(DefaultCommandRegulationService)
            });

            DataGrid dataGrid;

            using (TestWindow.Show(dataList, serviceList, out dataGrid))
            {
                // Begin edit and ensure the grid is indeed in edit mode.
                dataGrid.CurrentCell = new System.Windows.Controls.DataGridCellInfo(dataList[0], dataGrid.Columns[0]);
                Assert.IsTrue(target.BeginItemEdit(), "Begin edit should have succeeded.");
                Assert.IsTrue(target.IsEditingField);

                using (var eventsSink = new DGEventsSink(dataGrid))
                {
                    Assert.IsTrue(target.CancelItemEdit());
                    Assert.IsTrue(eventsSink.RowEditEndingEventRaised);
                    Assert.IsTrue(eventsSink.CellEditEndingEventRaised);

                    eventsSink.Reset();
                    Assert.IsTrue(target.CancelItemEdit());
                    Assert.IsFalse(eventsSink.RowEditEndingEventRaised);
                    Assert.IsFalse(eventsSink.CellEditEndingEventRaised);
                }
            }
        }
        public void CurrentEditTest()
        {
            ObservableCollection <TestData> dataList = new ObservableCollection <TestData>()
            {
                new TestData()
                {
                    StrValue = "A"
                },
                new TestData()
                {
                    StrValue = "B"
                },
                new TestData()
                {
                    StrValue = "C"
                }
            };

            var target      = new DataGridEditStateService();
            var serviceList = new UIServiceCollection();

            serviceList.Add(new ServiceFactoryMock(target));
            serviceList.Add(new ParameterlessUIServiceFactory()
            {
                ServiceType = typeof(DataGridCurrentCellService)
            });
            serviceList.Add(new ParameterlessUIServiceFactory()
            {
                ServiceType = typeof(DefaultCommandRegulationService)
            });

            DataGrid dataGrid;

            using (TestWindow.Show(dataList, serviceList, out dataGrid))
            {
                // Begin edit and ensure the grid is indeed in edit mode.
                dataGrid.CurrentCell = new DataGridCellInfo(dataList[0], dataGrid.Columns[0]);
                Precondition(target.BeginItemEdit(), "Begin edit should have succeeded.");

                Assert.AreEqual(dataList[0], target.CurrentEdit);
                Precondition(target.CommitItemEdit(), "Failed committing");
                Assert.IsNull(target.CurrentEdit);

                dataGrid.CurrentCell = new DataGridCellInfo(dataList[2], dataGrid.Columns[0]);
                Precondition(dataGrid.BeginEdit(), "Begin edit should have succeeded.");
                Assert.AreEqual(dataList[2], target.CurrentEdit);
                Precondition(target.CancelItemEdit(), "Failed canceling");
                Assert.IsNull(target.CurrentEdit);
            }
        }