문제

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