2
我真的很努力地完成這項工作。我有一個通用的存儲庫模式,我需要使用Microsoft Fakes存根存儲庫接口。存根接口與帶謂詞的泛型方法
public interface IDataAccess<T> where T : class
{
void Add(T entity);
void Update(T entity);
void Delete(T entity);
void Delete(Expression<Func<T, bool>> where);
T FindById(long id);
T FindById(string id);
T Find(Expression<Func<T, bool>> where);
IEnumerable<T> FindAll();
IEnumerable<T> FindMany(Expression<Func<T, bool>> where);
IQueryable<T> Find(Expression<Func<T, bool>> predicate = null, params Expression<Func<T, object>>[] includes);
IQueryable<T> FindIncluding(params Expression<Func<T, object>>[] includeProperties);
}
試圖創建一個存根
IQueryable<T> Find(Expression<Func<T, bool>> predicate = null, params Expression<Func<T, object>>[] includes);
IQueryable<T> FindIncluding(params Expression<Func<T, object>>[] includeProperties);
,並在我的測試..
IDataAccess<EnterprisePermissionSet> dataAccess = new HG.Fus.Authentication.Data.Fakes.
StubIDataAccess<EnterprisePermissionSet>()
{
FindIncludingExpressionOfFuncOfT0ObjectArray =() => { };
};
我只是不知道如何構建這個存根,
你要模仿你在裏面尋找的行爲'{}' –
這是我在做什麼,但是也會不斷收到錯誤,我無法將源類型'Lambda表達式'轉換爲目標類型'IQueryable' –
JBeckton
好吧,閱讀我的答案,我將展示如何對這些方法進行存根... –