Den*_*nis 4 c# unit-testing moq
我在接口上有一个方法:
void HandleError(MyClasss c, object o, Exception e);
Run Code Online (Sandbox Code Playgroud)
我想用最小起订量来模拟这个,并在任何参数上抛出提供的Exception e。
就像是:
_mock.Setup(a => a.HandlreError(It.IsAny<MyClass>(), It.IsAny<object>()
, It.IsAny<Exception>())).Throws( [the 'any' exception] )
Run Code Online (Sandbox Code Playgroud)
您可以使用通过传递给模拟对象的参数来调用的回调操作:
_mock
.Setup(a => a.HandlreError(It.IsAny<MyClass>(), It.IsAny<object>(), It.IsAny<Exception>()))
.Callback((MyClass c, object o, Exception e) => { throw e; });
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
652 次 |
| 最近记录: |