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

[FeatureRequest] Allow setting the default MockBehavior constructor parameter value #1537

Open
obones opened this issue Feb 26, 2025 · 0 comments

Comments

@obones
Copy link

obones commented Feb 26, 2025

In our existing code base, we have lots of mocks, some being created specifically with MockBehavior.Strict as their constructor parameter, but most with the parameterless constructor which implies calling with MockBehavior.Default.

While the current situation is fine, we would like to experiment setting all mocks to Strict mode and were looking for a way to globally say Default is Strict in our project(s) instead of the current Default is Loose.

This is not possible at the moment, mostly because MockBehavior defines Default = Loose

If this was changed so that Default has its own distinct value, the constructor could then do something like this:

this.behavior = (behavior == MockBehavior.Default) ? GlobalDefaultMockBehavior : behavior;

Where GlobalDefaultMockBehavior has MockBehavior.Loose by default but can be changed by a method yet to be written. Setting it via a flag in the assembly definition would be nice.

Obviously, any new value set into GlobalDefaultMockBehavior has no impact on existing Mock<T> instances, and thread safety of such a global value is nonexistent and should be documented as such.

I have seen Issue #1230 but I believe the request here is not for the same use case.

Back this issue
Back this issue

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