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

Moq's ReturnsAsync() returns the Result's Value when Result.Created(...) is used. #214

Open
CloudCees opened this issue Oct 10, 2024 · 0 comments

Comments

@CloudCees
Copy link

CloudCees commented Oct 10, 2024

Hello,

I try to return a Result.Created(Result.Success()) via a ReturnsAsync with Moq as follows:

        var r2 = Result.Created(Result.Success());
        _mockService2
            .Setup(x => x.SyncAsync(It.IsAny<Company>(), It.IsAny<Contact>()))
            .ReturnsAsync(r2);

But when the Mock is executed in the system under test then the Value of r2 is returned. So in this case the Mocked object is returning Result.Success().

To make it clear, if I would change r2 to Result.Created(null), then a null value is returned.

On the otherhand,

        _mockService
            .Setup(x => x.SyncAsync(It.IsAny<Company>(), It.IsAny<Contact>()))
            .ReturnsAsync(Result.Error());

works like a charm. Then the Result.Error is nicely returned by the Mocked object.

I have some feeling that the implicit operators are at work with this problem but I cannot put the finger on it...

Please let me know if you need some extra clarification.

@CloudCees CloudCees changed the title Moq' Moq's ReturnsAsync() returns the Result's Value when Result.Created(...) is used. Oct 10, 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