mirror of https://github.com/abpframework/abp.git
20 changed files with 383 additions and 17 deletions
@ -0,0 +1,24 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp2.1</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.IdentityServer.MongoDB.Tests</AssemblyName> |
||||
|
<PackageId>Volo.Abp.IdentityServer.MongoDB.Tests</PackageId> |
||||
|
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.IdentityServer.MongoDB\Volo.Abp.IdentityServer.MongoDB.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.IdentityServer.TestBase\Volo.Abp.IdentityServer.TestBase.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> |
||||
|
<PackageReference Include="Mongo2Go" Version="2.2.1" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,7 @@ |
|||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class ApiResourceRepository_Tests //: ApiResourceRepository_Tests<AbpIdentityServerTestEntityFrameworkCoreModule>
|
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp2.1</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.IdentityServer.MongoDB.Tests</AssemblyName> |
||||
|
<PackageId>Volo.Abp.IdentityServer.MongoDB.Tests</PackageId> |
||||
|
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.IdentityServer.MongoDB\Volo.Abp.IdentityServer.MongoDB.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.IdentityServer.TestBase\Volo.Abp.IdentityServer.TestBase.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> |
||||
|
<PackageReference Include="Mongo2Go" Version="2.2.1" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,33 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Mongo2Go; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.IdentityServer.MongoDB; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
|
||||
|
[DependsOn( |
||||
|
typeof(AbpIdentityServerTestBaseModule), |
||||
|
typeof(AbpIdentityServerMongoDbModule) |
||||
|
)] |
||||
|
public class AbpIdentityServerMongoDbTestModule : AbpModule |
||||
|
{ |
||||
|
private MongoDbRunner _mongoDbRunner; |
||||
|
|
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
_mongoDbRunner = MongoDbRunner.Start(); |
||||
|
|
||||
|
context.Services.Configure<DbConnectionOptions>(options => |
||||
|
{ |
||||
|
options.ConnectionStrings.Default = _mongoDbRunner.ConnectionString; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
public override void OnApplicationShutdown(ApplicationShutdownContext context) |
||||
|
{ |
||||
|
_mongoDbRunner.Dispose(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class ApiResourceRepository_Tests : ApiResourceRepository_Tests<AbpIdentityServerMongoDbTestModule> |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class ClientRepository_Tests : ClientRepository_Tests<AbpIdentityServerMongoDbTestModule> |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class IdentityResourceRepository_Tests : IdentityResourceRepository_Tests<AbpIdentityServerMongoDbTestModule> |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp2.1</TargetFramework> |
||||
|
<AssemblyName>Volo.Abp.IdentityServer.TestBase</AssemblyName> |
||||
|
<PackageId>Volo.Abp.IdentityServer.TestBase</PackageId> |
||||
|
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.TestBase\Volo.Abp.TestBase.csproj" /> |
||||
|
<ProjectReference Include="..\..\src\Volo.Abp.IdentityServer.Domain\Volo.Abp.IdentityServer.Domain.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> |
||||
|
<PackageReference Include="NSubstitute" Version="3.1.0" /> |
||||
|
<PackageReference Include="Shouldly" Version="3.0.0" /> |
||||
|
<PackageReference Include="xunit" Version="2.3.1" /> |
||||
|
<PackageReference Include="xunit.extensibility.execution" Version="2.3.1" /> |
||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,16 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class AbpIdentityServerTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule> |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
||||
|
{ |
||||
|
options.UseAutofac(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Autofac; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.Threading; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
[DependsOn( |
||||
|
typeof(AbpAutofacModule), |
||||
|
typeof(AbpTestBaseModule), |
||||
|
typeof(AbpIdentityServerDomainModule) |
||||
|
)] |
||||
|
public class AbpIdentityServerTestBaseModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
context.Services.AddAlwaysAllowPermissionChecker(); |
||||
|
} |
||||
|
|
||||
|
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
||||
|
{ |
||||
|
SeedTestData(context); |
||||
|
} |
||||
|
|
||||
|
private static void SeedTestData(ApplicationInitializationContext context) |
||||
|
{ |
||||
|
using (var scope = context.ServiceProvider.CreateScope()) |
||||
|
{ |
||||
|
//var dataSeeder = scope.ServiceProvider.GetRequiredService<IIdentityServerDataSeeder>();
|
||||
|
//AsyncHelper.RunSync(() => dataSeeder.SeedAsync("1q2w3E*"));
|
||||
|
|
||||
|
scope.ServiceProvider |
||||
|
.GetRequiredService<AbpIdentityServerTestDataBuilder>() |
||||
|
.Build(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,68 @@ |
|||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Guids; |
||||
|
using Volo.Abp.IdentityServer.ApiResources; |
||||
|
using Volo.Abp.IdentityServer.Clients; |
||||
|
using Volo.Abp.IdentityServer.Grants; |
||||
|
using Volo.Abp.IdentityServer.IdentityResources; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class AbpIdentityServerTestDataBuilder : ITransientDependency |
||||
|
{ |
||||
|
private readonly IGuidGenerator _guidGenerator; |
||||
|
private readonly IApiResourceRepository _apiResourceRepository; |
||||
|
private readonly IClientRepository _clientRepository; |
||||
|
private readonly IIdentityResourceRepository _identityResourceRepository; |
||||
|
//private readonly IPersistentGrantRepository _persistentGrantRepository;
|
||||
|
|
||||
|
public AbpIdentityServerTestDataBuilder( |
||||
|
IGuidGenerator guidGenerator, |
||||
|
IApiResourceRepository apiResourceRepository, |
||||
|
IClientRepository clientRepository, |
||||
|
IIdentityResourceRepository identityResourceRepository |
||||
|
/*IPersistentGrantRepository persistentGrantRepository*/) |
||||
|
{ |
||||
|
_guidGenerator = guidGenerator; |
||||
|
_apiResourceRepository = apiResourceRepository; |
||||
|
_clientRepository = clientRepository; |
||||
|
_identityResourceRepository = identityResourceRepository; |
||||
|
//_persistentGrantRepository = persistentGrantRepository;
|
||||
|
} |
||||
|
|
||||
|
public void Build() |
||||
|
{ |
||||
|
AddPersistedGrants(); |
||||
|
AddIdentityResources(); |
||||
|
AddApiResources(); |
||||
|
AddClients(); |
||||
|
} |
||||
|
|
||||
|
private void AddPersistedGrants() |
||||
|
{ |
||||
|
//_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()));
|
||||
|
//_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()));
|
||||
|
//_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()));
|
||||
|
} |
||||
|
|
||||
|
private void AddIdentityResources() |
||||
|
{ |
||||
|
_identityResourceRepository.Insert(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource1")); |
||||
|
_identityResourceRepository.Insert(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource2")); |
||||
|
_identityResourceRepository.Insert(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource3")); |
||||
|
} |
||||
|
|
||||
|
private void AddApiResources() |
||||
|
{ |
||||
|
_apiResourceRepository.Insert(new ApiResource(_guidGenerator.Create(), "NewApiResource1")); |
||||
|
_apiResourceRepository.Insert(new ApiResource(_guidGenerator.Create(), "NewApiResource2")); |
||||
|
_apiResourceRepository.Insert(new ApiResource(_guidGenerator.Create(), "NewApiResource3")); |
||||
|
} |
||||
|
|
||||
|
private void AddClients() |
||||
|
{ |
||||
|
_clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId1")); |
||||
|
_clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId2")); |
||||
|
_clientRepository.Insert(new Client(_guidGenerator.Create(), "ClientId3")); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.IdentityServer.ApiResources; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public abstract class ApiResourceRepository_Tests<TStartupModule> : AbpIdentityServerTestBase<TStartupModule> |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
protected IApiResourceRepository apiResourceRepository { get; } |
||||
|
|
||||
|
public ApiResourceRepository_Tests() |
||||
|
{ |
||||
|
apiResourceRepository = ServiceProvider.GetRequiredService<IApiResourceRepository>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task FindByNormalizedNameAsync() |
||||
|
{ |
||||
|
(await apiResourceRepository.FindByNameAsync("NewApiResource2")).ShouldNotBeNull(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task GetListByScopesAsync() |
||||
|
{ |
||||
|
(await apiResourceRepository.GetListByScopesAsync(new []{ "NewApiResource2", "NewApiResource3"})).Count.ShouldBe(2); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.IdentityServer.Clients; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public abstract class ClientRepository_Tests<TStartupModule> : AbpIdentityServerTestBase<TStartupModule> |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
protected IClientRepository clientRepository { get; } |
||||
|
|
||||
|
public ClientRepository_Tests() |
||||
|
{ |
||||
|
clientRepository = ServiceProvider.GetRequiredService<IClientRepository>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task FindByCliendIdAsync() |
||||
|
{ |
||||
|
(await clientRepository.FindByCliendIdAsync("ClientId2")).ShouldNotBeNull(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.IdentityServer.IdentityResources; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class IdentityResourceRepository_Tests<TStartupModule> : AbpIdentityServerTestBase<TStartupModule> |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
private IIdentityResourceRepository identityResourceRepository; |
||||
|
public IdentityResourceRepository_Tests() |
||||
|
{ |
||||
|
identityResourceRepository = ServiceProvider.GetRequiredService<IIdentityResourceRepository>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task GetListByScopesAsync() |
||||
|
{ |
||||
|
(await identityResourceRepository.GetListByScopesAsync(new []{"", "NewIdentityResource2" })).Count.ShouldBe(1); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue