mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-08-15 18:44:57 +00:00
Find overriding implementations for virtual methods
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using EntityFrameworkCore.Projectables.Extensions;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
|
||||
using Xunit;
|
||||
|
||||
namespace EntityFrameworkCore.Projectables.Tests.Extensions
|
||||
@@ -18,6 +20,18 @@ namespace EntityFrameworkCore.Projectables.Tests.Extensions
|
||||
}
|
||||
}
|
||||
|
||||
class BaseType
|
||||
{
|
||||
public virtual void VirtualMethod(int arg1) { }
|
||||
public virtual void GenericVirtualMethod<TArg>(TArg arg1) { }
|
||||
}
|
||||
|
||||
class DerivedType : BaseType
|
||||
{
|
||||
public override void VirtualMethod(int arg1) { }
|
||||
public override void GenericVirtualMethod<TArg>(TArg arg1) { }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetNestedTypePath_OuterType_Returns1Entry()
|
||||
{
|
||||
@@ -28,7 +42,6 @@ namespace EntityFrameworkCore.Projectables.Tests.Extensions
|
||||
Assert.Single(result);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void GetNestedTypePath_InnerType_Returns2Entries()
|
||||
{
|
||||
@@ -59,5 +72,53 @@ namespace EntityFrameworkCore.Projectables.Tests.Extensions
|
||||
Assert.Equal(typeof(TypeExtensionTests), result.First());
|
||||
Assert.Equal(typeof(InnerType.SubsequentlyInnerType), result.Last());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetOverridingMethod_BaseTypeVirtualMethod_FindsSameMethod()
|
||||
{
|
||||
var type = typeof(BaseType);
|
||||
var method = typeof(BaseType).GetMethod("VirtualMethod")!;
|
||||
|
||||
var result = type.GetOverridingMethod(method);
|
||||
|
||||
Assert.Equal(method, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetOverridingMethod_DerivedTypeVirtualMethod_FindsOverridingMethod()
|
||||
{
|
||||
var baseType = typeof(BaseType);
|
||||
var baseMethod = baseType.GetMethod("VirtualMethod")!;
|
||||
var derivedType = typeof(DerivedType);
|
||||
var derivedMethod = typeof(DerivedType).GetMethod("VirtualMethod")!;
|
||||
|
||||
var resolvedMethod = derivedType.GetOverridingMethod(baseMethod);
|
||||
|
||||
Assert.Equal(derivedMethod, resolvedMethod);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetOverridingMethod_BaseTypeGenericVirtualMethod_FindsSameMethod()
|
||||
{
|
||||
var type = typeof(BaseType);
|
||||
var method = typeof(BaseType).GetMethod("GenericVirtualMethod")!;
|
||||
|
||||
var result = type.GetOverridingMethod(method);
|
||||
|
||||
Assert.Equal(method, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetOverridingMethod_DerivedTypeGenericVirtualMethod_FindsOverridingMethod()
|
||||
{
|
||||
var baseType = typeof(BaseType);
|
||||
var baseMethod = baseType.GetMethod("GenericVirtualMethod")!;
|
||||
var derivedType = typeof(DerivedType);
|
||||
var derivedMethod = typeof(DerivedType).GetMethod("GenericVirtualMethod")!;
|
||||
|
||||
var resolvedMethod = derivedType.GetOverridingMethod(baseMethod);
|
||||
|
||||
Assert.Equal(derivedMethod, resolvedMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user