B
Berryl Hesh
I am experimenting with a class of widgets, and trying to decide on a
general strategy for testing them. Say my button widget has a property in
it's interface of:
public event EventHandler Click;
If I implement this as a Win Forms button, I know I can use the implemented
buttons PreformClick() method to test it, but how can I do this more
generically, just using the .Net event? For example, in the sample test code
below, I think I want to do something like
widgetHello.Click.Invoke(this, EventArgs.Empty);
which doesn't even compile much less work.
Thanks for the help - BH
[Test]
public void ClickEvent_CanBeDelegated_ToAnArbitraryMethod() {
// arrange
Assert.That(HelloMessage, Is.EqualTo(null));
var btnHello = new Button {Text = "Click Me"};
var widgetHello = new WinButton(btnHello);
widgetHello.Click += delegate { SayHello(); };
// act
btnHello.PerformClick();
// assert
Assert.That(HelloMessage, Is.EqualTo("Hello World"));
}
general strategy for testing them. Say my button widget has a property in
it's interface of:
public event EventHandler Click;
If I implement this as a Win Forms button, I know I can use the implemented
buttons PreformClick() method to test it, but how can I do this more
generically, just using the .Net event? For example, in the sample test code
below, I think I want to do something like
widgetHello.Click.Invoke(this, EventArgs.Empty);
which doesn't even compile much less work.
Thanks for the help - BH
[Test]
public void ClickEvent_CanBeDelegated_ToAnArbitraryMethod() {
// arrange
Assert.That(HelloMessage, Is.EqualTo(null));
var btnHello = new Button {Text = "Click Me"};
var widgetHello = new WinButton(btnHello);
widgetHello.Click += delegate { SayHello(); };
// act
btnHello.PerformClick();
// assert
Assert.That(HelloMessage, Is.EqualTo("Hello World"));
}