我在[TestInitialize]
var classHelper = new classHelper(mockSessionRepository.Object, new SecurityTokenAgent(), AuthorityReporting.Instance, new UserClientProcessor());
locationRepo = new LocationRepo(mockXmlReader.Object, classHelper);
我想到了classHelper
我会做的事情:
mockClassHelper = new Mock<IClassHelper>(mockSessionRepository.Object, new SecurityTokenAgent(), AuthorityReporting.Instance, new UserClientProcessor());
locationRepo = new LocationRepo(mockXmlReader.Object, mockSecurityHelper.Object);
这似乎是合乎逻辑的,它似乎也打破了我的所有[TestMethods]
。
请赐教,如果这是合乎逻辑的?
编辑:位置回复
internal LocationRepo(IXmlReader xmlReader, IClassHelper classHelper)
{
this.xmlReader = xmlReader;
this.classHelper = classHelper;
this.Init();
}
/// <summary>
/// Prevents a default instance of the <see cref="LocationRepo" /> class from being created.
/// </summary>
private LocationRepo() : this(new XmlReader(), new ClassHelper()){ }
答案 0 :(得分:3)
接口没有构造函数,因此您不需要将参数传递给它,因此要创建模拟到IClassHelper
,只需执行此操作:< / p>
var mockClassHelper = new Mock<IClassHelper>();
这是使用界面的精彩世界。