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
Hi,

Is it possible to delay verification of arguments on the recordexpectations.
I'm looking for something like:

IQueryDns dns = RecorderManager.CreateMockedObject<IQueryDns>();

using (RecordExpectations recorder = new RecordExpectations())
{

recorder.ExpectAndReturn(dns.LookupPtr(_IpAdddress), domainList).CheckArguments();
recorder.ValidateArgsOnVerify = true; // This is what I want
}

TestClass target = new TestClass(dns);
target.Run();
RecorderManager.Verify(); //This is what I want

The issue I'm facing is because the call to LookupPtr is enclosed in a try catch block in the code and the realtime check is cought in this block so I need to delay the verification.

Currently I'm using a work around with reflective mocks to do the delayed verification but it would be nice to be able to do this in Nautral mocks.

Is this possible?

brgds
Martin
asked by Martin1 (1.1k points)

3 Answers

0 votes
Hi,
You can use the MockManager.ValidateArgsOnVerify API
MockManager.ValidateArgsOnVerify = true;


e.g.
MockManager.ValidateArgsOnVerify = true;
using (RecordExpectations recorder = new RecordExpectations())
{
   recorder.ExpectAndReturn(dns.LookupPtr(_IpAdddress),domainList)
   .CheckArguments();
}

TestClass target = new TestClass(dns);
target.Run();
MockManager.Verify();


:arrow: You can use the [VerifyMocks] attribute too
answered by eli (5.7k points)
0 votes
Hi,

Thanks for the reply.

I did already try that and it failed to work, but after you confirmed that it is supposed to work I moved the MockManager.ValidateArgsOnVerify = true; to the first line in the test and then it works.

So from what I can figure out it must be before I call RecorderManager.CreateMockedObject<IQueryDns>();

Is this correct?

Is there an attribute for this(As I can see potential for errors when writing the tests with the current method)?

Thanks
Martin
answered by Martin1 (1.1k points)
0 votes
Hi,

You are right. The setting of ValidateArgsOnVerify should be done before.
this is actually true for most behavior settings.

Currently there is no attribute for this. But i really like the idea for adding attributes for things like this.
answered by lior (13.2k points)
...