Skip to content

Commit be22332

Browse files
committed
Add failing tests for covariant return types involving a variant generic interface
1 parent ee08309 commit be22332

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Castle.Core.Tests/DynamicProxy.Tests/CovariantReturnsTestCase.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public void Reflection_returns_methods_from_a_derived_class_before_methods_from_
5252
[TestCase(typeof(DerivedClassWithStringInsteadOfObject))]
5353
[TestCase(typeof(DerivedClassWithStringInsteadOfInterface))]
5454
[TestCase(typeof(DerivedClassWithStringInsteadOfGenericArg))]
55+
[TestCase(typeof(BottleOfWater))]
5556
public void Can_proxy_type_having_method_with_covariant_return(Type classToProxy)
5657
{
5758
_ = generator.CreateClassProxy(classToProxy, new StandardInterceptor());
@@ -62,6 +63,7 @@ public void Can_proxy_type_having_method_with_covariant_return(Type classToProxy
6263
[TestCase(typeof(DerivedClassWithStringInsteadOfObject), typeof(string))]
6364
[TestCase(typeof(DerivedClassWithStringInsteadOfInterface), typeof(string))]
6465
[TestCase(typeof(DerivedClassWithStringInsteadOfGenericArg), typeof(string))]
66+
[TestCase(typeof(BottleOfWater), typeof(Glass<Water>))]
6567
public void Proxied_method_has_correct_return_type(Type classToProxy, Type expectedMethodReturnType)
6668
{
6769
var proxy = generator.CreateClassProxy(classToProxy, new StandardInterceptor());
@@ -116,6 +118,22 @@ public class DerivedClassWithStringInsteadOfGenericArg : BaseClassWithGenericArg
116118
{
117119
public override string Method() => nameof(DerivedClassWithStringInsteadOfGenericArg);
118120
}
121+
122+
public interface Glass<out T> { }
123+
124+
public class Liquid { }
125+
126+
public class Water : Liquid { }
127+
128+
public class BottleOfLiquid
129+
{
130+
public virtual Glass<Liquid> Method() => default(Glass<Liquid>);
131+
}
132+
133+
public class BottleOfWater : BottleOfLiquid
134+
{
135+
public override Glass<Water> Method() => default(Glass<Water>);
136+
}
119137
}
120138
}
121139

0 commit comments

Comments
 (0)