Browse Source

Address Copilot review feedback

pull/25319/head
maliming 2 weeks ago
parent
commit
77bc52ed28
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 22
      modules/identity/test/Volo.Abp.Identity.EntityFrameworkCore.Tests/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentitySharedUserSeparateDbEntityFrameworkCoreTestModule.cs
  2. 16
      modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserManager_SharedUser_SeparateDatabase_Tests.cs

22
modules/identity/test/Volo.Abp.Identity.EntityFrameworkCore.Tests/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentitySharedUserSeparateDbEntityFrameworkCoreTestModule.cs

@ -1,5 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
@ -31,10 +31,10 @@ public class AbpIdentitySharedUserSeparateDbEntityFrameworkCoreTestModule : AbpM
public static readonly Guid TenantBId =
IdentityUserManager_SharedUser_SeparateDatabase_Tests<AbpIdentitySharedUserSeparateDbEntityFrameworkCoreTestModule>.TenantBId;
// Static cache so the in-memory SQLite databases survive for the full process lifetime
// (without an open connection, in-memory shared-cache databases are discarded). One entry
// per unique connection string.
private static readonly ConcurrentDictionary<string, SqliteConnection> _keepAlive = new();
// Per-app keep-alive connections so the in-memory SQLite databases survive for the test's
// lifetime (without an open connection, shared-cache in-memory databases are discarded).
// Disposed in OnApplicationShutdown so connections do not accumulate across tests.
private readonly List<SqliteConnection> _keepAlive = new();
public override void PreConfigureServices(ServiceConfigurationContext context)
{
@ -98,16 +98,20 @@ public class AbpIdentitySharedUserSeparateDbEntityFrameworkCoreTestModule : AbpM
context.Services.AddAlwaysDisableUnitOfWorkTransaction();
}
private static void EnsureDatabase(string connectionString)
public override void OnApplicationShutdown(ApplicationShutdownContext context)
{
if (_keepAlive.ContainsKey(connectionString))
foreach (var connection in _keepAlive)
{
return;
connection.Dispose();
}
_keepAlive.Clear();
}
private void EnsureDatabase(string connectionString)
{
var keepAlive = new SqliteConnection(connectionString);
keepAlive.Open();
_keepAlive[connectionString] = keepAlive;
_keepAlive.Add(keepAlive);
new IdentityDbContext(
new DbContextOptionsBuilder<IdentityDbContext>().UseSqlite(connectionString).Options)

16
modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserManager_SharedUser_SeparateDatabase_Tests.cs

@ -120,11 +120,15 @@ public abstract class IdentityUserManager_SharedUser_SeparateDatabase_Tests<TSta
using (CurrentTenant.Change(TenantAId))
{
(await IdentityUserManager.FindByEmailAsync(email)).UserName.ShouldBe(nameA);
var userA = await IdentityUserManager.FindByEmailAsync(email);
userA.ShouldNotBeNull();
userA.UserName.ShouldBe(nameA);
}
using (CurrentTenant.Change(TenantBId))
{
(await IdentityUserManager.FindByEmailAsync(email)).UserName.ShouldBe(nameB);
var userB = await IdentityUserManager.FindByEmailAsync(email);
userB.ShouldNotBeNull();
userB.UserName.ShouldBe(nameB);
}
}
@ -150,11 +154,15 @@ public abstract class IdentityUserManager_SharedUser_SeparateDatabase_Tests<TSta
using (CurrentTenant.Change(TenantAId))
{
(await IdentityUserManager.FindByNameAsync(userName)).Email.ShouldBe(emailA);
var userInTenantA = await IdentityUserManager.FindByNameAsync(userName);
userInTenantA.ShouldNotBeNull();
userInTenantA.Email.ShouldBe(emailA);
}
using (CurrentTenant.Change(TenantBId))
{
(await IdentityUserManager.FindByNameAsync(userName)).Email.ShouldBe(emailB);
var userInTenantB = await IdentityUserManager.FindByNameAsync(userName);
userInTenantB.ShouldNotBeNull();
userInTenantB.Email.ShouldBe(emailB);
}
}
}

Loading…
Cancel
Save