How to mock a web service

前端 未结 4 1566
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-25 13:09

Do I have to rewrite my code to do this into an interface? Or is there an easier way? I am using Moq

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-25 13:42

    there is an easy way. for example if we have WebService class with the name DbService, first create an interface for it (ex. IService), and use this interface for mocking, then add a class to your project and put this:

    public partial class DbService:IService {
    
    }
    

    leave class empty, because of web services are partial class we use this implementation. (previously

提交回复
热议问题