下面是連貫接口:如何嘲笑連貫接口與犀牛模擬
public interface IReporter<in T,out TResult>
{
IReporter<T, TResult> Add(T seed);
TResult Prepare();
}
使用在代碼爲:
串errorReport = ErrorReporter.Add(例外)。準備() ;
模擬測試情況:
With.Mocks(mockRepository)
.Expecting(() =>
{
Expect.Call(errorReporter.Add(null)).IgnoreArguments();
Expect.Call(errorReporter.Prepare()).Return(string.Empty);
Expect.Call(notifier.Notify(null)).IgnoreArguments().Return(true);
})
.Verify(() =>
{
ITransporter transporter = new Transporter
{
ExpectedArgsLength = 1,
Notifiers = notifiers,
ErrorReporter = errorReporter
};
transporter.Run(new string[] { });
});
錯誤:
Rhino.Mocks.Exceptions.ExpectationViolationException:IReporter`2.Prepare();預期#1,實際#0。
If I comment Expect.Call(errorReporter.Prepare())。Return(string.Empty);那麼它對我來說沒有任何意義。
我錯過了什麼嗎?請幫忙!
如果我按以下方式分解我的代碼,那麼測試運行良好。 ErrorReporter.Add(例外); string errorReport = ErrorReporter.Prepare();我不想破解我的代碼 – milind