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

Not possible to Substitute.For(new[] { typeof(ISomething) }, null) in 4.3.0 #685

Closed
appel1 opened this issue Mar 3, 2022 · 5 comments
Closed

Comments

@appel1
Copy link
Contributor

appel1 commented Mar 3, 2022

private static bool HasItems<T>(T[]? array) => array?.Length != 0;

It was changed from:

private static bool HasItems<T>(T[]? array)
{
    return array != null && array.Length > 0;
}

to

private static bool HasItems<T>(T[]? array) => array?.Length != 0;

Those two statements behave differently if array is null. The old code resulted in false but the new code returns true in this case. I don't think that was an intentional change?

  Message: 
NSubstitute.Exceptions.SubstituteException : Can not provide constructor arguments when substituting for an interface.

  Stack Trace: 
CastleDynamicProxyFactory.VerifyNoConstructorArgumentsGivenForInterface(Object[] constructorArguments)
CastleDynamicProxyFactory.CreateProxyUsingCastleProxyGenerator(Type typeToProxy, Type[] additionalInterfaces, Object[] constructorArguments, IInterceptor[] interceptors, ProxyGenerationOptions proxyGenerationOptions)
CastleDynamicProxyFactory.GenerateTypeProxy(ICallRouter callRouter, Type typeToProxy, Type[] additionalInterfaces, Object[] constructorArguments)
CastleDynamicProxyFactory.GenerateProxy(ICallRouter callRouter, Type typeToProxy, Type[] additionalInterfaces, Object[] constructorArguments)
SubstituteFactory.Create(Type[] typesToProxy, Object[] constructorArguments, Boolean callBaseByDefault)
SubstituteFactory.Create(Type[] typesToProxy, Object[] constructorArguments)
Substitute.For(Type[] typesToProxy, Object[] constructorArguments)

Changing it to this should fix it:

private static bool HasItems<T>(T[]? array) => array?.Length > 0;
@appel1
Copy link
Contributor Author

appel1 commented Mar 3, 2022

Had missed that there already was a pull request for this:
#683

@AlexVallat
Copy link

This is also the cause of MRCollective/AutofacContrib.NSubstitute#65

@dtchepak
Copy link
Member

NSubstitute 4.4.0 should include the fix for this. Could you please confirm?

@rcdailey
Copy link

Upgraded to v4.4.0 and ran all my tests; I'm not able to reproduce this issue anymore.

rcdailey added a commit to recyclarr/recyclarr that referenced this issue Aug 23, 2022
@304NotModified
Copy link
Contributor

Upgraded to v4.4.0 and ran all my tests; I'm not able to reproduce this issue anymore.

Great! Then I will close this as done :)

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

No branches or pull requests

5 participants