Using Moq to mock an asynchronous method for a unit test

前端 未结 3 925
北海茫月
北海茫月 2020-11-30 18:44

I am testing a method for a service that makes a Web API call. Using a normal HttpClient works fine for unit tests if I also run the web service (l

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 19:31

    Recommend @Stuart Grassie's answer above.

    var moqCredentialMananger = new Mock();
    moqCredentialMananger
                        .Setup(x => x.GetCredentialsAsync(It.IsAny()))
                        .ReturnsAsync(new Credentials() { .. .. .. });
    

提交回复
热议问题