Skip to content

Commit

Permalink
Add tests for method default impls in mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
stakx committed Sep 1, 2023
1 parent 7e80e83 commit 23af447
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,57 @@ public void Can_proxy_interface_with_static_abstract_method()

#endregion

#region Mixins

[Test]
public void Can_intercept_method_with_default_implementation_from_mixin_in_proxied_class()
{
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new InheritsMethodWithDefaultImplementation());
var expected = "intercepted";
var interceptor = new WithCallbackInterceptor(invocation => invocation.ReturnValue = expected);
var proxy = generator.CreateClassProxy(typeof(object), options, interceptor);
var actual = ((IHaveMethodWithDefaultImplementation)proxy).MethodWithDefaultImplementation();
Assert.AreEqual(expected, actual);
}

[Test]
public void Can_intercept_method_with_default_implementation_from_mixin_in_proxied_interface()
{
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new InheritsMethodWithDefaultImplementation());
var expected = "intercepted";
var interceptor = new WithCallbackInterceptor(invocation => invocation.ReturnValue = expected);
var proxy = generator.CreateInterfaceProxyWithoutTarget(typeof(IEmpty), options, interceptor);
var actual = ((IHaveMethodWithDefaultImplementation)proxy).MethodWithDefaultImplementation();
Assert.AreEqual(expected, actual);
}

[Test]
public void Can_proceed_to_method_default_implementation_from_mixin_in_proxied_class()
{
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new InheritsMethodWithDefaultImplementation());
var interceptor = new WithCallbackInterceptor(invocation => invocation.Proceed());
var proxy = generator.CreateClassProxy(typeof(object), options, interceptor);
var expected = "default implementation";
var actual = ((IHaveMethodWithDefaultImplementation)proxy).MethodWithDefaultImplementation();
Assert.AreEqual(expected, actual);
}

[Test]
public void Can_proceed_to_method_default_implementation_from_mixin_in_proxied_interface()
{
var options = new ProxyGenerationOptions();
options.AddMixinInstance(new InheritsMethodWithDefaultImplementation());
var interceptor = new WithCallbackInterceptor(invocation => invocation.Proceed());
var proxy = generator.CreateInterfaceProxyWithoutTarget(typeof(IEmpty), options, interceptor);
var expected = "default implementation";
var actual = ((IHaveMethodWithDefaultImplementation)proxy).MethodWithDefaultImplementation();
Assert.AreEqual(expected, actual);
}
#endregion

public interface IHaveGenericMethodWithDefaultImplementation
{
string GenericMethodWithDefaultImplementation<T>()
Expand Down

0 comments on commit 23af447

Please sign in to comment.