2016-11-08 84 views
1

我想設置我發送的Dto的ID It.IsAny<int>()MOQ異步ID設置

如何設置?

 _service.Setup(x => x.GetDtoAsync(It.IsAny<int>())).ReturnsAsync(new Dto() 
     { 
      Id = ????? 
     }); 

回答

0

您可以使用Returns<T>(Func<T, TResult>)並返回一個完成Task

_service.Setup(x => x.GetDtoAsync(It.IsAny<int>())) 
    .Returns<int>(id => Task.FromResult(new Dto { Id = id }));