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
It appears maybe Isolator has cached something and ignores the default parameterless constructor...

The code that mimics (loosely) real code that causes this bug:
    public class UsesCustomer
    {
        public string Name { get; private set; }

        public Customer CustomerObject { get; set; }
    }

    public class CustomerX
    {
        UsesCustomer parent;

        public string Name { get; private set; }

        public static CustomerX NewCustomer(UsesCustomer uses)
        {
            return new CustomerX(uses);
        }

        public static CustomerX GetCustomer(UsesCustomer uses, string whatever)
        {
            return new CustomerX(uses, whatever);
        }

        private CustomerX() { }

        private CustomerX(UsesCustomer parent) 
        {
            Name = parent.Name;
        }

        private CustomerX(UsesCustomer parent, string somethingElse)
        {
            Name = parent.Name + somethingElse;
        }
    }


Now the tests - ran individually they both pass, but if you created an ordered test (A being first, B being second), the B test will fail will null references.

        [Isolated(), TestMethod()]
        public void TestA()
        {
            UsesCustomer fake = Isolate.Fake.Instance<UsesCustomer>();
            Isolate.WhenCalled(() => fake.Name).WillReturn("BLAH");

            CustomerX customer = CustomerX.GetCustomer(fake, "BLAH");

            Assert.AreEqual<string>("BLAHBLAH", customer.Name);
        }

        [Isolated(), TestMethod()]
        public void TestB()
        {
            UsesCustomer uses = new UsesCustomer();

            CustomerX fake = Isolate.Fake.Instance<CustomerX>(Members.CallOriginal);    //for other reasons
            Isolate.WhenCalled(() => fake.Name).WillReturn("BLAH2");
            Isolate.Swap.NextInstance<CustomerX>().With(fake);

            CustomerX customer = CustomerX.NewCustomer(uses);

            Assert.AreEqual<string>("BLAH2", customer.Name);
        }


Please let me know when a patch is available...
asked by boo (21.8k points)

1 Answer

0 votes
Brian,

Thanks for the code example, I've reproduced the problem. It's obviously a bug :twisted:

I'll let you know when it's fixed.

Thanks,
answered by gilz (14.5k points)
...