Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit support for matching cancellation tokens with It class. (It.IsCancellationToken()) #1477

Open
1 task done
mjamro opened this issue May 5, 2024 · 0 comments
Open
1 task done

Comments

@mjamro
Copy link

mjamro commented May 5, 2024

Category

  • 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).
  • It class is static, so you cannot add an extension method with similar behaviour on your own.

Back this issue
Back this issue

@mjamro mjamro changed the title Adding support for matching cancellation tokens with It class. (It.IsCancellationToken()) Explicit support for matching cancellation tokens with It class. (It.IsCancellationToken()) May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant