51Testing软件测试论坛
标题:
请教关于mock的问题,各位xdjm帮帮忙
[打印本页]
作者:
红尾鱼鱼
时间:
2010-2-21 14:45
标题:
请教关于mock的问题,各位xdjm帮帮忙
想请教一下,对于泛型接口怎么用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都是刚刚接触,这两个搞到一起就昏头了,有没有好心人能指点一二?感激不尽~~
作者:
xieyang702
时间:
2011-6-1 11:01
偶也在学,不会耶
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2