How to moq a static class with a static method (UnitOfWork case)?
问题 I have these classes: public static class UnitOfWorkSS { public static IUnitOfWork Begin() { return IoC.Resolve<IUnitOfWork>(); } } public class PostService { using (IUnitOfWork unitOfWork = UnitOfWorkSS.Begin()) { //don't forget to sanitize html content htmlContent = _htmlSanitizer.Sanitize(htmlContent); IPost post = _factory.CreatePost(byUser, title, htmlContent); _postRepository.Add(post); unitOfWork.Commit(); } } How can I mock the classes UnitOfWorkSS and unitOfWork ? 回答1: It looks like