-
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
NS3002 false positive when nested returns #150
Comments
Hi @andrewdmoreno using System.Collections.Generic;
using NSubstitute;
namespace TestProject6
{
public class FooTests
{
public void Test()
{
var provider = Substitute.For<IOptionProvider>();
provider
.GetOptions(Arg.Any<EnrollmentDetail>())
.Returns(_ =>
{
var enrollment = _.Arg<EnrollmentDetail>();
return new List<OptionSummary>();
});
}
}
public interface IOptionProvider
{
List<OptionSummary> GetOptions(EnrollmentDetail enrollment);
}
public class OptionSummary
{
}
public class EnrollmentDetail
{
}
} no warnings were reported with
Can you provide small solution with repro? |
Thanks @tpodolak. I will double check both package versions and see if I can repro it in a smaller solution. |
@tpodolak At first I could not repro in a fresh solution so I started looking at what else was unique about the setup and was finally able to repro. I reduced it down to the minimum needed to repro. Basically it was only when I introduced the public class FooTests
{
public void Test()
{
var providerFactory = Substitute.For<IProviderFactory>();
providerFactory.GetProvider().Returns(info =>
{
var provider = Substitute.For<IOptionProvider>();
provider
.GetOptions(Arg.Any<string>())
.Returns(_ =>
{
// Warning NS3002 Can not find an argument of type string to this call.
var input = _.Arg<string>();
return new List<string> {input};
});
return provider;
});
}
}
public interface IProviderFactory
{
IOptionProvider GetProvider();
}
public interface IOptionProvider
{
List<string> GetOptions(string input);
} |
@andrewdmoreno Thanks for taking the time to refine the reproduction case! @tpodolak I'm guessing the issue is the nested |
Now that we know that the nested public class FooTests
{
public void Test()
{
var provider = Substitute.For<IOptionProvider>();
provider
.GetOptions(Arg.Any<string>())
.Returns(_ =>
{
var input = _.Arg<string>();
return new List<string> {input};
});
var providerFactory = Substitute.For<IProviderFactory>();
providerFactory.GetProvider().Returns(provider);
}
}
public interface IProviderFactory
{
IOptionProvider GetProvider();
}
public interface IOptionProvider
{
List<string> GetOptions(string input);
} However, I imagine there could be valid use cases for having nested |
#118 was closed so did not want to add onto it, however, I am running into this issue still.
IOptionProvider:
I tried with versions
1.0.11
,1.0.13
, and1.0.14
. Am I doing something wrong possibly?The text was updated successfully, but these errors were encountered: