-
Notifications
You must be signed in to change notification settings - Fork 7
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
NS5000 when checking if an event subscription was received. #202
Comments
@dtchepak I am trying to add valid test case for this scenario and I came up with this using NSubstitute;
using System;
using Xunit;
namespace MyNamespace
{
public class Foo
{
public event Action SomeEvent;
}
public class FooTests
{
[Fact]
public void Test()
{
var substitute = NSubstitute.Substitute.For<Foo>();
substitute.Received().SomeEvent += Arg.Any<Action>();
}
}
} However, this test passes, even though SomeEvent was not fired - according to docs |
This is because the member is not virtual. Running multiple tests including this one gives me:
If it is
|
Ahh right. I dont know why I thought that events were handled differently. Will update my PR accordingly |
…iption GH-202 - do not report NS500 for event subscriptions
Can you release an update with this fix to NuGet, please? |
Since Version 1.0.16 the analyzer rule NS5000 alerts code like:
sub.Received(1).PropertyChanged += MyPropertyChangedHandler;
ErrorMessage:
NS5000: Unused received check. To fix, make sure there is a call after "Received". Correct: "sub.Received().SomeCall();". Incorrect: "sub.Received();"
The text was updated successfully, but these errors were encountered: