|
| 1 | +using AspectCore.DynamicProxy; |
| 2 | +using Xunit; |
| 3 | + |
| 4 | +namespace AspectCore.Tests.DynamicProxy; |
| 5 | + |
| 6 | +public class CovariantReturnTypesTests : DynamicProxyTestBase |
| 7 | +{ |
| 8 | + public interface IService |
| 9 | + { |
| 10 | + object Method(); |
| 11 | + object Property { get; } |
| 12 | + } |
| 13 | + |
| 14 | + public class Service : IService |
| 15 | + { |
| 16 | + public virtual object Method() => nameof(Service); |
| 17 | + public virtual object Property { get; } = nameof(Service); |
| 18 | + } |
| 19 | + |
| 20 | + public class CovariantReturnsService : Service |
| 21 | + { |
| 22 | + public override string Method() => nameof(CovariantReturnsService); |
| 23 | + public override string Property { get; } = nameof(CovariantReturnsService); |
| 24 | + } |
| 25 | + |
| 26 | + [Fact] |
| 27 | + public void CreateClassProxy_CovariantReturns_Test() |
| 28 | + { |
| 29 | + var service = ProxyGenerator.CreateClassProxy<CovariantReturnsService>(); |
| 30 | + Assert.Equal(nameof(CovariantReturnsService), service.Method()); |
| 31 | + Assert.Equal(nameof(CovariantReturnsService), service.Property); |
| 32 | + } |
| 33 | + |
| 34 | + [Fact] |
| 35 | + public void CreateClassProxy_WithServiceType_CovariantReturns_Test() |
| 36 | + { |
| 37 | + var service = ProxyGenerator.CreateClassProxy<Service, CovariantReturnsService>(); |
| 38 | + Assert.Equal(nameof(CovariantReturnsService), service.Method()); |
| 39 | + Assert.Equal(nameof(CovariantReturnsService), service.Property); |
| 40 | + } |
| 41 | + |
| 42 | + [Fact] |
| 43 | + public void CreateInterfaceProxy_CovariantReturns_Test() |
| 44 | + { |
| 45 | + var service = ProxyGenerator.CreateInterfaceProxy<IService, CovariantReturnsService>(); |
| 46 | + Assert.Equal(nameof(CovariantReturnsService), service.Method()); |
| 47 | + Assert.Equal(nameof(CovariantReturnsService), service.Property); |
| 48 | + } |
| 49 | +} |
0 commit comments