moq
moq copied to clipboard
Explicit support for matching cancellation tokens with It class. (It.IsCancellationToken())
Category
- [x] Feature request
Describe the feature
When mocking async methods that require a cancellation token you can use It.IsAny<CancellationToken>() syntax like this:
myMock.Setup(m => m.DoSomethingAsync(It.IsAny<CancellationToken>()));
I propose adding a new method to It class for matching cancellation tokens, that does exactly the same:
myMock.Setup(m => m.DoSomethingAsync(It.IsCancellationToken()));
Rationale:
- It's slightly more readable and less verbose than
It.IsAny<>syntax.. Readable code is good 👍 - Async methods are extremely common and mocking them is common as well.
- It's purely syntactic sugar. It breaks nothing.
- Code completion will be easier. Right now you need to do it in two steps (IsAny + CancellationToken in generic params).
Itclass is static, so you cannot add an extension method with similar behaviour on your own.
Due to lack of recent activity, this issue has been labeled as 'stale'. It will be closed if no further activity occurs within 30 more days. Any new comment will remove the label.
