How to moq a static class with a static method (UnitOfWork case)?

后端 未结 4 2052
無奈伤痛
無奈伤痛 2021-02-08 02:10

I have these classes:

public static class UnitOfWorkSS 
{
  public static IUnitOfWork Begin()
  {
    return IoC.Resolve();
  }
}

public clas         


        
4条回答
  •  感情败类
    2021-02-08 02:50

    I realize this is a very old question, but in case someone ends up here...

    The best solution is a design change like the other answers say. However, if that's not possible, you can either use Microsoft Fakes (which replaced Moles) or, if you'd rather not depend on Visual Studio, there is a library called Smocks that can help.

    https://github.com/vanderkleij/Smocks

提交回复
热议问题