Skip to content

Commit

Permalink
Merge pull request #3 from vcup/main
Browse files Browse the repository at this point in the history
feat: Scheme auto configuration improvement.
  • Loading branch information
gdlcf88 committed May 7, 2024
2 parents 2c1ffa3 + 818650b commit f6b630e
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 13 deletions.
7 changes: 7 additions & 0 deletions EasyAbp.Abp.GraphQL.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyAbp.Abp.GraphQL.Web.Alt
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyAbp.Abp.GraphQL.Web.Voyager", "src\EasyAbp.Abp.GraphQL.Web.Voyager\EasyAbp.Abp.GraphQL.Web.Voyager.csproj", "{A85D651F-F1B1-495C-BA7B-B3D1A26697A6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyAbp.Abp.GraphQL.Provider.Shared.Tests", "test\EasyAbp.Abp.GraphQL.Provider.Shared.Tests\EasyAbp.Abp.GraphQL.Provider.Shared.Tests.csproj", "{A620AE17-4929-47CC-B59D-9C3D1A711526}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -125,6 +127,10 @@ Global
{A85D651F-F1B1-495C-BA7B-B3D1A26697A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A85D651F-F1B1-495C-BA7B-B3D1A26697A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A85D651F-F1B1-495C-BA7B-B3D1A26697A6}.Release|Any CPU.Build.0 = Release|Any CPU
{A620AE17-4929-47CC-B59D-9C3D1A711526}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A620AE17-4929-47CC-B59D-9C3D1A711526}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A620AE17-4929-47CC-B59D-9C3D1A711526}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A620AE17-4929-47CC-B59D-9C3D1A711526}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -148,6 +154,7 @@ Global
{43DFC28D-C5F6-4883-998C-55E5B2426CA5} = {649A3FFA-182F-4E56-9717-E6A9A2BEC545}
{0CC56659-E3CF-4E4B-8D78-CD649EAA6088} = {649A3FFA-182F-4E56-9717-E6A9A2BEC545}
{A85D651F-F1B1-495C-BA7B-B3D1A26697A6} = {649A3FFA-182F-4E56-9717-E6A9A2BEC545}
{A620AE17-4929-47CC-B59D-9C3D1A711526} = {CCD2960C-23CC-4AB4-B84D-60C7AAA52F4D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4324B3B4-B60B-4E3C-91D8-59576B4E26DD}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,41 @@ public AbpGraphQLAppServiceSchemeConfigurations()
_scheme = new Dictionary<string, AbpGraphQLEntitySchemeConfiguration>();
}

private static bool GetReadOnlyAppServiceTypeGenericArgument(
Type type,
out Type[] args
)
{
args = null;
if (!type.IsAssignableToGenericType(typeof(IReadOnlyAppService<,,,>)))
{
type = type.GetInterfaces()
.FirstOrDefault(i => i.IsAssignableToGenericType(typeof(IReadOnlyAppService<,,,>)));
}

if (type is null)
{
return false;
}

args = type.GetGenericArguments();

if (args.Length is 4 && type.Name.StartsWith("IReadOnlyAppService"))
{
return true;
}

foreach (var t in type.GetInterfaces())
{
if (GetReadOnlyAppServiceTypeGenericArgument(t, out args))
{
return true;
}
}

return false;
}

/// <summary>
/// Configure by an Application.Contracts assembly.
/// </summary>
Expand All @@ -39,26 +74,16 @@ public AbpGraphQLAppServiceSchemeConfigurations()

foreach (var appServiceType in appServiceTypes)
{
var readOnlyAppServiceType = appServiceType.GetInterfaces()
.FirstOrDefault(x => x.IsAssignableToGenericType(typeof(IReadOnlyAppService<,,,>)));

if (readOnlyAppServiceType == null)
if (!GetReadOnlyAppServiceTypeGenericArgument(appServiceType, out var args))
{
continue;
}

var args = readOnlyAppServiceType.GetGenericArguments();

if (args.Length != 4)
{
continue;
}

var getOutputDtoType = args[0];
var getListOutputDtoType = args[1];
var keyType = args[2];
var getListInputType = args[3];

var schemeName = schemeNamePrefix + getOutputDtoType.Name.RemovePostFix("Dto");

configureAction ??= _ => { };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ProjectReference Include="..\..\src\EasyAbp.Abp.GraphQL.Provider.GraphQLDotnet\EasyAbp.Abp.GraphQL.Provider.GraphQLDotnet.csproj" />
<ProjectReference Include="..\EasyAbp.Abp.GraphQL.Application.Tests\EasyAbp.Abp.GraphQL.Application.Tests.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<ProjectReference Include="..\EasyAbp.Abp.GraphQL.Provider.Shared.Tests\EasyAbp.Abp.GraphQL.Provider.Shared.Tests.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace EasyAbp.Abp.GraphQL;

[DependsOn(
typeof(AbpGraphQLApplicationTestModule),
typeof(AbpAbpGraphQLProviderGraphQLDotnetModule)
typeof(AbpAbpGraphQLProviderGraphQLDotnetModule),
typeof(GraphQLProviderSharedTestModule)
)]
public class GraphQLProviderGraphQLDotnetTestModule : AbpModule
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>EasyAbp.Abp.GraphQL</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\EasyAbp.Abp.GraphQL.Provider.Shared\EasyAbp.Abp.GraphQL.Provider.Shared.csproj" />
<ProjectReference Include="..\EasyAbp.Abp.GraphQL.TestBase\EasyAbp.Abp.GraphQL.TestBase.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions test/EasyAbp.Abp.GraphQL.Provider.Shared.Tests/EmptyDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace EasyAbp.Abp.GraphQL;

internal class EmptyDto;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace EasyAbp.Abp.GraphQL;

public abstract class GraphQLProviderSharedTestBase : GraphQLTestBase<GraphQLProviderSharedTestModule>
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Volo.Abp.Modularity;

namespace EasyAbp.Abp.GraphQL;

[DependsOn(
typeof(AbpGraphQLTestBaseModule),
typeof(AbpGraphQLProviderSharedModule)
)]
public class GraphQLProviderSharedTestModule : AbpModule
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;

namespace EasyAbp.Abp.GraphQL;

internal interface IEmptyAppService2 : IReadOnlyAppService<EmptyDto, Guid>;
internal interface IEmptyAppService3 : IReadOnlyAppService<EmptyDto, Guid, PagedAndSortedResultRequestDto>;
internal interface IEmptyAppService4 : IReadOnlyAppService<EmptyDto, EmptyDto, Guid, PagedAndSortedResultRequestDto>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Reflection;
using NSubstitute;
using Shouldly;
using Xunit;

namespace EasyAbp.Abp.GraphQL.Tests;

public class AbpGraphQLAppServiceSchemeConfigurationsTests
{
[Fact]
public void Configure_With_Assembly_Should_Scan_IEmptyAppService4()
{
// arrange
var assembly = Substitute.For<Assembly>();
assembly.DefinedTypes.Returns([typeof(IEmptyAppService4).GetTypeInfo()]);

var config = new AbpGraphQLAppServiceSchemeConfigurations();

// act
config.Configure(assembly);

// assert
config.GetConfigurations().Count.ShouldBePositive();
}

[Fact]
public void Configure_With_Assembly_Should_Scan_IEmptyAppService3()
{
// arrange
var assembly = Substitute.For<Assembly>();
assembly.DefinedTypes.Returns([typeof(IEmptyAppService3).GetTypeInfo()]);

var config = new AbpGraphQLAppServiceSchemeConfigurations();

// act
config.Configure(assembly);

// assert
config.GetConfigurations().Count.ShouldBePositive();
}

[Fact]
public void Configure_With_Assembly_Should_Scan_IEmptyAppService2()
{
// arrange
var assembly = Substitute.For<Assembly>();
assembly.DefinedTypes.Returns([typeof(IEmptyAppService2).GetTypeInfo()]);

var config = new AbpGraphQLAppServiceSchemeConfigurations();

// act
config.Configure(assembly);

// assert
config.GetConfigurations().Count.ShouldBePositive();
}
}

0 comments on commit f6b630e

Please sign in to comment.