I have a function here that is for getting the logs in the queue. How can I mock this function for unit testing ?
void QueueBackgroundWorkItem(Func<CancellationToken, IServiceProvider, Task> workItem);
Mock<IBackgroundTaskQueue> _Mock= new Mock<IBackgroundTaskQueue>();
_Mock.Setup(x=>x.QueueBackgroundWorkItem(?)).Returns(Task.CompletedTask);
Thank you.
2
Answers
One way to mock such method, if you are not testing a specific parameter, is to use an
It.IsAny
:QueueBackgroundWorkItem
returnsvoid
so just setup withIt.IsAny
: