-
-
Notifications
You must be signed in to change notification settings - Fork 801
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
Cannot mock subclass of superclass with internal virtual methods #991
Comments
Interesting. I can't tell you right away why that happens, but I can tell you that the problem happens in the infrastructure below Moq, not in Moq itself. I've opened a bug report over at the DynamicProxy repository (castleproject/Core#488). I'll close your issue here, since there's nothing we can do in Moq. P.S.: Some more info in the Castle.Core issue that might be useful to you. |
I closed this too early... sorry. Let's close this once we've updated to a new version of DynamicProxy that contains a fix for this. |
Thanks for the quick response! I see now why I couldn't reproduce it locally, as it was a little more complicated than I gave it credit for. |
Ran across this today, did anyone find a way around this or did they have to redesign the clients that are inheriting from those types of base classes? |
I'm running in to the same problem trying to create a mock for a named subclass of Azure DataLakeServiceClient. Inner Exception 1: |
I just ran into this same issue with one of my own classes.
This is in a .NET 6 project...I might not have made internals visible in the correct way. There's no Assembly.cs file anymore and I couldn't find much info on how to do this in .NET 6 except for the following (which may not be correct) MyProject.csproj
UPDATE MyProject.csproj
I also found that as of .NET 5 and higher, the following also works (source: here): MyProject.csproj
|
I have had some serious code rage with this issue. Any workarounds for when you need to create a subclass like OP has? My issue is when I try create a subclass of |
I'm getting the same issue when I try create a subclass of |
Due to lack of recent activity, this issue has been labeled as 'stale'. |
Unfortunately, this bug report is a little confusing, as I have tried multiple times to create a small reproducible example, but I am unable to.
I'm trying to make a mock of the Azure BlockBlobClient
This works fine, I can easily execute
However, if I subclass the BlockBlobClient, everything goes wrong, even if the subclass does nothing.
I then get the following error:
It seems like Moq is trying to mock the
internal virtual
methodPipeline
in the BlobBaseClient, which the BlockBlobClient inherits from.Seeing as the method is internal and in another assembly, I cannot override it. However if I define a property with the same name, ala:
I get the same error, but with the next
internal virtual
propertywhich is also a property on the superclass
So my theory is that there's something that's going on with the internal virtual properties, but only in a subclass of a subclass in another assembly.
Unfortunately, I cannot reproduce the problem, if I try to mimick the same thing locally (e.g. create two assemblies and the same internal virtual structure). I'm not sure if this is a Windsor or a Moq problem either.
The text was updated successfully, but these errors were encountered: