-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance enumerable graph type determining (#262)
Co-authored-by: Tommy Lillehagen <[email protected]>
- Loading branch information
Showing
2 changed files
with
166 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
test/GraphQL.Conventions.Tests/Types/Resolution/Extensions/ReflectionExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using GraphQL.Conventions.Types.Resolution.Extensions; | ||
using Xunit; | ||
|
||
namespace Tests.Types.Resolution.Extensions | ||
{ | ||
public class ReflectionExtensionsTests | ||
{ | ||
[Theory] | ||
[MemberData(nameof(IsEnumerableGraphType_Should_Return_True_For_Common_Collection_Types_Data))] | ||
public void IsEnumerableGraphType_Should_Return_True_For_Common_Collection_Types(Type type) | ||
{ | ||
Assert.IsTrue(type.GetTypeInfo().IsEnumerableGraphType()); | ||
} | ||
|
||
public static TheoryData<Type> IsEnumerableGraphType_Should_Return_True_For_Common_Collection_Types_Data() => new() | ||
{ | ||
typeof(IEnumerable<>), | ||
typeof(ConcurrentQueue<>), | ||
typeof(HashSet<>), | ||
typeof(int[]), | ||
typeof(List<>), | ||
typeof(IList<>), | ||
typeof(IReadOnlyList<>), | ||
typeof(IReadOnlyCollection<>), | ||
}; | ||
|
||
[Theory] | ||
[MemberData(nameof(IsEnumerableGraphType_Should_Return_False_For_Common_Dictionary_Types_Data))] | ||
public void IsEnumerableGraphType_Should_Return_False_For_Common_Dictionary_Types(Type type) | ||
{ | ||
Assert.IsFalse(type.GetTypeInfo().IsEnumerableGraphType()); | ||
} | ||
|
||
public static TheoryData<Type> IsEnumerableGraphType_Should_Return_False_For_Common_Dictionary_Types_Data() => new() | ||
{ | ||
typeof(IDictionary<,>), | ||
typeof(IDictionary), | ||
}; | ||
|
||
[Theory] | ||
[MemberData(nameof(GetImplementationInterface_WithoutFuse_AcquireSpecifiedInterfaceOnly_Data))] | ||
public void GetImplementationInterface_WithoutFuse_AcquireSpecifiedInterfaceOnly(Type type, Type assignableInterface) | ||
=> Assert.IsTrue(type.IsImplementingInterface(assignableInterface, false)); | ||
|
||
public static TheoryData<Type, Type> GetImplementationInterface_WithoutFuse_AcquireSpecifiedInterfaceOnly_Data() => | ||
new() | ||
{ | ||
{ typeof(ITestInterface1<int>), typeof(ITestInterface1<int>) }, | ||
{ typeof(ITestInterface2<int>), typeof(ITestInterface1<int>) }, | ||
{ typeof(ITestInterface2<int>), typeof(ITestInterface2<int>) }, | ||
{ typeof(TestClass11<int>), typeof(ITestInterface1<int>) }, | ||
{ typeof(TestClass12), typeof(ITestInterface1<string>) }, | ||
{ typeof(TestClass12), typeof(ITestInterface2<string>) }, | ||
{ typeof(TestClass2), typeof(ITestInterface1<int>) }, | ||
{ typeof(TestClass2), typeof(ITestInterface1<string>) }, | ||
{ typeof(TestClass2), typeof(ITestInterface2<string>) }, | ||
}; | ||
|
||
[Theory] | ||
[MemberData(nameof(GetImplementationInterface_WithFuse_AcquireSpecifiedInterfaceOnly_Data))] | ||
public void GetImplementationInterface_WithFuse_AcquireSpecifiedInterfaceOnly(Type type, Type assignableInterface) => | ||
Assert.IsTrue(type.IsImplementingInterface(assignableInterface)); | ||
|
||
public static TheoryData<Type, Type> GetImplementationInterface_WithFuse_AcquireSpecifiedInterfaceOnly_Data() => | ||
new() | ||
{ | ||
{ typeof(ITestInterface1<int>), typeof(ITestInterface1<>) }, | ||
{ typeof(ITestInterface2<int>), typeof(ITestInterface1<>) }, | ||
{ typeof(ITestInterface2<int>), typeof(ITestInterface2<>) }, | ||
{ typeof(TestClass11<int>), typeof(ITestInterface1<>) }, | ||
// | ||
{ typeof(ITestInterface1<string>), typeof(ITestInterface1<>) }, | ||
{ typeof(ITestInterface2<string>), typeof(ITestInterface1<>) }, | ||
{ typeof(ITestInterface2<string>), typeof(ITestInterface2<>) }, | ||
{ typeof(TestClass11<string>), typeof(ITestInterface1<>) }, | ||
// | ||
{ typeof(TestClass12), typeof(ITestInterface1<>) }, | ||
{ typeof(TestClass12), typeof(ITestInterface2<>) }, | ||
{ typeof(TestClass2), typeof(ITestInterface1<>) }, | ||
{ typeof(TestClass2), typeof(ITestInterface2<>) }, | ||
}; | ||
|
||
private interface ITestInterface1<out T> | ||
{ | ||
// ReSharper disable once UnusedMember.Global | ||
T Item => throw new NotImplementedException(); | ||
} | ||
|
||
private interface ITestInterface2<out T> : ITestInterface1<T> | ||
{ | ||
} | ||
|
||
private class TestClass11<T> : ITestInterface1<T> | ||
{ | ||
} | ||
|
||
private class TestClass12 : ITestInterface2<string> | ||
{ | ||
} | ||
|
||
private class TestClass2 : ITestInterface2<string>, ITestInterface1<int> | ||
{ | ||
} | ||
} | ||
} |