Reputation: 359
I have this annoying method which pop up a MessageBox. So when I try to test it I want to do something like this.
/// <summary>
/// A test for LoadConfig exception
/// </summary>
[TestMethod]
public void LoadConfigTest1()
{
// Arrange
var target = new RFIDManager();
Isolate.WhenCalled(() => ConfigurationManager.AppSettings[0]).WillThrow(new Exception("foo"));
Isolate.WhenCalled(() => MessageBox.Show()).IgnoreCall();
// Act
var result = target.LoadConfig();
// Assert
Assert.IsFalse(result);
}
This don't compile. Because
MessageBox.Show()
needs a string argument. So I want to know is it possible to specify ignore call always, no matter what is the argument ?
I don't know the exact string that will show up.
Thanks a lot !
Upvotes: 2
Views: 701
Reputation: 108957
Try
Isolate.WhenCalled(() => MessageBox.Show(null)).IgnoreCall();
That should ignore all MessageBox.Show()
.
Upvotes: 1