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...