我有一個接口(稱爲IRepository
),有這樣它的方法:NSubstitute不能設置返回值(CouldNotSetReturnException)
IEnumerable<TEntity> ExecuteStoredProcedure<TEntity>(string functionName,
params Tuple<string, object>[] parameters);
我想設置方法將返回的內容時,它是通過所謂的我的單元測試。就像這樣:
dataAccess = Substitute.For<IRepository>();
dataAccess.ExecuteStoredProcedure<MyCustomReturnType>(null, null)
.ReturnsForAnyArgs(MyCustomReturnList);
當我運行測試,我得到這個異常:
NSubstitute.Exceptions.CouldNotSetReturnException:找不到一個電話從返回。
該消息繼續謹慎試圖用實際的類來做到這一點,但這並不適用於我。
我試圖改變我的null
PARAMS要的東西更真實:
ExecuteStoredProcedure<MyCustomReturnType>("", new Tuple<string, object>[]{null})
但是這並沒有幫助...
任何想法,我做錯了這個替代品?
(我的猜測是,它有事情做與params
關鍵字)。
本示例使用最新的NSub發行版:https://gist.github.com/dtchepak/05179a90ad59623b21b3您可以發佈該測試與代碼之間的任何差異嗎? –
感謝您的工作代碼。讓我意識到這是我的靜態類(該名單)沒有在通話之前設置。 (請參閱我的答案以獲取更多詳細信息。) – Vaccano