【发布时间】:2015-05-11 02:26:16
【问题描述】:
我想针对某些错误的网络行为测试存储库。我使用 MS Fakes 伪造了课程,它看起来像这样:
ShimInputRepository
.AllInstances
.UpdateEngagementStringNullableOfInt64NullableOfInt32String = (xInst, xEngId, xTrimUri, xTargetVers, xComments) =>
{
if (xEngId != initializer.SeededEngagementsWithoutEmp[3].EngagementId)
{
return xInst.UpdateEngagement(xEngId, xTrimUri, xTargetVers, xComments); //Unfortunately, calls recursively same method (not the original one)
}
else
{
throw new Exception
(
"An error occurred while executing the command definition. See the inner exception for details.",
new Exception
(
"A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable)"
)
);
}
};
我不知道如何使用该代码调用原始方法(目前它递归调用相同的方法)。
如何调用原方法?
更新:我真正想要实现的是在对该方法的特定调用(“if() ...”语句)上抛出异常,否则将调用转发到原始实例。
【问题讨论】:
-
你想调用哪个方法?
-
我实现的唯一一个,即“UpdateEngagement...”
-
你想从同一个方法中调用它吗?这是不可能的,永远不会到达调用自身的代码。或者您想知道如何在该方法之外调用它
-
请查看“更新”
标签: c# mstest microsoft-fakes shim