Skip to content

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

Closed as not planned
@mjamro

Description

@mjamro

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions