1st test that works fine:
[TestMethod]
[ExpectedException(typeof(SoapException))]
public void BarTest0()
{
using (RecordExpectations recorder = new RecordExpectations())
{
Foo.Bar(0, 0);
recorder.WhenArgumentsMatch(
1,
Check.IsAny());
recorder.Throw(new SoapException("1st", null)).RepeatAlways();
Foo.Bar(0, 0);
recorder.WhenArgumentsMatch(
Check.NotEqual(1),
Check.IsAny());
recorder.FailWhenCalled().RepeatAlways();
}
Foo.Bar(1, 1); // Throws SoapException
}
2nd that fails (just WhenArgumentsMatch/Throw order changed):
[TestMethod]
[ExpectedException(typeof(SoapException))]
public void BarTest1()
{
using (RecordExpectations recorder = new RecordExpectations())
{
Foo.Bar(0, 0);
recorder.Throw(new SoapException()).RepeatAlways().WhenArgumentsMatch(
1,
Check.IsAny());;
Foo.Bar(0, 0);
recorder.FailWhenCalled().RepeatAlways().WhenArgumentsMatch(
Check.NotEqual(1),
Check.IsAny());;
}
Foo.Bar(1, 1); // Should throw SoapException
}
It fails on 1st WhenArgumentsMatch call,
looks like WhenArgumentsMatch trying apply arguments to the "new SoapException()" call!, if I'll change exception type to Exception() test will work.
So, I think there is bug with WhenArgumentsMatch. The bug is that WhenArgumentsMatch trying appy arguments not to the original call but to the call inside Throw(...).
Comments/Ideas?
PS:
BTW Why WhenArgumentsMatch returns void, not IMockBehaviour?
Thanks.