public void CommitEditTest()
        {
            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.CommitItemEdit());
                    Assert.IsTrue(eventsSink.RowEditEndingEventRaised);
                    Assert.IsTrue(eventsSink.CellEditEndingEventRaised);

                    eventsSink.Reset();
                    Assert.IsTrue(target.CommitItemEdit());
                    Assert.IsFalse(eventsSink.RowEditEndingEventRaised);
                    Assert.IsFalse(eventsSink.CellEditEndingEventRaised);
                }
            }
        }
        public void BeginEditTest()
        {
            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))
            {
                using (var eventsSink = new DGEventsSink(dataGrid))
                {
                    Assert.IsFalse(target.BeginItemEdit(), "Begin edit should have failed, because the data grid has no selected cell.");
                    Assert.IsFalse(eventsSink.BeginningEditEventRaised);

                    // Select a cell eligible for editing.
                    dataGrid.CurrentCell = new System.Windows.Controls.DataGridCellInfo(dataList[0], dataGrid.Columns[0]);
                    Assert.IsTrue(target.BeginItemEdit(), "Begin edit should have succeeded.");
                    Assert.IsTrue(eventsSink.BeginningEditEventRaised);
                    Assert.IsTrue(target.IsEditingField);

                    eventsSink.Reset();
                    Assert.IsTrue(target.BeginItemEdit(), "Although no new editing began, begin edit should return true - meaning the grid is in edit mode.");
                    Assert.IsFalse(eventsSink.BeginningEditEventRaised);
                }
            }
        }