-
Notifications
You must be signed in to change notification settings - Fork 268
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
NSubstitute/Castle proxy fail to create substitute that returns a derived class from abstract that satisfies interface implicitly #730
Comments
Also note, using Moq, there is no issue with this: public void CreateTest()
{
var a = new Mock<ConcreteIOContext>();
a.Setup(x => x.CreateDirectoryInfo()).Returns(new XDirectoryInfo());
} |
I lied. It seems to be an issue with namespace TestNSubstituteBS
{
public class ConcreteIOContext : AbstractIOContext
{
// public override XDirectoryInfo CreateDirectoryInfo() => new XDirectoryInfo(); <-- does not work
public override IDirectoryInfo CreateDirectoryInfo() => new XDirectoryInfo(); // <--- this does work
}
} The code above now makes it work without any issue. |
It seems that from castleproject/Core#659 (comment) that the issue has been resolved with a later version of Castle.Core supporting C# 9 covariants (which would hopefully be my issue). So maybe update Castle.Core to a version greater than 5.1.0? |
Thanks @siblount . I've updated Castle.Core in the MR readying next release: #731 There's an appveyor build if you want to try it out: https://ci.appveyor.com/project/NSubstitute/nsubstitute/builds/47889349/artifacts |
Tried out the CI build and I'm glad to say that the issue no longer persists. Thanks @dtchepak, closing this. |
Describe the bug
NSubstitute/Castle proxy fails to create a substitute for a concrete class that derives from an abstract class and virtual members.
To Reproduce
Here's an example of what I am talking about:
Setup classes
Test code:
Running the above returns this error message...
and stack trace...
Expected behaviour
Preferibly, that it works. Otherwise, an error message about how much of an idiot I am.
Environment:
Additional context
This occurs for
Substitute.For<>()
andSubstitute.ForPartsOf<>()
.The text was updated successfully, but these errors were encountered: