我正在尝试使用 Mock 库测试函数 GetcallEntityBycallEntity (Guid callId)。
这个函数调用另一个没有实现任何接口的类。
受保护的虚拟 CallFacade CallFacade() { return new CallFacade(); }
public Note GetCallEntityByCallEntity(Guid CallEntity) { myCall= null; **CallFacade** callFacade = Get CallFacade(); if (CallEntity!= Guid.Empty) { myCall = callFacade.GetCallByEntityId(CallEntity); } return myCall; }
CallFacade 不是一个接口
在我的测试中:
[TestInitialize]
public void TestInitialization()
{
IoCMocks.Initialize();
CommonCallFacadeMock = new CommonCallFacadeMock();
}
public void GetCallEntityByNoteEntity_GetCall_ReturnValidCall()
{
//Arrange
CallmyNote = GetmyCall(); //private method. == Call.CreateCall();
//Stubs
CommonCallFacadeMock.MockCallFacade.Setup(x => x.GetCallByEntityId(ExistingCallEntity)).Returns(myCall);
//Action
var obtained = CommonCallFacadeMock.GetCallEntityByCallEntity(ExistingCallEntity);
CommonCallFacadeMock.MockCallFacade.Verify(x => x.GetCallByEntityId(It.IsAny<Guid>()), Times.Once());
}