diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/DefaultInterfaceMembersTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/DefaultInterfaceMembersTestCase.cs index 0be67095e..f623425da 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/DefaultInterfaceMembersTestCase.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/DefaultInterfaceMembersTestCase.cs @@ -78,7 +78,7 @@ public void Can_intercept_method_with_default_implementation_in_proxied_interfac } [Test] - public void Can_proceed_to_default_implementation_in_proxied_class() + public void Can_proceed_to_method_default_implementation_in_proxied_class() { var interceptor = new WithCallbackInterceptor(invocation => invocation.Proceed()); var proxy = generator.CreateClassProxy(interceptor); @@ -88,7 +88,7 @@ public void Can_proceed_to_default_implementation_in_proxied_class() } [Test] - public void Can_proceed_to_default_implementation_in_proxied_interface() + public void Can_proceed_to_method_default_implementation_in_proxied_interface() { var interceptor = new WithCallbackInterceptor(invocation => invocation.Proceed()); var proxy = generator.CreateInterfaceProxyWithoutTarget(interceptor); @@ -97,6 +97,78 @@ public void Can_proceed_to_default_implementation_in_proxied_interface() Assert.AreEqual(expected, actual); } + [Test] + public void Can_proxy_class_that_inherits_property_with_default_implementation_from_interface() + { + _ = generator.CreateClassProxy(); + } + + [Test] + public void Can_proxy_interface_with_property_with_default_implementation() + { + _ = generator.CreateInterfaceProxyWithoutTarget(); + } + + [Test] + public void Default_implementation_gets_called_when_property_not_intercepted_in_proxied_class() + { + var options = new ProxyGenerationOptions(new ProxyNothingHook()); + var proxy = generator.CreateClassProxy(options); + var expected = "default implementation"; + var actual = ((IHavePropertyWithDefaultImplementation)proxy).PropertyWithDefaultImplementation; + Assert.AreEqual(expected, actual); + } + + [Test] + public void Default_implementation_gets_called_when_property_not_intercepted_in_proxied_interface() + { + var options = new ProxyGenerationOptions(new ProxyNothingHook()); + var proxy = generator.CreateInterfaceProxyWithoutTarget(options); + var expected = "default implementation"; + var actual = proxy.PropertyWithDefaultImplementation; + Assert.AreEqual(expected, actual); + } + + [Test] + public void Can_intercept_property_with_default_implementation_in_proxied_class() + { + var expected = "intercepted"; + var interceptor = new WithCallbackInterceptor(invocation => invocation.ReturnValue = expected); + var proxy = generator.CreateClassProxy(interceptor); + var actual = ((IHavePropertyWithDefaultImplementation)proxy).PropertyWithDefaultImplementation; + Assert.AreEqual(expected, actual); + } + + [Test] + public void Can_intercept_property_with_default_implementation_in_proxied_interface() + { + var expected = "intercepted"; + var interceptor = new WithCallbackInterceptor(invocation => invocation.ReturnValue = expected); + var proxy = generator.CreateInterfaceProxyWithoutTarget(interceptor); + var actual = proxy.PropertyWithDefaultImplementation; + Assert.AreEqual(expected, actual); + } + + [Test] + public void Can_proceed_to_property_default_implementation_in_proxied_class() + { + var interceptor = new WithCallbackInterceptor(invocation => invocation.Proceed()); + var proxy = generator.CreateClassProxy(interceptor); + var expected = "default implementation"; + var actual = ((IHavePropertyWithDefaultImplementation)proxy).PropertyWithDefaultImplementation; + Assert.AreEqual(expected, actual); + } + + [Test] + public void Can_proceed_to_property_default_implementation_in_proxied_interface() + { + var interceptor = new WithCallbackInterceptor(invocation => invocation.Proceed()); + var proxy = generator.CreateInterfaceProxyWithoutTarget(interceptor); + var expected = "default implementation"; + var actual = proxy.PropertyWithDefaultImplementation; + Assert.AreEqual(expected, actual); + } + [Test] public void Can_proxy_interface_with_sealed_method() { @@ -120,6 +192,17 @@ string MethodWithDefaultImplementation() } } + public interface IHavePropertyWithDefaultImplementation + { + string PropertyWithDefaultImplementation + { + get + { + return "default implementation"; + } + } + } + public interface IHaveSealedMethod { sealed string SealedMethod() @@ -129,6 +212,8 @@ sealed string SealedMethod() } public class InheritsMethodWithDefaultImplementation : IHaveMethodWithDefaultImplementation { } + + public class InheritsPropertyWithDefaultImplementation : IHavePropertyWithDefaultImplementation { } } }