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

[GH-135] - Detecting received like methods used in Received.InOrder #136

Merged
merged 1 commit into from
Feb 23, 2020

Conversation

tpodolak
Copy link
Member

@tpodolak tpodolak commented Feb 16, 2020

Closes #135

@coveralls
Copy link

coveralls commented Feb 16, 2020

Pull Request Test Coverage Report for Build 377

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.3%) to 95.553%

Files with Coverage Reduction New Missed Lines %
C/projects/nsubstitute-analyzers/src/NSubstitute.Analyzers.Shared/Extensions/SubstituteSymbolExtensions.cs 2 92.0%
Totals Coverage Status
Change from base Build 372: 0.3%
Covered Lines: 2213
Relevant Lines: 2316

💛 - Coveralls

@@ -0,0 +1,59 @@
# NS5001
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dtchepak as discussed nsubstitute/NSubstitute#604 (comment)
feel free to suggest better documentation and diagnostic id

Copy link
Member

@dtchepak dtchepak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor doc suggestions. Happy to merge as is. 👍

// Correct:
Received.InOrder(() =>
{
sub..Bar();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sub.Bar(); (one .)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


## Rule description

A violation of this rule occurs when
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion:

A violation of this rule occurs when any of the following are used inside Received.InOrder callback:

  • Received()
  • ReceivedWithAnyArgs()
  • DidNotReceive()
  • DidNotReceiveWithAnyArgs()

Calls within Received.InOrder are already checked to ensure they were received in the expected order. Individual received-like assertions should be moved outside the Received.InOrder block.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


For example:

````c#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be 3 ticks instead of 4? "```"? Never mind, just saw this renders fine with 4. I've just always used 3 😂

sub..Bar();
})
````

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, move the received-like method outside of Received.InOrder block:

// Incorrect:
Received.InOrder(() =>
{
    sub.Baz();
    sub.DidNotReceive().Bar();
})

// Correct:
Received.InOrder(() =>
{
    sub.Baz();
})
sub.DidNotReceive().Bar();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I aggregated these here: #135 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, copy-pasted your version

@tpodolak tpodolak force-pushed the GH-135-received-like-methods-in-receivedinorder branch from 3539311 to 675c135 Compare February 23, 2020 18:01
@tpodolak tpodolak merged commit dc84b2a into dev Feb 23, 2020
@tpodolak tpodolak deleted the GH-135-received-like-methods-in-receivedinorder branch February 23, 2020 19:37
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

Successfully merging this pull request may close these issues.

Detect usages of Received like methods in Received.InOrder block
3 participants