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
[Test]
public void ConvertingComplexListOfPropertiesToJsonWorksCorrectly()
{
var items = new Dictionary<string, object>();
items.Add("First", 1);
items.Add("Second", 2);

var childItems = new Dictionary<string, object>();
items.Add("Tenth", 10);
items.Add("Eleventh", 11);

var childFake = Isolate.Fake.Instance<ClientProperties>();
Isolate.NonPublic.Property.WhenGetCalled(childFake, "Items").WillReturn(childItems);
items.Add("Third", childFake);
items.Add("Fourth", 4);

var propertiesFake = Isolate.Fake.Instance<ClientProperties>();
Isolate.NonPublic.Property.WhenGetCalled(propertiesFake, "Items").WillReturn(items);

.
.
.
}

The issue is that the propertiesFake fake gets 6 items, while the other fake (childFake) gets zero items. Why is that? THat doesn't make any sense...

Thanks.
asked by bmains (13.2k points)

1 Answer

0 votes
Hi Brian,

I'm a bit confused - it seems in the test that you're only adding items to the items dictionary.
[Test]
public void ConvertingComplexListOfPropertiesToJsonWorksCorrectly()
{
var items = new Dictionary<string, object>();
items.Add("First", 1);
items.Add("Second", 2);

var childItems = new Dictionary<string, object>();
items.Add("Tenth", 10);
items.Add("Eleventh", 11);

var childFake = Isolate.Fake.Instance<ClientProperties>();
Isolate.NonPublic.Property.WhenGetCalled(childFake, "Items").WillReturn(childItems);
items.Add("Third", childFake);
items.Add("Fourth", 4);

var propertiesFake = Isolate.Fake.Instance<ClientProperties>();
Isolate.NonPublic.Property.WhenGetCalled(propertiesFake, "Items").WillReturn(items);

if this is the case it explains why items is the only collection with items.
answered by dhelper (11.9k points)
...