-
Notifications
You must be signed in to change notification settings - Fork 278
NSubstitute does not overrides private protected virtual methods #612
Copy link
Copy link
Closed
Labels
bugReported problem with NSubstitute behaviourReported problem with NSubstitute behaviour
Description
Describe the bug
NSubstitute does not overrides private protected virtual methods.
To Reproduce
using System.Runtime.CompilerServices;
using NSubstitute;
using NUnit.Framework;
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
namespace TestProject1
{
public class PrivateProtectedSpec
{
private protected virtual void PrivateProtectedVirtualMethod() => throw new Exception("I Was Called");
protected virtual void ProtectedVirtualMethod() => throw new Exception("I Was Called");
[Test]
public void TestPrivateProtectedCall() {
var system = Substitute.For<PrivateProtectedSpec>();
Assert.DoesNotThrow(() => system.ProtectedVirtualMethod(), "this one passes");
Assert.DoesNotThrow(() => system.PrivateProtectedVirtualMethod(), "this fails");
}
}
}
Expected behaviour
Calls on private protected virtual methods should not result in calls to the base type.
Environment:
- NSubstitute version: 4.2.1
- NSubstitute.Analyzers version: CSharp 1.0.12
- Platform: netcoreapp3.1 win64
Additional context
<PackageReference Include="NUnit" Version="3.8.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugReported problem with NSubstitute behaviourReported problem with NSubstitute behaviour