Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.

Conversation

@kzu
Copy link
Member

@kzu kzu commented Oct 28, 2020

We added the parameterless mock.Setup() to make it more discoverable how to switch the entire mock(s) to setup mode so the invocation tracking and recording and strict mock validation doesn't kick in, while you still get to use the lamba-free way of setting things up.

That pattern, however, could be confusing and lead you to believe you need one such Setup() call for every mock being set up in the using block. This is not the case: the setup scope is active for the entire call-context/thread, so there's no need for the method to be called on a particular instance of one mock.

This analyzer and codefix makes this more obvious and also introduces users to the Syntax static helper, which should make the test code also much more succint since it has optimized members for shorter syntax (i.e. for Verify, Raise, Any/Not and so on). Notice the added using static Moq.Syntax; at the top of the file when the codefix is applied:

SimplifySetup

The added helpers are mostly brought as-is from Stunts, but with a simplified folder structure for individual analyzer codes.

We added the parameterless `mock.Setup()` to make it more discoverable how to switch the entire mock(s) to setup mode so the invocation tracking and recording and strict mock validation doesn't kick in, while you still get to use the lamba-free way of setting things up.

That pattern, however, could be confusing and lead you to believe you need one such Setup() call for every mock being set up in the using block. This is not the case: the setup scope is active for the entire call-context/thread, so there's no need for the method to be called on a particular instance of one mock.

This analyzer and codefix makes this more obvious and also introduces users to the Syntax static helper, which should make the test code also much more succint since it has optimized members for shorter syntax (i.e. for Verify, Raise, Any/Not and so on).

The added helpers are mostly brought as-is from Stunts, but with a simplified folder structure for individual analyzer codes.
@kzu kzu merged commit 8961830 into main Oct 28, 2020
@kzu kzu deleted the dev branch October 28, 2020 06:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants