diff --git a/framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/Sqlite/AbpUnitTestSqliteConnection.cs b/framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/Sqlite/AbpUnitTestSqliteConnection.cs new file mode 100644 index 00000000000..e3b0dd7e304 --- /dev/null +++ b/framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/Sqlite/AbpUnitTestSqliteConnection.cs @@ -0,0 +1,52 @@ +using System.Threading; +using Microsoft.Data.Sqlite; +using Volo.Abp.Threading; + +namespace Volo.Abp.EntityFrameworkCore.Sqlite; + +/// +/// This class is for unit testing purposes. +/// It prevents exceptions in concurrent testing because Sqlite is not thread-safe. +/// +public class AbpUnitTestSqliteConnection : SqliteConnection +{ + public AbpUnitTestSqliteConnection(string connectionString) + : base(connectionString) + { + } + + public override SqliteCommand CreateCommand() + { + return new AbpSqliteCommand + { + Connection = this, + CommandTimeout = DefaultTimeout, + Transaction = Transaction + }; + } +} + +internal class AbpSqliteCommand : SqliteCommand +{ + private readonly static SemaphoreSlim Semaphore = new SemaphoreSlim(1, 1); + + public override SqliteConnection? Connection + { + get => base.Connection; + set + { + using (Semaphore.Lock()) + { + base.Connection = value; + } + } + } + + protected override void Dispose(bool disposing) + { + using (Semaphore.Lock()) + { + base.Dispose(disposing); + } + } +} diff --git a/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/AbpAuditingTestModule.cs b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/AbpAuditingTestModule.cs index 3a21cfaf5a8..c753d65d07c 100644 --- a/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/AbpAuditingTestModule.cs +++ b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/AbpAuditingTestModule.cs @@ -62,7 +62,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); using (var context = new AbpAuditingTestDbContext(new DbContextOptionsBuilder() diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs index f23ac14fda5..7db3130827d 100644 --- a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs @@ -93,7 +93,7 @@ await categoryRepository.InsertManyAsync(new List private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); using (var context = new TestMigrationsDbContext(new DbContextOptionsBuilder().UseSqlite(connection).Options)) diff --git a/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AbpAccountApplicationTestModule.cs b/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AbpAccountApplicationTestModule.cs index 100087f1fb4..2a6c9327531 100644 --- a/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AbpAccountApplicationTestModule.cs +++ b/modules/account/test/Volo.Abp.Account.Application.Tests/Volo/Abp/Account/AbpAccountApplicationTestModule.cs @@ -44,7 +44,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) } private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); new IdentityDbContext( diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreTestModule.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreTestModule.cs index bb8570d253a..42d246625e3 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreTestModule.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreTestModule.cs @@ -31,7 +31,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); new AbpAuditLoggingDbContext( diff --git a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreTestModule.cs b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreTestModule.cs index a642ddc2276..c19016d0d0b 100644 --- a/modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreTestModule.cs +++ b/modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreTestModule.cs @@ -31,7 +31,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); new BackgroundJobsDbContext( diff --git a/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests/EntityFrameworkCore/BlobStoringDatabaseEntityFrameworkCoreTestModule.cs b/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests/EntityFrameworkCore/BlobStoringDatabaseEntityFrameworkCoreTestModule.cs index 082b1640b75..038ca5874d5 100644 --- a/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests/EntityFrameworkCore/BlobStoringDatabaseEntityFrameworkCoreTestModule.cs +++ b/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests/EntityFrameworkCore/BlobStoringDatabaseEntityFrameworkCoreTestModule.cs @@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; +using Volo.Abp.EntityFrameworkCore.Sqlite; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Modularity; @@ -9,7 +10,8 @@ namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore; [DependsOn( typeof(BlobStoringDatabaseTestBaseModule), - typeof(BlobStoringDatabaseEntityFrameworkCoreModule) + typeof(BlobStoringDatabaseEntityFrameworkCoreModule), + typeof(AbpEntityFrameworkCoreSqliteModule) )] public class BlobStoringDatabaseEntityFrameworkCoreTestModule : AbpModule { @@ -28,7 +30,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); new BlobStoringDbContext( diff --git a/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests/Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests.csproj b/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests/Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests.csproj index 59db9b77df2..b48e29993d2 100644 --- a/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests/Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests.csproj +++ b/modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests/Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests.csproj @@ -11,6 +11,7 @@ + diff --git a/modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/EntityFrameworkCore/BloggingEntityFrameworkCoreTestModule.cs b/modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/EntityFrameworkCore/BloggingEntityFrameworkCoreTestModule.cs index 0a27448f6e9..498e8e7ab65 100644 --- a/modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/EntityFrameworkCore/BloggingEntityFrameworkCoreTestModule.cs +++ b/modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/EntityFrameworkCore/BloggingEntityFrameworkCoreTestModule.cs @@ -33,7 +33,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder().UseSqlite(connection).Options; diff --git a/modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/CmsKitEntityFrameworkCoreTestModule.cs b/modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/CmsKitEntityFrameworkCoreTestModule.cs index 9b7fee252ac..139e4bdce9d 100644 --- a/modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/CmsKitEntityFrameworkCoreTestModule.cs +++ b/modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/CmsKitEntityFrameworkCoreTestModule.cs @@ -30,7 +30,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); new CmsKitDbContext( diff --git a/modules/docs/test/Volo.Docs.EntityFrameworkCore.Tests/Volo/Docs/EntityFrameworkCore/DocsEntityFrameworkCoreTestModule.cs b/modules/docs/test/Volo.Docs.EntityFrameworkCore.Tests/Volo/Docs/EntityFrameworkCore/DocsEntityFrameworkCoreTestModule.cs index eb3a5ae5bde..fe3e32291ff 100644 --- a/modules/docs/test/Volo.Docs.EntityFrameworkCore.Tests/Volo/Docs/EntityFrameworkCore/DocsEntityFrameworkCoreTestModule.cs +++ b/modules/docs/test/Volo.Docs.EntityFrameworkCore.Tests/Volo/Docs/EntityFrameworkCore/DocsEntityFrameworkCoreTestModule.cs @@ -30,7 +30,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); new DocsDbContext( diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/AbpFeatureManagementEntityFrameworkCoreTestModule.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/AbpFeatureManagementEntityFrameworkCoreTestModule.cs index 3329f1dba64..242cf752332 100644 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/AbpFeatureManagementEntityFrameworkCoreTestModule.cs +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/AbpFeatureManagementEntityFrameworkCoreTestModule.cs @@ -36,7 +36,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); new FeatureManagementDbContext( diff --git a/modules/identity/test/Volo.Abp.Identity.EntityFrameworkCore.Tests/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreTestModule.cs b/modules/identity/test/Volo.Abp.Identity.EntityFrameworkCore.Tests/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreTestModule.cs index beb2797ea9d..f0d1966bd0c 100644 --- a/modules/identity/test/Volo.Abp.Identity.EntityFrameworkCore.Tests/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreTestModule.cs +++ b/modules/identity/test/Volo.Abp.Identity.EntityFrameworkCore.Tests/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreTestModule.cs @@ -35,7 +35,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); new IdentityDbContext( diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestEntityFrameworkCoreModule.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestEntityFrameworkCoreModule.cs index 6e934d1d8c4..e6711fc1806 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestEntityFrameworkCoreModule.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.EntityFrameworkCore.Tests/Volo/Abp/IdentityServer/AbpIdentityServerTestEntityFrameworkCoreModule.cs @@ -40,7 +40,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); new IdentityDbContext( diff --git a/modules/openiddict/test/Volo.Abp.OpenIddict.EntityFrameworkCore.Tests/Volo/Abp/OpenIddict/EntityFrameworkCore/OpenIddictEntityFrameworkCoreTestModule.cs b/modules/openiddict/test/Volo.Abp.OpenIddict.EntityFrameworkCore.Tests/Volo/Abp/OpenIddict/EntityFrameworkCore/OpenIddictEntityFrameworkCoreTestModule.cs index b7bf2160981..c47ecc79962 100644 --- a/modules/openiddict/test/Volo.Abp.OpenIddict.EntityFrameworkCore.Tests/Volo/Abp/OpenIddict/EntityFrameworkCore/OpenIddictEntityFrameworkCoreTestModule.cs +++ b/modules/openiddict/test/Volo.Abp.OpenIddict.EntityFrameworkCore.Tests/Volo/Abp/OpenIddict/EntityFrameworkCore/OpenIddictEntityFrameworkCoreTestModule.cs @@ -37,7 +37,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); new IdentityDbContext( diff --git a/modules/setting-management/test/Volo.Abp.SettingManagement.EntityFrameworkCore.Tests/Volo/Abp/SettingManagement/EntityFrameworkCore/AbpSettingManagementEntityFrameworkCoreTestModule.cs b/modules/setting-management/test/Volo.Abp.SettingManagement.EntityFrameworkCore.Tests/Volo/Abp/SettingManagement/EntityFrameworkCore/AbpSettingManagementEntityFrameworkCoreTestModule.cs index 9a2c51853e4..58df348af71 100644 --- a/modules/setting-management/test/Volo.Abp.SettingManagement.EntityFrameworkCore.Tests/Volo/Abp/SettingManagement/EntityFrameworkCore/AbpSettingManagementEntityFrameworkCoreTestModule.cs +++ b/modules/setting-management/test/Volo.Abp.SettingManagement.EntityFrameworkCore.Tests/Volo/Abp/SettingManagement/EntityFrameworkCore/AbpSettingManagementEntityFrameworkCoreTestModule.cs @@ -33,7 +33,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); new SettingManagementDbContext( diff --git a/modules/tenant-management/test/Volo.Abp.TenantManagement.EntityFrameworkCore.Tests/Volo/Abp/TenantManagement/EntityFrameworkCore/AbpTenantManagementEntityFrameworkCoreTestModule.cs b/modules/tenant-management/test/Volo.Abp.TenantManagement.EntityFrameworkCore.Tests/Volo/Abp/TenantManagement/EntityFrameworkCore/AbpTenantManagementEntityFrameworkCoreTestModule.cs index 9358a422165..336fbb228fc 100644 --- a/modules/tenant-management/test/Volo.Abp.TenantManagement.EntityFrameworkCore.Tests/Volo/Abp/TenantManagement/EntityFrameworkCore/AbpTenantManagementEntityFrameworkCoreTestModule.cs +++ b/modules/tenant-management/test/Volo.Abp.TenantManagement.EntityFrameworkCore.Tests/Volo/Abp/TenantManagement/EntityFrameworkCore/AbpTenantManagementEntityFrameworkCoreTestModule.cs @@ -37,7 +37,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); new TenantManagementDbContext( diff --git a/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.EntityFrameworkCore.Tests/EntityFrameworkCore/MyProjectNameEntityFrameworkCoreTestModule.cs b/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.EntityFrameworkCore.Tests/EntityFrameworkCore/MyProjectNameEntityFrameworkCoreTestModule.cs index 1804d8cff79..b316391b5fe 100644 --- a/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.EntityFrameworkCore.Tests/EntityFrameworkCore/MyProjectNameEntityFrameworkCoreTestModule.cs +++ b/templates/app/aspnet-core/test/MyCompanyName.MyProjectName.EntityFrameworkCore.Tests/EntityFrameworkCore/MyProjectNameEntityFrameworkCoreTestModule.cs @@ -59,7 +59,7 @@ public override void OnApplicationShutdown(ApplicationShutdownContext context) private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder() diff --git a/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.EntityFrameworkCore.Tests/EntityFrameworkCore/MyProjectNameEntityFrameworkCoreTestModule.cs b/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.EntityFrameworkCore.Tests/EntityFrameworkCore/MyProjectNameEntityFrameworkCoreTestModule.cs index 7abdfb25f8e..aed68ef88c8 100644 --- a/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.EntityFrameworkCore.Tests/EntityFrameworkCore/MyProjectNameEntityFrameworkCoreTestModule.cs +++ b/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.EntityFrameworkCore.Tests/EntityFrameworkCore/MyProjectNameEntityFrameworkCoreTestModule.cs @@ -33,7 +33,7 @@ public override void ConfigureServices(ServiceConfigurationContext context) private static SqliteConnection CreateDatabaseAndGetConnection() { - var connection = new SqliteConnection("Data Source=:memory:"); + var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); connection.Open(); new MyProjectNameDbContext(