chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Good evening,
I m trying to hide messageboxes by using WhenCalled method but I encoutnered build error. Would you tell me if you know the solution?

Here is my code
-------------------------------------
[Test]
public void ReadCsvData_OK_RetrievalCsvDataFailed()
{
Isolate.WhenCalled(()=> MessageBox.Show(String.Empty)).WillReturn(DialogResult.OK);

fileTest file = new fileTest();

bool bRtn =file.GetData(FilePath);

Assert.AreEqual(false, bRtn);
}
-------------------------------------
errors is from "WhenCalled(()=> MessageBox" parts.

')' is invalid ,
'>' is invalid
')' is required
; is required

Thak you very much.
asked by anyakira (640 points)

3 Answers

0 votes
Hi,

Is it possible that you are building you test project as .NET 2.0 project?
The Isolator API is using lambda expressions that works from .NET 3.5
answered by ohad (35.4k points)
0 votes
Hi,

Is it possible that you are building you test project as .NET 2.0 project?
The Isolator API is using lambda expressions that works from .NET 3.5


Thanks for your reply-

Yes, I m using Visual Studio 2005. Probably, it uses .NET2..

Now, I need to press OK button everytime an error meassage pop up while testing error cases.
Is there anyway to hide messageboxes while testing?
answered by anyakira (640 points)
0 votes
Hi,
Basically the way you did is right except that you can't use .NET 3.5 syntax.
You still can use the Isolator AAA API with Visual Studio 2005 if you have .NET 3.5 installed. See this post in our blog.


The other option is to use the Isolator natural mocks API which compiled in .NET 2.0.
Here is how you do it natural mocks API:
[Test]
public void ReadCsvData_OK_RetrievalCsvDataFailed()
{
    // everything inside the using block is faked!
    using (RecordExpectations recorder = RecorderManager.StartRecording())
    {
        MessageBox.Show(null);
        recorder.Return(DialogResult.OK);
    }

    FileTest file = new FileTest();

    bool bRtn = file.GetData(FilePath);

    Assert.AreEqual(false, bRtn); 
}


Hope it helps.
answered by ohad (35.4k points)
...