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

Mocking dependency with in keyword parameter does not match #1292

Closed
khurd21 opened this issue Oct 5, 2022 · 1 comment
Closed

Mocking dependency with in keyword parameter does not match #1292

khurd21 opened this issue Oct 5, 2022 · 1 comment

Comments

@khurd21
Copy link

khurd21 commented Oct 5, 2022

I have an interface:

public interface ILogbookService
{
    IEnumerable<LoggedJump> ListJumps(in int uspaMembershipNumber, in int from, in int to);
    LoggedJump LogJump(in LoggedJump jump);
    LoggedJump EditJump(in LoggedJump jump);
    LoggedJump DeleteJump(in LoggedJump jump);
}

And in my test case:

this.LogbookServiceMock.Setup(x => x.LogJump(It.IsAny<LoggedJump>()))
            .Returns(loggedJump)
            .Verifiable();

LogbookController controller = new(this.LoggerMock.Object, this.LogbookServiceMock.Object);

// Act
var result = await controller.LogJump(new LogJumpRequest());

/* ... */

this.LogbookServiceMock.Verify();

The Setup will not match in this scenario. When looking into why, I found that if I change the interface to not contain the in keyword, the match works as expected. Is this an expected behavior?

With this interface it works as expected:

public interface ILogbookService
{
    IEnumerable<LoggedJump> ListJumps(in int uspaMembershipNumber, in int from, in int to);
    LoggedJump LogJump(LoggedJump jump);
    LoggedJump EditJump(LoggedJump jump);
    LoggedJump DeleteJump(LoggedJump jump);
}
@khurd21
Copy link
Author

khurd21 commented Oct 5, 2022

Never fails after you post something, you find an answer.

I replaced It.IsAny<LoggedJump>() with It.Ref<LoggedJump>.IsAny and it works as expected.

@khurd21 khurd21 closed this as completed Oct 5, 2022
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