Mocking generic method call for any given type parameter

后端 未结 4 1809
孤独总比滥情好
孤独总比滥情好 2020-12-05 12:35

I have an interface

public interface IDataProvider
{
    T GetDataDocument(Guid document) where T:class, new()
}

I\'d like to mock

4条回答
  •  无人及你
    2020-12-05 13:26

    For the particular test you are going to use this mock for, you probably know what T will be, right?

    simply just setup the mock for that:

    myMock.Setup(m => m.GetDataDocument()>(It.IsAny()))
       .Returns(() => new MyDataClass());
    

    It's not really recommended to reuse the mocks anyway, so go ahead and setup mocks for the actual test at hand.

提交回复
热议问题