Stubbing Task returning method in async unit test

前端 未结 2 1030
闹比i
闹比i 2021-01-01 12:00

Let\'s say I have the following class and an interface it depends on:

public class MyController
{
    private IRepository _repository;
    public MyControlle         


        
2条回答
  •  余生分开走
    2021-01-01 12:42

    You will need to return something; async Task methods cannot ever return null.

    The T doesn't matter. You could declare a static readonly Task SuccessTask = Task.FromResult(null); as a helper constant if you want. I have similar constants in my AsyncEx library.

    提交回复
    热议问题