[FeatureRequest] Allow setting the default MockBehavior constructor parameter value
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.
Global statics are generally a bad idea IMHO. You could just create your own factory method you use throughout your test base to construct those mocks in a unified way, say Mocks.Create<T> where you get to define and control your static behavior as you see fit.
Makes sense?
I understand your point of view, but then what's the point of having a Default member in the enumeration?
As to your suggestion, it would require quite a discipline from all developers and code reviewers when a simple setting would alleviate this burden, even allowing for running with the default value changed in a "what if" situation.
Due to lack of recent activity, this issue has been labeled as 'stale'. It will be closed if no further activity occurs within 30 more days. Any new comment will remove the label.
This issue will now be closed since it has been labeled 'stale' without activity for 30 days.
