V10: fix build warnings in test projects (#12509)
* Run code cleanup * Dotnet format benchmarks project * Fix up Test.Common * Run dotnet format + manual cleanup * Run code cleanup for unit tests * Run dotnet format * Fix up errors * Manual cleanup of Unit test project * Update tests/Umbraco.Tests.Benchmarks/HexStringBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/TestDbMeta.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix according to review * Fix after merge * Fix errors Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
@@ -2,10 +2,8 @@ using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
@@ -16,22 +14,21 @@ using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Infrastructure.Migrations.Install;
|
||||
using Umbraco.Cms.Infrastructure.Persistence;
|
||||
using Umbraco.Cms.Infrastructure.Persistence.Mappers;
|
||||
using Umbraco.Cms.Persistence.Sqlite;
|
||||
using Umbraco.Cms.Persistence.Sqlite.Mappers;
|
||||
using Umbraco.Cms.Persistence.Sqlite.Services;
|
||||
using Umbraco.Cms.Tests.Common;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Testing;
|
||||
|
||||
public class SqliteTestDatabase : BaseTestDatabase, ITestDatabase
|
||||
{
|
||||
private readonly TestDatabaseSettings _settings;
|
||||
private readonly TestUmbracoDatabaseFactoryProvider _dbFactoryProvider;
|
||||
public const string DatabaseName = "UmbracoTests";
|
||||
private readonly TestUmbracoDatabaseFactoryProvider _dbFactoryProvider;
|
||||
private readonly TestDatabaseSettings _settings;
|
||||
|
||||
protected UmbracoDatabase.CommandInfo[] _cachedDatabaseInitCommands = new UmbracoDatabase.CommandInfo[0];
|
||||
|
||||
public SqliteTestDatabase(TestDatabaseSettings settings, TestUmbracoDatabaseFactoryProvider dbFactoryProvider,
|
||||
ILoggerFactory loggerFactory)
|
||||
public SqliteTestDatabase(TestDatabaseSettings settings, TestUmbracoDatabaseFactoryProvider dbFactoryProvider, ILoggerFactory loggerFactory)
|
||||
{
|
||||
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
||||
_dbFactoryProvider = dbFactoryProvider;
|
||||
@@ -47,13 +44,19 @@ public class SqliteTestDatabase : BaseTestDatabase, ITestDatabase
|
||||
_testDatabases = schema.Concat(empty).ToList();
|
||||
}
|
||||
|
||||
public override void Detach(TestDbMeta meta)
|
||||
{
|
||||
meta.Connection.Close();
|
||||
_prepareQueue.TryAdd(CreateSqLiteMeta(meta.IsEmpty));
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
_prepareQueue = new BlockingCollection<TestDbMeta>();
|
||||
_readySchemaQueue = new BlockingCollection<TestDbMeta>();
|
||||
_readyEmptyQueue = new BlockingCollection<TestDbMeta>();
|
||||
|
||||
foreach (TestDbMeta meta in _testDatabases)
|
||||
foreach (var meta in _testDatabases)
|
||||
{
|
||||
_prepareQueue.Add(meta);
|
||||
}
|
||||
@@ -72,12 +75,6 @@ public class SqliteTestDatabase : BaseTestDatabase, ITestDatabase
|
||||
meta.Connection.Open();
|
||||
}
|
||||
|
||||
public override void Detach(TestDbMeta meta)
|
||||
{
|
||||
meta.Connection.Close();
|
||||
_prepareQueue.TryAdd(CreateSqLiteMeta(meta.IsEmpty));
|
||||
}
|
||||
|
||||
protected override DbConnection GetConnection(TestDbMeta meta) => new SqliteConnection(meta.ConnectionString);
|
||||
|
||||
protected override void RebuildSchema(IDbCommand command, TestDbMeta meta)
|
||||
@@ -101,7 +98,7 @@ public class SqliteTestDatabase : BaseTestDatabase, ITestDatabase
|
||||
database.Mappers.Add(new NullableDateMapper());
|
||||
database.Mappers.Add(new SqlitePocoGuidMapper());
|
||||
|
||||
foreach (UmbracoDatabase.CommandInfo dbCommand in _cachedDatabaseInitCommands)
|
||||
foreach (var dbCommand in _cachedDatabaseInitCommands)
|
||||
{
|
||||
database.Execute(dbCommand.Text, dbCommand.Parameters.Select(x => x.Value).ToArray());
|
||||
}
|
||||
@@ -117,9 +114,11 @@ public class SqliteTestDatabase : BaseTestDatabase, ITestDatabase
|
||||
using var database = (UmbracoDatabase)dbFactory.CreateDatabase();
|
||||
database.LogCommands = true;
|
||||
|
||||
using NPoco.ITransaction transaction = database.GetTransaction();
|
||||
using var transaction = database.GetTransaction();
|
||||
|
||||
var options = new TestOptionsMonitor<InstallDefaultDataSettings>(new InstallDefaultDataSettings { InstallData = InstallDefaultDataOption.All });
|
||||
var options =
|
||||
new TestOptionsMonitor<InstallDefaultDataSettings>(
|
||||
new InstallDefaultDataSettings { InstallData = InstallDefaultDataOption.All });
|
||||
|
||||
var schemaCreator = new DatabaseSchemaCreator(
|
||||
database,
|
||||
@@ -145,26 +144,29 @@ public class SqliteTestDatabase : BaseTestDatabase, ITestDatabase
|
||||
}
|
||||
|
||||
_prepareQueue.CompleteAdding();
|
||||
while (_prepareQueue.TryTake(out _)) { }
|
||||
while (_prepareQueue.TryTake(out _))
|
||||
{ }
|
||||
|
||||
_readyEmptyQueue.CompleteAdding();
|
||||
while (_readyEmptyQueue.TryTake(out _)) { }
|
||||
while (_readyEmptyQueue.TryTake(out _))
|
||||
{ }
|
||||
|
||||
_readySchemaQueue.CompleteAdding();
|
||||
while (_readySchemaQueue.TryTake(out _)) { }
|
||||
while (_readySchemaQueue.TryTake(out _))
|
||||
{ }
|
||||
}
|
||||
|
||||
private TestDbMeta CreateSqLiteMeta(bool empty)
|
||||
{
|
||||
var builder = new SqliteConnectionStringBuilder()
|
||||
var builder = new SqliteConnectionStringBuilder
|
||||
{
|
||||
DataSource = $"{Guid.NewGuid()}",
|
||||
Mode = SqliteOpenMode.Memory,
|
||||
ForeignKeys = true,
|
||||
Pooling = false, // When pooling true, files kept open after connections closed, bad for cleanup.
|
||||
Cache = SqliteCacheMode.Shared,
|
||||
Cache = SqliteCacheMode.Shared
|
||||
};
|
||||
|
||||
return new TestDbMeta(builder.DataSource, empty, builder.ConnectionString, Persistence.Sqlite.Constants.ProviderName, "InMemory");
|
||||
return new TestDbMeta(builder.DataSource, empty, builder.ConnectionString, Constants.ProviderName, "InMemory");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user