-
Notifications
You must be signed in to change notification settings - Fork 278
NSubstitute public virtual get internal set property not being auto substituted? #626
Description
I am attempting to substitute a class with a public virtual IThing Thing { get; internal set; } property and was expecting it to behave like a fully public property in terms of how NSubstitute automatically ties the get and the set together, but it doesn't seem to do that and I don't understand why. Is it expected behavior or could it be a bug, or enhancement?
To Reproduce
// in production code assembly
public interface IThing {}
internal class Example
{
public virtual IThing Thing { get; internal set; }
}
// in test assembly
[Test]
public void Test()
{
var thing = Substitute.For<IThing>();
var ex = Substitute.For<Example>();
ex.Thing = thing;
ex.Thing.ShouldBe(thing); // throws exception because the proxies are not the same
}
Expected behaviour
I was expecting that assertion to pass, but instead it throws because there are two different proxy instances there. The only arrangement that works as I was expecting is if the Thing property is public virtual {get; set; }, every other combination I've tried fails the same way.
Environment:
- NSubstitute version: 4.2.2
- NSubstitute.Analyzers version: CSharp 1.0.13
- Platform: .NET 4.8
Additional context
The production assembly under test has it's AssemblyInfo.cs set up with InternalsVisibleTo the test assembly AND [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]