Use FakeItEasy's A.CallTo() on another method in same object

后端 未结 2 690
别那么骄傲
别那么骄傲 2020-12-19 09:54

Using FakeItEasy, how do I check to see if my object\'s method calls another method on this same object?

The Test:

[TestMethod]
public void EatBanana         


        
2条回答
  •  轮回少年
    2020-12-19 10:20

    It's possible to do this. If the WillEat method were virtual - otherwise FakeItEasy won't be able to fake it out.

    With that change, you could do this:

    [TestMethod]
    public void EatBanana_CallsWillEat()
    {
        var fakeMonkey = A.Fake();
    
        fakeMonkey.EatBanana(new Banana());
    
        A.CallTo(()=>fakeMonkey.WillEat(A._)).MustHaveHappened();
    }
    

    I'm still not convinced it's a good idea (as I ranted in the comments) - I think you'd be better off relying on other observable behaviour, but I'm not familiar with your system. If you think this is the best way to go, the example code should work for you.

提交回复
热议问题