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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
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.
asked by tom3m (9.7k points)

2 Answers

0 votes
Hi,

It fails on 1st WhenArgumentsMatch call, looks like WhenArgumentsMatch trying apply arguments to the "new SoapException()" call!


Indeed this is the right conclusion. we have a bug there that causes the WhenArgumentMatch call to be applied to the new SoapException call. :evil:
if I'll change exception type to Exception() test will work.

Yes becuase TypeMock ignores calls made on types from MSCorlib.

A workaround for this will be to create the returned exception outside the recording block.
answered by lior (13.2k points)
0 votes
Indeed this is the right conclusion. we have a bug there that causes the WhenArgumentMatch call to be applied to the new SoapException call.


Yep, please keep me updated when you'll fix it. I can then test patch :)
answered by tom3m (9.7k points)
...