代码之家  ›  专栏  ›  技术社区  ›  pixel

沙马林。表单-单元测试使用Autofac的ServiceLocator的方法

  •  0
  • pixel  · 技术社区  · 6 年前

    我试图在我的系统中对一个方法进行单元测试 MyViewModel BaseViewModel 这个 BaseViewModel 有这样的方法吗

    protected bool DoSomething()
    {
       if (something)
       {
          ServiceLocator.Current.GetInstance ...; //ERROR
          return true;
       }
       else
       {
          return false;
       }
    }
    

    DoSomething 几乎在每个视图模型中都被称为。该应用程序按预期工作,但我正在尝试单元测试(NUnit)和调用的每个方法 剂量 就是单元测试失败

    我得到的错误是

    error CS0119: 'ServiceLocator' is a type, which is not valid in the given context
    

    这个 ServiceLocator 是从哪里来的 Autofac.CommonServiceLocator

    0 回复  |  直到 6 年前