Skip to content

Commit

Permalink
Add more tests for default interface property impls
Browse files Browse the repository at this point in the history
  • Loading branch information
stakx committed Aug 31, 2023
1 parent 2b2e97e commit 1b6cb2c
Showing 1 changed file with 87 additions and 2 deletions.
Expand Up @@ -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<InheritsMethodWithDefaultImplementation>(interceptor);
Expand All @@ -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<IHaveMethodWithDefaultImplementation>(interceptor);
Expand All @@ -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<InheritsPropertyWithDefaultImplementation>();
}

[Test]
public void Can_proxy_interface_with_property_with_default_implementation()
{
_ = generator.CreateInterfaceProxyWithoutTarget<IHavePropertyWithDefaultImplementation>();
}

[Test]
public void Default_implementation_gets_called_when_property_not_intercepted_in_proxied_class()
{
var options = new ProxyGenerationOptions(new ProxyNothingHook());
var proxy = generator.CreateClassProxy<InheritsPropertyWithDefaultImplementation>(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<IHavePropertyWithDefaultImplementation>(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<InheritsPropertyWithDefaultImplementation>(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<IHavePropertyWithDefaultImplementation>(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<InheritsPropertyWithDefaultImplementation>(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<IHavePropertyWithDefaultImplementation>(interceptor);
var expected = "default implementation";
var actual = proxy.PropertyWithDefaultImplementation;
Assert.AreEqual(expected, actual);
}

[Test]
public void Can_proxy_interface_with_sealed_method()
{
Expand All @@ -120,6 +192,17 @@ string MethodWithDefaultImplementation()
}
}

public interface IHavePropertyWithDefaultImplementation
{
string PropertyWithDefaultImplementation
{
get
{
return "default implementation";
}
}
}

public interface IHaveSealedMethod
{
sealed string SealedMethod()
Expand All @@ -129,6 +212,8 @@ sealed string SealedMethod()
}

public class InheritsMethodWithDefaultImplementation : IHaveMethodWithDefaultImplementation { }

public class InheritsPropertyWithDefaultImplementation : IHavePropertyWithDefaultImplementation { }
}
}

Expand Down

0 comments on commit 1b6cb2c

Please sign in to comment.