|
想请教一下,对于泛型接口怎么用mock进行模拟测试呢?比如对下面的接口:
public interface IDbEntity : IEntity
{
string PrimaryKey { get; }
string XmlDataSource { get; set; }
}
public interface IDbEntityUtility<T> where T : IDbEntity
{
IList<string> AddEntities(params T[] entities);
bool SetEntities(params T[] entities);
T GetEntity(string id);
IList<T> GetEntities();
bool DeleteEntities();
bool DeleteEntities(params string[] ids);
}
我写的测试代码如下:
var mockIDbEntityUtility = new Mock<IDbEntityUtility<IDbEntity>>();
mockIDbEntityUtility.Setup(idbEntityUtility => idbEntityUtility.AddEntities(T[])).Returns("returnresult");
mockIDbEntityUtility.Setup(idbEntityUtility => idbEntityUtility.SetEntities(T[])).Returns(true);
return mockIDbEntityUtility.Object;
可是无论怎么写都有语法错误,我对C#不上很熟悉,泛型和mock都是刚刚接触,这两个搞到一起就昏头了,有没有好心人能指点一二?感激不尽~~ |
|