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
I have two very similar tests. One of them passes and one fails, throwing the exception "Cannot use WhenCalled without a complementing behavior statement." Here is a minimal repro:

namespace TypeMockReproTest
{
    using System.Xml.Linq;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using TypeMock.ArrangeActAssert;

    [TestClass, Isolated]
    public class TypemockReproTest
    {
        [TestMethod]
        public void TestOne()
        {
            Isolate.Fake.StaticMethods(typeof(XElement), Members.CallOriginal);
            Isolate.WhenCalled(() => XElement.Load((string)null)).WillReturn(XElement.Parse(string.Empty));
        }

        [TestMethod]
        public void TestTwo()
        {
            Isolate.Fake.StaticMethods(typeof(XElement), Members.CallOriginal);
            Isolate.WhenCalled(() => XElement.Load((string)null)).WillReturn(XElement.Parse("<foo>"));
        }
    }
}


Test One throws the exception and Test Two passes. Any ideas?

Thanks,
Larry
asked by lgolding@microsoft.c (4k points)

2 Answers

0 votes
XElement.Parse(String.Empty) throws an XmlException, so the attempt to set up the "WhenCalled" condition fails.

Sorry,
Larry
answered by lgolding@microsoft.c (4k points)
0 votes
No need to be sorry, this is a good catch - our error message is misleading and should be cleared up. I'll make sure we will fix this for an upcoming version.

Thanks!
Doron
Typemock Support
answered by doron (17.2k points)
...