How do you mock an IAsyncEnumerable?

后端 未结 4 1160
时光取名叫无心
时光取名叫无心 2020-12-20 13:23

I want to unit test a method that calls another method of a service returning an IAsyncEnumerable. I have created a a mock of my service Mock<

4条回答
  •  猫巷女王i
    2020-12-20 14:11

    It really depends on which mocking framework your using. But, it would be something simple like this example using Moq

    var data = new [] {1,2,3,4};
    var mockSvc = new Mock();
    mockSvc.Setup(obj => obj.CallSomethingReturningAsyncStream()).Returns(data.ToAsyncEnumerable());
    

提交回复
热议问题