我正在尝试为旧系统编写一些单元测试。 认为我有一个基类和这样的服务:
public class BaseService
{
[Dependency]
public IBaseInterface _mybaseInterface { get; set; }
}
public class MyService : BaseService, IMyService
{
private readonly ISomeOtherInterface _myOtherInterface;
public MyService(ISomeOtherInterface myOtherInterface)
{
_myOtherInterface = myOtherInterface;
}
}
public class MyOtherService
{
private readonly IMyService _myservice;
public MyService(IMyService myservice)
{
_myservice = myservice
}
}
问题1: 我正在为MyOtherService类编写测试,并且必须模拟IMyservice,但我不知道如何模拟基本类中的接口。
问题2: 将BaseService的注入转换为构造函数注入是否可以帮助我模拟Myservice类依赖关系?