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
In Typemock 5.x some developer on our team did this:

CustomJob job = new CustomJob();
Customer customer = new Customer();

Isolate.WhenCalled(() => job.Customer).WillReturn(customer);
Isolate.WhenCalled(() => job.Customer.Orders.Count).WillReturn(2);


Since a later version (last time I checked it was 6.0.1) that did not work anymore. Now we do this

CustomJob job = new CustomJob();
Customer customer = new Customer();

var fakeOrder = Isolate.Fake.Instance<Order>();
Isolate.WhenCalled(() => fakeOrder.OrderLines.Count).WillReturn(2);

Isolate.WhenCalled(() => job.Customer).WillReturn(customer);
Isolate.WhenCalled(() => job.Customer.Order.OrderLines.Count).WillReturn(2);


And now the test succeeds again.

Just wondering if this is a bug... I mean feature in 5.x or 6.x ;-)
asked by dvdstelt (5.3k points)

1 Answer

0 votes
Curious - this worked for me. Is there anything special going on in the Customer or CustomerJob classes? I tried the following:
public class Parent
{
    public Son Son {get;set;}
}

public class Son
{
    public IList<Class> Classes { get; set; }
}

[TestMethod]
public void WhenCalled_OnLiveProperty_ShouldWork()
{
    var realLogger = new Parent();
    var sonOfLogger = new Son();

    Isolate.WhenCalled(() => realLogger.Son).WillReturn(sonOfLogger);
    Isolate.WhenCalled(() => realLogger.Son.Classes.Count).WillReturn(100);

    Assert.AreEqual(100, realLogger.Son.Classes.Count);
}


Is this different from what you did?

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