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

Replace Moq #1470

Closed
martincostello opened this issue Aug 9, 2023 · 6 comments · Fixed by #1472
Closed

Replace Moq #1470

martincostello opened this issue Aug 9, 2023 · 6 comments · Fixed by #1472
Assignees
Labels
Milestone

Comments

@martincostello
Copy link
Member

Given recent developments with Moq as of version 4.20.0, we should remove it and replace with another library.

NSubstitue seems like a good substitue.

I'm going to work on this today unless someone has any strong opinions about an alternative library to use in its place.

@martincostello martincostello added this to the v8.0.0 milestone Aug 9, 2023
@martincostello martincostello self-assigned this Aug 9, 2023
@martincostello martincostello moved this to In Progress in Polly v8 Aug 9, 2023
@martintmk
Copy link
Contributor

Are there any plans to fork the Moq?
Maybe in the meantime, we can freeze the versions and wait for some "official forked package".

I have not used NSubstitute personally, so I can't comment on that. It seems some folks find it cleaner compared to Moq.

If the switch is straightforward, we can get away with that.

@adamnova
Copy link
Contributor

adamnova commented Aug 9, 2023

There is already an issue for creating a migration tool: nsubstitute/NSubstitute#720

I would probably wait and see in this case, how it develops. The latest version of Moq no longer has that dependency, so I would say it's not immediate concern.

@martincostello
Copy link
Member Author

Thanks for the link, I'll bear that in mind for the future. I have however just finished locally converting the code over 😅

martincostello added a commit to martincostello/Polly that referenced this issue Aug 9, 2023
Remove Moq and replace with NSubstitute.
Resolves App-vNext#1470.
@adamnova
Copy link
Contributor

adamnova commented Aug 9, 2023

I am looking at the PR and to be honest, I like the syntax more than Moq. Never used NSubstitute before.

martincostello added a commit that referenced this issue Aug 9, 2023
Remove Moq and replace with NSubstitute.
Resolves #1470.
@github-project-automation github-project-automation bot moved this from In Progress to Done in Polly v8 Aug 9, 2023
@lucasgarciadev22
Copy link

Hello, I'm worried about this situation, we use Moq in my company and I'm willing to replace it ASAP. Is NSubistitute safe and easy to migrate from Moq?

Thanks !

@martincostello
Copy link
Member Author

This specific code base maybe took me about an hour, others have taken 15 minutes, others still I stopped and reverted the changes and I'll tackle them another time.

From my experiences today, it seems to mostly be a function of how much you use functionality like Verify() in Moq. The more you use that, the more work a migration is.

In the simplest cases, it's just a matter of a change like this:

- var thing = Mock.Of<Thing>();
+ var thing = Substitute.For<Thing>();

The more coupled your tests are to verifying the behaviour of the underlying code through Mock, then the more effort the migration appears to be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants