Expected: the property to be proxied but not intercepted.
Actual: the property is generated in the proxy but does not pass the value to the underlying instance
public class TestCacheProxyGenerationHook : AllMethodsHook
{
public override bool ShouldInterceptMethod(Type type, MethodInfo methodInfo)
{
return false;
}
}
public interface ITestCacheInterface
{
int InstanceProperty { get; set; }
}
public class TestClassForCache : ITestCacheInterface
{
public virtual int InstanceProperty { get; set; }
}
[Fact]
public async Task DynamicProxy_NonIntercepted_Property_Leaked()
{
var instance = new TestClassForCache();
var toProxy = instance.GetType();
var proxyGenerationOptions = new ProxyGenerationOptions(new TestCacheProxyGenerationHook());
var generator = new ProxyGenerator();
var proxy = generator.CreateClassProxyWithTarget(toProxy,
instance,
proxyGenerationOptions);
var accessor = (ITestCacheInterface)proxy;
accessor.InstanceProperty = 1;
Assert.Equal(accessor.InstanceProperty, instance.InstanceProperty); // Fails here 1 != 0
}