I’m facing a problem while unit testing my forms.
The problem is that data bindings are simply not working when the form is not visible.
Here’s some example code:
Data = new Data(); EdtText.DataBindings.Add( new Binding('Text', Data, 'Text', false, DataSourceUpdateMode.OnPropertyChanged));
and later on:
Form2 f = new Form2(); f.Data.Text = 'Test 1'; f.EdtText.Text = 'Test 2'; f.Data.Text = 'Test 3';
At the end the values for components are f.EdtText.Text = ‘Test 2’ and f.Data.Text = ‘Test 3’ but the expected values should be both ‘Test 3’.
Any suggestions?
I think you answered your own question — in order for the property change event (
TextChanged) to occur the control has to be displayed. Your unit test can just do something like this:Instead of exposing the Form components, you’ll probably want to use NUnitForms to get the Form controls: