模拟内部类中受保护函数内的函数
特定函数 [ExecuteSelectQuery] 需要一个单元测试,恰好是这样的:
internal abstract class DataRequestProcessor
{
protected DataView ExecuteSelectQuery(SqlDataSource dataSource)
{
//do some stuff
// need to mock this function
}
}
internal class AccountDataRequestProcessor : DataRequestProcessor
{
public InfoClass GetSomeDetail(ApiRequest<object> apiRequest)
{
....
ExecuteSelectQuery(dataSource);
.....
}
}
我想使用 Interface,但 DataRequestProcessor 只是说更改保护级别。与我尝试在测试类中继承 AccountDataRequestProcessor 相同“不一致的可访问性基类比派生类更难访问”。当从类 [GetSomeDetail] 的单元测试中调用函数 [ExecuteSelectQuery] 时,有没有办法模拟它?我正在使用 xunit,带有 4.5.2 .net 框架,c# 7.3
There is a unit test required for a specific function[ExecuteSelectQuery] which happens to be as such:
internal abstract class DataRequestProcessor
{
protected DataView ExecuteSelectQuery(SqlDataSource dataSource)
{
//do some stuff
// need to mock this function
}
}
internal class AccountDataRequestProcessor : DataRequestProcessor
{
public InfoClass GetSomeDetail(ApiRequest<object> apiRequest)
{
....
ExecuteSelectQuery(dataSource);
.....
}
}
I thought of going with Interface but DataRequestProcessor simply says to change protection level. Same with if I try to inherit AccountDataRequestProcessor in test class "inconsistent accessibility base class is less accessible than derived class" . Is there a way to Mock the function[ExecuteSelectQuery] when it is called from unit test of class[GetSomeDetail] ? I am using xunit, with 4.5.2 .net framework , c# 7.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论