I still can't force this to happen, but I know when it's going to happen.
The tested class is this:
public class TestedClass
{
public bool TestedMethod(string token, out Guid firstKey, out Guid secondKey)
{
firstKey = new Guid("{11111111-1111-1111-1111-111111111111}");
secondKey = new Guid("{22222222-2222-2222-2222-222222222222}");
return true;
}
}
This is the test that, sometimes, fails:
[TestMethod]
[VerifyMocks]
public void TestMethod1()
{
Guid firstKey;
Guid secondKey;
Guid expectedFirstKey = new Guid("{33333333-3333-3333-3333-333333333333}");
Guid expectedSecondKey = new Guid("{44444444-4444-4444-4444-444444444444}");
string token = "token";
bool expected = true;
bool actual;
TestedClass target = RecorderManager.CreateMockedObject<TestedClass>(Constructor.Mocked, StrictFlags.AllMethods);
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
recorder.DefaultBehavior.CheckArguments();
recorder.ExpectAndReturn(target.TestedMethod(token, out expectedFirstKey, out expectedSecondKey), expected);
}
actual = target.TestedMethod(token, out firstKey, out secondKey);
Assert.AreEqual(expected, actual);
Assert.AreEqual(expectedFirstKey, firstKey);
Assert.AreEqual(expectedSecondKey, secondKey);
}
So I decided to used a
CustomChecker to make sure the output parameters where the ones I wanted and found out that the mocking always fails when the value of the
ArgumentValue is
null.
Here is the new test:
private static bool CustomChecker(ParameterCheckerEventArgs data)
{
if (data.ArgumentValue == null)
{
Assert.Inconclusive("TypeMock failure.");
}
return true;
}
[TestMethod]
[VerifyMocks]
public void TestMethod2()
{
Guid firstKey;
Guid secondKey;
Guid expectedFirstKey = new Guid("{33333333-3333-3333-3333-333333333333}");
Guid expectedSecondKey = new Guid("{44444444-4444-4444-4444-444444444444}");
string token = "token";
bool expected = true;
bool actual;
TestedClass target = RecorderManager.CreateMockedObject<TestedClass>(Constructor.Mocked, StrictFlags.AllMethods);
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
recorder.DefaultBehavior.CheckArguments();
recorder.ExpectAndReturn(target.TestedMethod(token, out expectedFirstKey, out expectedSecondKey), expected)
.WhenArgumentsMatch(token,
Check.CustomChecker(CustomChecker, expectedFirstKey),
Check.CustomChecker(CustomChecker, expectedSecondKey));
}
actual = target.TestedMethod(token, out firstKey, out secondKey);
Assert.AreEqual(expected, actual);
Assert.AreEqual(expectedFirstKey, firstKey);
Assert.AreEqual(expectedSecondKey, secondKey);
}