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 a few classes
    public interface IItemFactory 
    {

    }
    public class ItemFactory:IItemFactory
    {

    }

    public class ItemController:Controller
    {
        public IItemFactory factory;
        public RedditCloneTests.TypeMockTesting.IItemFactory Factory
        {
            get { return factory; }
            set { factory = value; }
        }
        public ItemController()
            : this(null)
        {

        }
        public ItemController(IItemFactory itemFactory)
        {
            factory = itemFactory ?? new ItemFactory();
        }
    }


And this test method
        [SetUp]
        public void Init()
        {

           ItemController controllerFake = Isolate.Fake.Instance<ItemController>(Members.ReturnRecursiveFakes);
            Isolate.Swap<ItemController>().With(controllerFake);

            controller = new ItemController();
        }

        [Test, Isolated]
        public void TestItemFactory1()
        {

        }


The code blows up at line
           ItemController controllerFake = Isolate.Fake.Instance<ItemController>(Members.ReturnRecursiveFakes);


The message is this:
TestCase 'TestItemFactory.Init.TestItemFactory1' failed: Object reference not set to an instance of an object.
   System.NullReferenceException
   Message: Object reference not set to an instance of an object.
   Source: TypeMock
   StackTrace:
   at TypeMock.MockManager.a(ConstructorInfo A_0)
   at TypeMock.MockManager.a(Type A_0, ConstructorInfo& A_1)
   at TypeMock.MockManager.a(Type A_0, Object[] A_1)
   at TypeMock.MockManager.StubAllMethods(MockObject mock)
   at ar.StubFirstLevel[T]()
   at ar.Instance[T](Members behavior)
   D:C#TestRedditCloneRedditCloneTestsTypeMockTestingTestNestedCall.cs(28,0): at RedditCloneTests.TypeMockTesting.TestItemFactory.Init()



Is this a bug, or by design? If it's by designed, why?

Note: The controller class is the controller class in ASP.NET MVC.
________
maryjane
asked by nsoonhui (59.1k points)

2 Answers

0 votes
I assume you are running version 5.0. Recursive fakes were improved in version 5.1 (which is now available for download) - can you upgrade and let me know if it works for you?

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
0 votes
Thanks, version 5.1 solves all the problem
________
Ford Essex V6 engine picture
answered by nsoonhui (59.1k points)
...