我有以下接口。由於T是通用的,我不確定如何使用Moq來模擬IRepository。我確信有一種方法,但我沒有通過在這裏或谷歌搜索找到任何東西。有人知道我能做到嗎?使用moq來模擬具有通用參數的類型
我對Moq相當陌生,但可以看到花時間學習它的好處。
/// <summary>
/// This is a marker interface that indicates that an
/// Entity is an Aggregate Root.
/// </summary>
public interface IAggregateRoot
{
}
/// <summary>
/// Contract for Repositories. Entities that have repositories
/// must be of type IAggregateRoot as only aggregate roots
/// should have a repository in DDD.
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IRepository<T> where T : IAggregateRoot
{
T FindBy(int id);
IList<T> FindAll();
void Add(T item);
void Remove(T item);
void Remove(int id);
void Update(T item);
void Commit();
void RollbackAllChanges();
}