Change InMemory to Sqlite for IDS4 tests

pull/1810/head
Halil İbrahim Kalkan 5 years ago
parent 29cb4a676b
commit 1660a7210d

@ -151,7 +151,7 @@ namespace Volo.Abp.IdentityServer.EntityFrameworkCore
grant.Property(x => x.SubjectId).HasMaxLength(PersistedGrantConsts.SubjectIdMaxLength); grant.Property(x => x.SubjectId).HasMaxLength(PersistedGrantConsts.SubjectIdMaxLength);
grant.Property(x => x.ClientId).HasMaxLength(PersistedGrantConsts.ClientIdMaxLength).IsRequired(); grant.Property(x => x.ClientId).HasMaxLength(PersistedGrantConsts.ClientIdMaxLength).IsRequired();
grant.Property(x => x.CreationTime).IsRequired(); grant.Property(x => x.CreationTime).IsRequired();
grant.Property(x => x.Data).IsRequired(); grant.Property(x => x.Data);
grant.HasKey(x => x.Key); //TODO: What about Id!!! grant.HasKey(x => x.Key); //TODO: What about Id!!!

@ -138,7 +138,9 @@ namespace Volo.Abp.IdentityServer.Clients
//Arrange //Arrange
await _persistedGrantStore.StoreAsync(new PersistedGrant await _persistedGrantStore.StoreAsync(new PersistedGrant
{ {
Key = "#1P3R" Key = "#1P3R",
Type = "Type",
ClientId = "ClientId"
}); });
//Act //Act

@ -19,7 +19,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.0.0-preview9.19423.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.0.0-preview9.19423.6" />
<PackageReference Include="NSubstitute" Version="4.2.1" /> <PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="Shouldly" Version="3.0.2" /> <PackageReference Include="Shouldly" Version="3.0.2" />
<PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="xunit" Version="2.4.1" />

@ -1,11 +1,12 @@
using System; using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Identity.EntityFrameworkCore; using Volo.Abp.Identity.EntityFrameworkCore;
using Volo.Abp.IdentityServer.EntityFrameworkCore; using Volo.Abp.IdentityServer.EntityFrameworkCore;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Uow;
namespace Volo.Abp.IdentityServer namespace Volo.Abp.IdentityServer
{ {
@ -18,22 +19,15 @@ namespace Volo.Abp.IdentityServer
{ {
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
context.Services.AddEntityFrameworkInMemoryDatabase(); var sqliteConnection = CreateDatabaseAndGetConnection();
var databaseName = Guid.NewGuid().ToString();
Configure<AbpDbContextOptions>(options => Configure<AbpDbContextOptions>(options =>
{ {
options.Configure(abpDbContextConfigurationContext => options.Configure(abpDbContextConfigurationContext =>
{ {
abpDbContextConfigurationContext.DbContextOptions.UseInMemoryDatabase(databaseName); abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection);
}); });
}); });
Configure<UnitOfWorkDefaultOptions>(options =>
{
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; //EF in-memory database does not support transactions
});
} }
public override void OnApplicationInitialization(ApplicationInitializationContext context) public override void OnApplicationInitialization(ApplicationInitializationContext context)
@ -41,6 +35,22 @@ namespace Volo.Abp.IdentityServer
SeedTestData(context); SeedTestData(context);
} }
private static SqliteConnection CreateDatabaseAndGetConnection()
{
var connection = new SqliteConnection("Data Source=:memory:");
connection.Open();
new IdentityDbContext(
new DbContextOptionsBuilder<IdentityDbContext>().UseSqlite(connection).Options
).GetService<IRelationalDatabaseCreator>().CreateTables();
new IdentityServerDbContext(
new DbContextOptionsBuilder<IdentityServerDbContext>().UseSqlite(connection).Options
).GetService<IRelationalDatabaseCreator>().CreateTables();
return connection;
}
private static void SeedTestData(ApplicationInitializationContext context) private static void SeedTestData(ApplicationInitializationContext context)
{ {
using (var scope = context.ServiceProvider.CreateScope()) using (var scope = context.ServiceProvider.CreateScope())

@ -51,22 +51,26 @@ namespace Volo.Abp.IdentityServer
{ {
_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()) _persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create())
{ {
Key = "PersistedGrantKey1", Key = "PersistedGrantKey1",
SubjectId = "PersistedGrantSubjectId1", SubjectId = "PersistedGrantSubjectId1",
ClientId = "PersistedGrantClientId1", ClientId = "PersistedGrantClientId1",
Type = "PersistedGrantType1" Type = "PersistedGrantType1"
}); });
_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()) _persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create())
{ {
Key = "PersistedGrantKey2", Key = "PersistedGrantKey2",
SubjectId = "PersistedGrantSubjectId2" SubjectId = "PersistedGrantSubjectId2",
ClientId = "c1",
Type = "c1type"
}); });
_persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create()) _persistentGrantRepository.Insert(new PersistedGrant(_guidGenerator.Create())
{ {
Key = "PersistedGrantKey3", Key = "PersistedGrantKey3",
SubjectId = "PersistedGrantSubjectId3" SubjectId = "PersistedGrantSubjectId3",
ClientId = "c1",
Type = "c1type"
}); });
} }

Loading…
Cancel
Save