-
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
Detect substituting for internal
members without InternalsVisibleTo
#66
Comments
@dtchepak regarding diagnostic message for new analyzer, do you think this is enough When it comes to the diagnostic id, I think this could be another And the last one question, for non-virtual substitution we have three different diagnostics one for Returns, second for Received and third for When like methods - should we go with same convention for internal members detection as well? |
Maybe I agree I'm not sure for your last question. Is a single diagnostic easier to implement? Only advantages I can think of for separate are following convention, and allowing finer grained suppression. Neither of those is that compelling, so if a single one is easier to implement, then I'd lean towards that. Also I think this will be less common that the non-virtual case (if that makes a difference). |
same diagnostic id for all internal analyzers
@dtchepak single vs multiple diagnostic is more or less the same effort. I was rather wondering if it is worth to use multiple diagnostics in this particular case. But after all, I decided to go with one diagnostic only |
…al-members Gh 66 substituting for internal members
From nsubstitute/NSubstitute#496, having a test assembly with visibility of internal members of assembly under test, but without
InternalsVisibleTo("DynamicProxyGenAssembly2")
, causes errors when running the tests.It would be good to catch this case, similar to NS2003.
From Robert's comment on NSubstitute@496:
The reproduction on that issue is a good test case to illustrate the problem (just having a type with internal members local to the test assembly with trigger the issue).
I'm not sure what category this should belong to. Could be
NS5xxx
as a general usage problem, although it is also sort of similar toNS1xxx
which covers non-virtual substitution, although in this case it is a non-substitutable member due tointernal
. The easiest is probably to put it inNS5xxx
, but maybe we should also consider adapting theNS1xxx
category to be something to do with "non-substitutable members" and include this?Draft rule page:
NS2003
Cause
Substituting for an internal member of a class without proxies having visibility into internal members.
Rule description
A violation of this rule occurs when using NSubstitute features like
Returns()
,Received()
etc. with an internal member of a class, but without giving NSubstitute's proxy assembly access to internal members.How to fix violations
There are several ways to fix this:
internal
topublic
internal
toprotected internal
DynamicProxyGenAssembly2
using:How to suppress violations
...
The text was updated successfully, but these errors were encountered: