如果我在该类中使用扩展方法,如何用单元测试的接口替换具体类?将接口抽象为具有扩展方法的类
我有一个方法:
[HttpGet]
[Route("/yoyo/{yoyoId:int}/accounts")]
public ResponseYoyoEnvelope GetAccountsByYoyoId([FromBody] RequestYoyoEnvelope requestYoyoEnvelope, int yoyoId)
{
var responseYoyoEnvelope = requestYoyoEnvelope.ToResponseYoyoEnvelope();
// get our list of accounts
// responseEnvelope.Data = //list of accounts
return responseYoyoEnvelope;
}
我想更换:
RequestYoyoEnvelope requestYoyoEnvelope
与抽象:
IRequestYoyoEnvelope requestYoyoEnvelope
然而
,ToResponseYoyoEnvelope
是一个扩展方法。
如果我在该类中使用扩展方法,如何用单元测试的接口替换具体类?
我调整了我的答案,一旦我意识到我错过了 - 这是一个API端点。然后我读了这个答案 - @Nkosi不会错过它,而且这个答案更重要。 –