Hello
Let us have a small look at four different classes and their dependencies:
- The first class represents a form in openpetra which holds a TSgrdDataGrid.
- The second class is the TSgrdDataGrid itself
- This class inherits the class SourceGrid.DataGrid which is a separate project
- SourceGrid.DataGrid contains Selection and this class is not a control itself. It is a “inner class” of a control.
In normal cases the user does something inside his dialog and the selection of the grid changes.
This changes invokes more or less of the code in those different classes and in any case, the lowest level is the selection-class. This class provides a set of events, which enables the outer part of the control to run a proper reaction. Actually this are the following different events ...
- CellGotFocus
- CellLostFocus
- FocusColumnEntered
- FocusColumnLeaving
- FocusRowEntered
- FocusRowLeaving
- SelectionChanged
Actually the "AnySpecificForm" installs its listener on the selection class which may be read like:
this.grdDetails.Selection.FocusRowEntered += new SourceGrid.RowEventHandler(this.FocusedRowChanged);
Problems:
Selection is not a control and cannot be addressed by NUnit
It is not trivial to upgrade NUnit, that it can handle selection and the result may be a performance problem (We have to reflect not only the controls but all subclasses.
It is not a good realization of a test to interact deeply inside of the code (not in this cases!) – We have to know that we use a grid with a specific Selection class.
[/list:u]
Solution
Following the picture our own control TSgrdDataGrid itself provides a set of event handlers named like the event handlers of the selection control. TSgrdDataGrid itself and only installs a listener to selection and AnySpecificForm only uses TSgrdDataGrid.
So Instead of
this.grdDetails.Selection.FocusRowEntered += new SourceGrid.RowEventHandler(this.FocusedRowChanged);
we write
this.grdDetails.FocusRowEntered += new SourceGrid.RowEventHandler(this.FocusedRowChanged);
And in the case of a test now we can write:
tFrmGLBatchTester.ttpgBatches.grdDetails.FireEvent(...)
Actually we have no chance to fire the event!
Best regards
Wolfgang