Using Moq to determine if a method is called

后端 未结 3 1953
暗喜
暗喜 2020-11-29 02:21

It is my understanding that I can test that a method call will occur if I call a higher level method, i.e.:

public abstract class SomeClass()
{    
    publi         


        
3条回答
  •  再見小時候
    2020-11-29 02:51

    No, mock testing assumes you are using certain testable design patterns, one of which is injection. In your case you would be testing SomeClass.SomeMethod and SomeOtherMethod must be implemented in another entity which needs to be interfaced.

    Your Someclass constructor would look like New(ISomeOtherClass). Then you would mock the ISomeOtherClass and set expectation on its SomeOtherMethod to be called and verify the expectation.

提交回复
热议问题