2

I want to create interrelated objects via the FakeItEasy framework the following way

        var gameWorld = A.Fake<IGameWorld>();
        var entityManager = A.Fake<IEntityManager>();
        A.CallTo(() => gameWorld.EntityManager).Returns(entityManager);
        var mapLevel = A.Fake<MapLevel>();
        A.CallTo(() => entityManager.GetCurrentAirSeaMapLevel()).Returns(mapLevel);
        var bounds = new Rectangle(0, 0, 100, 100);
        mapLevel.Bounds = bounds;

The issue is if I later call mapLevel.Bounds in the to tested coding, bounds is a generic dummy/fake, set by the framework and not the property(Bounds) which I have set.

What am I doing wrong ?

Marco
  • 2,189
  • 5
  • 25
  • 44
  • Hard to say without more details. Can you provide definitions for all interfaces and classes, as well as your test code, indicating what goes wrong where? – Blair Conrad May 09 '20 at 15:07
  • frankly this is tough...any hint concerning debugging ? Else I may try to create a minimal reproducible example – Marco May 09 '20 at 18:46
  • If you can, cut out as much extraneous code as possible. If you think the `Bounds` property is behaving badly, try just setting and getting it. If you see different behaviour, or you don't want to change your code, debug through. Examine every object that might contribute to a problem. Are things you think are Fakes really Fakes? Are they _the same Fake you thought they were_ (check identity in the debugger)? If you've faked a class instead of an interface, is the member that's "misbehaving" virtual or abstract? If not, FIE can't intercept calls. If this doesn't help, make a minimal repro. – Blair Conrad May 11 '20 at 11:21
  • thx for your input @BlairConrad! – Marco May 11 '20 at 12:17
  • Did it help enough? Are you fixed? – Blair Conrad May 18 '20 at 18:04
  • 1
    Yeah, the issue is I changed my (non-test) code considerably in the meantime and now this issue is gone. So, cannot reproduce it anymore. But I guess I just do not delete this question, because your comment(s) above may help other folks as well. – Marco May 19 '20 at 13:00

0 Answers0