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 !

有帮助吗?

解决方案

Try

Isolate.WhenCalled(() => MessageBox.Show(null)).IgnoreCall();

That should ignore all MessageBox.Show().

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top