When unit testing, how do I mock a return null from async method?

前端 未结 3 1171
面向向阳花
面向向阳花 2021-02-18 20:45

Normally, I mock my repo like so:

var repository = new Mock();
repository.Setup(r => r.GetMemberAsync(email))
    .Returns(Task.FromResult         


        
3条回答
  •  無奈伤痛
    2021-02-18 21:13

    You get a compiler error because you return a task that doesn't match the type the async method returns. You should return Task instead of simply Task:

    repository.Setup(r => r.GetMemberAsync(email)).Returns(Task.FromResult(null));
    

    提交回复
    热议问题