From 57077b53bf95aaa6bd77d7ba14734d30b53c2f27 Mon Sep 17 00:00:00 2001 From: iatsuta Date: Mon, 27 Apr 2026 16:37:35 +0200 Subject: [PATCH 01/13] migrate testsing --- .../Anch.Testing.Database.Mssql.csproj | 11 + .../MssqlDatabaseFilePathExtractor.cs | 26 ++ .../MssqlDatabaseTestingProvider.cs | 15 + ...ssqlTestDatabaseConnectionStringBuilder.cs | 31 ++ .../Framework.Application.Tests.csproj | 2 +- .../Framework.AutomationCore.Legacy.csproj} | 4 +- .../IntegrationTestBase.cs | 101 ++++++ .../ContextEvaluatorExtensions.cs | 0 .../ContextEvaluatorWithMappingExtensions.cs | 0 .../IRootServiceProviderContainer.cs | 0 .../RootServiceProviderContainer.cs | 3 + .../IntegrationTestBase.cs | 101 ------ .../RootServiceProviderContainer.cs | 4 - ...k.AutomationCore.ServiceEnvironment.csproj | 21 -- .../IntegrationTestBase.cs | 82 ----- .../IRootServiceProviderContainer.cs | 6 - .../RootServiceProviderContainer.cs | 28 -- .../RootServiceProviderContainerExtensions.cs | 34 -- .../TestInitializeAndCleanup.cs | 62 ---- .../Framework.AutomationCore.Xunit.csproj | 8 - .../DiAssemblyInitializeAndCleanup.cs | 20 -- .../DiTestInitializeAndCleanup.cs | 19 -- .../DiServiceProviderPool.cs | 16 - .../ServiceProviderPoolFunc.cs | 6 - .../AssemblyInitializeAndCleanup.cs | 56 ---- .../AssemblyInitializeAndCleanupBase.cs | 70 ---- .../Enums/TestRunMode.cs | 10 - .../Environment/TestEnvironment.cs | 16 - .../Environment/TestEnvironmentBuilder.cs | 169 ---------- .../Extensions/ConfigurationExtensions.cs | 19 -- .../Extensions/Excel/Column.cs | 13 - .../Extensions/ObjectExtensions.cs | 17 - .../Extensions/StreamExtensions.cs | 15 - .../Framework.AutomationCore.csproj | 19 +- .../Helpers/DatabaseHelper.cs | 37 -- .../IRootServiceProviderContainer.cs | 16 + .../RootServiceProviderContainer.cs | 16 + .../RootServiceProviderContainerExtensions.cs | 45 +++ .../ServiceEnvironment/ControllerEvaluator.cs | 4 +- .../ServiceProviderExtensions.cs | 0 .../Services/BssTestingEvaluator.cs | 0 .../Services/IntegrationTestTimeProvider.cs | 0 .../TestWebApiCurrentMethodResolver.cs | 0 .../TestWebApiExceptionExpander.cs | 0 .../IServiceProviderPool.cs | 7 - .../ServiceProviderPool.cs | 56 ---- .../Settings/AutomationFrameworkSettings.cs | 6 +- .../DatabaseUtils/CoreDatabaseUtil.Helper.cs | 47 --- .../Utils/DatabaseUtils/CoreDatabaseUtil.cs | 317 ------------------ .../Utils/DatabaseUtils/DatabaseContext.cs | 96 ------ .../Utils/DatabaseUtils/DatabaseItem.cs | 74 ---- .../Interfaces/IDatabaseContext.cs | 12 - .../DatabaseUtils/Interfaces/IDatabaseItem.cs | 12 - .../Interfaces/ITestDatabaseGenerator.cs | 28 -- .../DatabaseUtils/TestDatabaseGenerator.cs | 93 ----- .../Utils/TextRandomizer.cs | 23 -- .../WebApi/IntegrationWebApiBase.cs | 2 +- .../WebApi/WebApiBase.cs | 0 .../Extensions/EnumerableExtensions.cs | 2 +- src/BssFramework.slnx | 5 +- .../FileFactory/BaseCodeDomHelper.cs | 2 +- ...tabase.NHibernate.DBGenerator.Tests.csproj | 2 +- .../AuditDatabaseScriptGenerator.cs | 8 +- .../AuditSqlScriptGenerator.cs | 6 +- .../AuditTableGenerateContext.cs | 6 +- .../Impl/MigrationDBScriptGeneratorBuilder.cs | 43 ++- .../Audit/AuditInterceptor.cs | 8 +- .../Audit/AuditPropertiesSetter.cs | 6 +- .../PrimitiveTypeFieldMapper.cs | 2 +- .../Framework.Tracking.Tests.csproj | 2 +- src/Directory.Build.props | 2 +- src/Directory.Packages.props | 9 +- .../CoreEnumerableExtensions.cs | 106 +++--- src/Framework.Core/CoreStringExtensions.cs | 2 +- src/Framework.Core/CoreTypeExtensions.cs | 30 +- src/Framework.Core/ExceptionEvaluator.cs | 6 +- .../Helpers/DataContractSerializerHelper.cs | 44 +-- .../Serialization/Base85Convert.cs | 105 +++--- src/Framework.Core/XDocumentExtensions.cs | 14 +- .../Framework.ExpressionParsers.Tests.csproj | 2 +- .../CSharp/CSharpNativeExpressionParser.cs | 2 +- ...icrosoftCSharpExpressionParserImplement.cs | 206 ++++++------ .../CSharp/RoslynCSharpExpressionParser.cs | 30 +- .../CSharp/ScriptEngineService.cs | 2 +- .../Framework.Validation.Tests.csproj | 2 +- ...ramework.Authorization.TestGenerate.csproj | 2 +- ...ramework.Configuration.TestGenerate.csproj | 2 +- .../Impl/QueueService.cs | 2 +- .../Services/IntegrationEventProcessor.cs | 2 +- .../SampleSystem.CheckGenTests.csproj | 2 +- .../SampleSystem.CodeGenerate.csproj | 2 +- .../SampleSystem.DbGenerate.NHibernate.csproj | 2 +- .../AsyncControllerTests.cs | 2 +- .../AuditTests.cs | 12 +- .../Auth/PrincipalTests.cs | 2 +- .../AuthPerfomanceTest.cs | 4 +- .../AuthPerformanceTests.cs | 2 +- .../BUProjectionTests.cs | 2 +- .../BusinessUnitTests.cs | 3 +- .../CurrentUserManyRelativePathTests.cs | 2 +- .../CurrentUserSingleRelativePathTests.cs | 2 +- .../CurrentUserSourceTests.cs | 2 +- .../ChangeIndexesStrategyTests.cs | 2 +- .../DBGeneration/GenerateDBTests.cs | 2 +- .../DBGeneration/SchemeUpdateTests.cs | 2 +- ...UniqueGroupDatabaseScriptGeneratorTests.cs | 2 +- .../DefaultFieldsTests.cs | 4 +- .../DependencySecurityTests.cs | 2 +- .../EmployeeProjectionTests.cs | 2 +- .../EmployeeTests.cs | 2 +- .../EnversBug1676.cs | 2 +- .../EventDALListenerTests.cs | 2 +- .../ExpandPathTests.cs | 2 +- .../ExtraQueryableSecurityPathTests.cs | 2 +- .../FixedPropertyValidatorTests.cs | 6 +- ...ionPrincipalsByHierarchicalContextTests.cs | 2 +- .../ImpersonateTests.cs | 2 +- .../InformationTest.cs | 2 +- .../IntegrationVersionTest.cs | 2 +- .../JobTests.cs | 2 +- .../JsonConverterTests.cs | 2 +- .../LegalEntityProjectionTests.cs | 2 +- .../ManagmentUnitFluentMappingTests.cs | 2 +- .../ManualAndLegacyProjectionSecurityTests.cs | 2 +- .../NH/FullTextSearchTests.cs | 2 +- .../NHibFetchTests.cs | 2 +- .../NhibArrayContainsTest.cs | 2 +- .../NhibDateTimeTests.cs | 8 +- .../NotificationCountryTests.cs | 2 +- .../OneToOneTests.cs | 2 +- .../PerfomanceTests.cs | 2 +- .../PrincipalTests.cs | 2 +- .../PrincipalWithInitTests.cs | 2 +- .../RepositoryControllerTests.cs | 2 +- .../RepositoryWithoutSecurityTests.cs | 2 +- .../RestrictionRoleTests.cs | 2 +- ...eSystem.IntegrationTests.NHibernate.csproj | 4 +- .../SecurityContextRestrictionFilterTests.cs | 2 +- .../SecurityPathTests.cs | 2 +- .../SecurityRuleTests.cs | 2 +- .../SequenceBllTests.cs | 2 +- .../SqlParserTests.cs | 10 +- ...bscriptionCustomNotPersistentModelTests.cs | 2 +- .../MetadataSubscriptionSystemServiceTests.cs | 2 +- .../TransactionFlushBeforeCommit.cs | 2 +- .../UniqueGroupTests.cs | 2 +- .../UpdateTests.cs | 2 +- .../ValidationTests.cs | 2 +- .../VirtualPermissionTests.cs | 2 +- .../WebApi/EmployeeTests.cs | 2 +- .../WrongSecurityMessageTests.cs | 2 +- .../__Support/InitializeAndCleanup.cs | 80 ++--- .../__Support/TestCollection.cs | 6 - .../TestData/Helpers/DataHelper.Init.cs | 4 +- .../__Support/TestData/Helpers/DataHelper.cs | 6 +- .../__Support/TestData/TestBase.cs | 28 +- .../SampleSystemTestDatabaseGenerator.cs | 104 +++--- ...m.IntegrationTests.Xunit.NHibernate.csproj | 30 -- .../ServiceProviderMemberDataTest.cs | 19 -- .../__Support/Database/DatabaseGenerator.cs | 52 --- .../__Support/EnvironmentInitializer.cs | 53 --- .../__Support/TestBase.cs | 6 - .../__Support/TestData/TestDataInitializer.cs | 264 --------------- .../appsettings.json | 21 -- .../SampleSystem.UnitTests.csproj | 2 +- 165 files changed, 774 insertions(+), 2617 deletions(-) create mode 100644 src/Anch.Testing.Database.Mssql/Anch.Testing.Database.Mssql.csproj create mode 100644 src/Anch.Testing.Database.Mssql/MssqlDatabaseFilePathExtractor.cs create mode 100644 src/Anch.Testing.Database.Mssql/MssqlDatabaseTestingProvider.cs create mode 100644 src/Anch.Testing.Database.Mssql/MssqlTestDatabaseConnectionStringBuilder.cs rename src/AutomationCore/{Framework.AutomationCore.ServiceEnvironment.LegacyContext/Framework.AutomationCore.ServiceEnvironment.LegacyContext.csproj => Framework.AutomationCore.Legacy/Framework.AutomationCore.Legacy.csproj} (72%) create mode 100644 src/AutomationCore/Framework.AutomationCore.Legacy/IntegrationTestBase.cs rename src/AutomationCore/{Framework.AutomationCore.ServiceEnvironment.LegacyContext => Framework.AutomationCore.Legacy}/RootServiceProviderContainer/ContextEvaluatorExtensions.cs (100%) rename src/AutomationCore/{Framework.AutomationCore.ServiceEnvironment.LegacyContext => Framework.AutomationCore.Legacy}/RootServiceProviderContainer/ContextEvaluatorWithMappingExtensions.cs (100%) rename src/AutomationCore/{Framework.AutomationCore.ServiceEnvironment.LegacyContext => Framework.AutomationCore.Legacy}/RootServiceProviderContainer/IRootServiceProviderContainer.cs (100%) create mode 100644 src/AutomationCore/Framework.AutomationCore.Legacy/RootServiceProviderContainer/RootServiceProviderContainer.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/IntegrationTestBase.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/RootServiceProviderContainer/RootServiceProviderContainer.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/Framework.AutomationCore.ServiceEnvironment.csproj delete mode 100644 src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/IntegrationTestBase.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/RootServiceProviderContainer/IRootServiceProviderContainer.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/RootServiceProviderContainer/RootServiceProviderContainer.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/RootServiceProviderContainer/RootServiceProviderContainerExtensions.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/TestInitializeAndCleanup.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore.Xunit/ServiceEnvironment/DiAssemblyInitializeAndCleanup.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore.Xunit/ServiceEnvironment/DiTestInitializeAndCleanup.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore.Xunit/ServiceProviderPool/DiServiceProviderPool.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore.Xunit/ServiceProviderPool/ServiceProviderPoolFunc.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/AssemblyInitializeAndCleanup.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/AssemblyInitializeAndCleanupBase.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Enums/TestRunMode.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Environment/TestEnvironment.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Environment/TestEnvironmentBuilder.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Extensions/ConfigurationExtensions.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Extensions/Excel/Column.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Extensions/ObjectExtensions.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Extensions/StreamExtensions.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Helpers/DatabaseHelper.cs create mode 100644 src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/IRootServiceProviderContainer.cs create mode 100644 src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/RootServiceProviderContainer.cs create mode 100644 src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/RootServiceProviderContainerExtensions.cs rename src/AutomationCore/{Framework.AutomationCore.ServiceEnvironment => Framework.AutomationCore}/ServiceEnvironment/ControllerEvaluator.cs (98%) rename src/AutomationCore/{Framework.AutomationCore.ServiceEnvironment => Framework.AutomationCore}/ServiceEnvironment/ServiceProviderExtensions.cs (100%) rename src/AutomationCore/{Framework.AutomationCore.ServiceEnvironment => Framework.AutomationCore}/ServiceEnvironment/Services/BssTestingEvaluator.cs (100%) rename src/AutomationCore/{Framework.AutomationCore.ServiceEnvironment => Framework.AutomationCore}/ServiceEnvironment/Services/IntegrationTestTimeProvider.cs (100%) rename src/AutomationCore/{Framework.AutomationCore.ServiceEnvironment => Framework.AutomationCore}/ServiceEnvironment/TestWebApiCurrentMethodResolver.cs (100%) rename src/AutomationCore/{Framework.AutomationCore.ServiceEnvironment => Framework.AutomationCore}/ServiceEnvironment/TestWebApiExceptionExpander.cs (100%) delete mode 100644 src/AutomationCore/Framework.AutomationCore/ServiceProviderPool/IServiceProviderPool.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/ServiceProviderPool/ServiceProviderPool.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.Helper.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseItem.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseContext.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseItem.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/ITestDatabaseGenerator.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/TestDatabaseGenerator.cs delete mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/TextRandomizer.cs rename src/AutomationCore/{Framework.AutomationCore.ServiceEnvironment => Framework.AutomationCore}/WebApi/IntegrationWebApiBase.cs (81%) rename src/AutomationCore/{Framework.AutomationCore.ServiceEnvironment => Framework.AutomationCore}/WebApi/WebApiBase.cs (100%) delete mode 100644 src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestCollection.cs delete mode 100644 src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/SampleSystem.IntegrationTests.Xunit.NHibernate.csproj delete mode 100644 src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/ServiceProviderMemberDataTest.cs delete mode 100644 src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/Database/DatabaseGenerator.cs delete mode 100644 src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/EnvironmentInitializer.cs delete mode 100644 src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/TestBase.cs delete mode 100644 src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/TestData/TestDataInitializer.cs delete mode 100644 src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/appsettings.json diff --git a/src/Anch.Testing.Database.Mssql/Anch.Testing.Database.Mssql.csproj b/src/Anch.Testing.Database.Mssql/Anch.Testing.Database.Mssql.csproj new file mode 100644 index 000000000..de4c36d99 --- /dev/null +++ b/src/Anch.Testing.Database.Mssql/Anch.Testing.Database.Mssql.csproj @@ -0,0 +1,11 @@ + + + + Anch.Testing.Database.Mssql + + + + + + + diff --git a/src/Anch.Testing.Database.Mssql/MssqlDatabaseFilePathExtractor.cs b/src/Anch.Testing.Database.Mssql/MssqlDatabaseFilePathExtractor.cs new file mode 100644 index 000000000..c5a18b593 --- /dev/null +++ b/src/Anch.Testing.Database.Mssql/MssqlDatabaseFilePathExtractor.cs @@ -0,0 +1,26 @@ +using System.Data.Common; + +using Anch.Testing.Database.ConnectionStringManagement; + +namespace Anch.Testing.Database.Mssql; + +public class MssqlDatabaseFilePathExtractor : IDatabaseFilePathExtractor +{ + public string Extract(TestDatabaseConnectionString connectionString) + { + var builder = new DbConnectionStringBuilder + { + ConnectionString = connectionString.Value + }; + + if (!builder.TryGetValue("Data Source", out var value)) + throw new InvalidOperationException("Data Source is missing."); + + var dataSource = value?.ToString(); + + if (string.IsNullOrWhiteSpace(dataSource)) + throw new InvalidOperationException("Data Source is empty."); + + return dataSource; + } +} diff --git a/src/Anch.Testing.Database.Mssql/MssqlDatabaseTestingProvider.cs b/src/Anch.Testing.Database.Mssql/MssqlDatabaseTestingProvider.cs new file mode 100644 index 000000000..8af67647f --- /dev/null +++ b/src/Anch.Testing.Database.Mssql/MssqlDatabaseTestingProvider.cs @@ -0,0 +1,15 @@ +using Anch.Testing.Database.ConnectionStringManagement; +using Anch.Testing.Database.DependencyInjection; + +using Microsoft.Extensions.DependencyInjection; + +namespace Anch.Testing.Database.Mssql; + +public class MssqlDatabaseTestingProvider : IDatabaseTestingProvider +{ + public void AddServices(IServiceCollection services) + { + services.AddSingleton() + .AddSingleton(); + } +} diff --git a/src/Anch.Testing.Database.Mssql/MssqlTestDatabaseConnectionStringBuilder.cs b/src/Anch.Testing.Database.Mssql/MssqlTestDatabaseConnectionStringBuilder.cs new file mode 100644 index 000000000..4aca1c191 --- /dev/null +++ b/src/Anch.Testing.Database.Mssql/MssqlTestDatabaseConnectionStringBuilder.cs @@ -0,0 +1,31 @@ +using System.Data.Common; + +using Anch.Testing.Database.ConnectionStringManagement; + +namespace Anch.Testing.Database.Mssql; + +public class MssqlTestDatabaseConnectionStringBuilder(TestDatabaseSettings databaseSettings) : ITestDatabaseConnectionStringBuilder +{ + public TestDatabaseConnectionString AddPostfix(string postfix) + { + var builder = new DbConnectionStringBuilder { ConnectionString = databaseSettings.DefaultConnectionString.Value }; + + var dataSource = builder["Data Source"]?.ToString(); + + if (string.IsNullOrWhiteSpace(dataSource)) + throw new InvalidOperationException("Data Source is missing in connection string."); + + var directory = Path.GetDirectoryName(dataSource); + var fileName = Path.GetFileNameWithoutExtension(dataSource); + var extension = Path.GetExtension(dataSource); + + var newFileName = $"{fileName}{postfix}{extension}"; + var newDataSource = directory is null + ? newFileName + : Path.Combine(directory, newFileName); + + builder["Data Source"] = newDataSource; + + return new TestDatabaseConnectionString(builder.ConnectionString); + } +} diff --git a/src/Application/Framework.Application.Tests/Framework.Application.Tests.csproj b/src/Application/Framework.Application.Tests/Framework.Application.Tests.csproj index f6403c8e1..7395050bc 100644 --- a/src/Application/Framework.Application.Tests/Framework.Application.Tests.csproj +++ b/src/Application/Framework.Application.Tests/Framework.Application.Tests.csproj @@ -10,7 +10,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/Framework.AutomationCore.ServiceEnvironment.LegacyContext.csproj b/src/AutomationCore/Framework.AutomationCore.Legacy/Framework.AutomationCore.Legacy.csproj similarity index 72% rename from src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/Framework.AutomationCore.ServiceEnvironment.LegacyContext.csproj rename to src/AutomationCore/Framework.AutomationCore.Legacy/Framework.AutomationCore.Legacy.csproj index e9e84160c..bb3f58337 100644 --- a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/Framework.AutomationCore.ServiceEnvironment.LegacyContext.csproj +++ b/src/AutomationCore/Framework.AutomationCore.Legacy/Framework.AutomationCore.Legacy.csproj @@ -1,7 +1,7 @@  - Luxoft.Framework.AutomationCore.ServiceEnvironment.LegacyContext + Luxoft.Framework.AutomationCore.Legacy Framework.AutomationCore @@ -15,7 +15,7 @@ - + diff --git a/src/AutomationCore/Framework.AutomationCore.Legacy/IntegrationTestBase.cs b/src/AutomationCore/Framework.AutomationCore.Legacy/IntegrationTestBase.cs new file mode 100644 index 000000000..db393affa --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore.Legacy/IntegrationTestBase.cs @@ -0,0 +1,101 @@ +using Anch.Core; + +using Framework.Application; +using Framework.Application.Repository; +using Framework.AutomationCore.RootServiceProviderContainer; +using Framework.BLL.DTOMapping.Domain; +using Framework.Configuration.BLL; +using Framework.Configuration.Domain; +using Framework.Core; +using Framework.Core.Helpers; +using Framework.Database; +using Framework.Notification.DTO; + +using Microsoft.Extensions.DependencyInjection; + +using Anch.SecuritySystem; + +namespace Framework.AutomationCore; + +//public abstract class IntegrationTestBase(IServiceProvider rootServiceProvider) : IRootServiceProviderContainer +// where TBLLContext : IServiceProviderContainer +//{ +// public IServiceProvider RootServiceProvider { get; } = rootServiceProvider; + +// public Task EvaluateAsync( +// DBSessionMode sessionMode, +// UserCredential? customUserCredential, +// Func> getResult) => +// rootServiceProvider.GetRequiredService>().EvaluateAsync(sessionMode, customUserCredential, getResult); + + +// protected IConfigurationBLLContext GetConfigurationBLLContext(TBLLContext context) => context.ServiceProvider.GetRequiredService(); + +// /// +// /// Отчистка списка нотифицаций +// /// +// public virtual void ClearNotifications() => +// this.EvaluateWrite(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectNotification.Pipe(bll => bll.GetFullList().ForEach(bll.Remove))); + +// /// +// /// Получение списка модификаций +// /// +// /// +// protected virtual List> GetModifications() => +// this.EvaluateRead(context => + +// this.GetConfigurationBLLContext(context).Logics.DomainObjectModification.GetFullList() +// .ToList(mod => new ObjectModificationInfoDTO +// { +// Identity = mod.DomainObjectId, +// ModificationType = mod.Type, +// Revision = mod.Revision, +// TypeInfoDescription = new TypeInfoDescriptionDTO { Name = mod.DomainType.Name, Namespace = mod.DomainType.Namespace } +// })); + +// /// +// /// Отчистка списка модификаций +// /// +// protected virtual void ClearModifications() => +// this.EvaluateWrite(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectModification.Pipe(bll => bll.GetFullList().ForEach(bll.Remove))); + +// /// +// /// Отчистка интеграционных евентов +// /// +// public virtual void ClearIntegrationEvents() +// { +// this.ClearModifications(); + +// this.EvaluateWrite(context => +// { +// var bll = this.GetConfigurationBLLContext(context).Logics.Default.Create(); + +// bll.GetFullList().ForEach(bll.Remove); +// }); +// } + +// protected int GetIntegrationEventCount() => +// this.EvaluateRead(ctx => ctx.ServiceProvider.GetRequiredService>().Create().GetQueryable().Count()); + + +// /// +// /// Получение интегационных евентов +// /// +// /// +// protected virtual List GetIntegrationEvents(string queueTag = "default") +// { +// var serializeType = typeof(T).FullName; + +// return this.EvaluateRead(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectEvent +// .GetListBy(v => v.SerializeType == serializeType && v.QueueTag == queueTag) +// .ToList(obj => DataContractSerializerHelper.Deserialize(obj.SerializeData))); +// } + +// /// +// /// Получение списка нотификаций +// /// +// /// +// protected virtual List GetNotifications() => +// this.EvaluateRead(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectNotification.GetFullList() +// .ToList(obj => DataContractSerializerHelper.Deserialize(obj.SerializeData))); +//} diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/RootServiceProviderContainer/ContextEvaluatorExtensions.cs b/src/AutomationCore/Framework.AutomationCore.Legacy/RootServiceProviderContainer/ContextEvaluatorExtensions.cs similarity index 100% rename from src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/RootServiceProviderContainer/ContextEvaluatorExtensions.cs rename to src/AutomationCore/Framework.AutomationCore.Legacy/RootServiceProviderContainer/ContextEvaluatorExtensions.cs diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/RootServiceProviderContainer/ContextEvaluatorWithMappingExtensions.cs b/src/AutomationCore/Framework.AutomationCore.Legacy/RootServiceProviderContainer/ContextEvaluatorWithMappingExtensions.cs similarity index 100% rename from src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/RootServiceProviderContainer/ContextEvaluatorWithMappingExtensions.cs rename to src/AutomationCore/Framework.AutomationCore.Legacy/RootServiceProviderContainer/ContextEvaluatorWithMappingExtensions.cs diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/RootServiceProviderContainer/IRootServiceProviderContainer.cs b/src/AutomationCore/Framework.AutomationCore.Legacy/RootServiceProviderContainer/IRootServiceProviderContainer.cs similarity index 100% rename from src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/RootServiceProviderContainer/IRootServiceProviderContainer.cs rename to src/AutomationCore/Framework.AutomationCore.Legacy/RootServiceProviderContainer/IRootServiceProviderContainer.cs diff --git a/src/AutomationCore/Framework.AutomationCore.Legacy/RootServiceProviderContainer/RootServiceProviderContainer.cs b/src/AutomationCore/Framework.AutomationCore.Legacy/RootServiceProviderContainer/RootServiceProviderContainer.cs new file mode 100644 index 000000000..7e236216c --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore.Legacy/RootServiceProviderContainer/RootServiceProviderContainer.cs @@ -0,0 +1,3 @@ +namespace Framework.AutomationCore.RootServiceProviderContainer; + +public class RootServiceProviderContainer(IServiceProvider rootServiceProvider) : RootServiceProviderContainer(rootServiceProvider), IRootServiceProviderContainer; diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/IntegrationTestBase.cs b/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/IntegrationTestBase.cs deleted file mode 100644 index ceb3b13a1..000000000 --- a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/IntegrationTestBase.cs +++ /dev/null @@ -1,101 +0,0 @@ -using Anch.Core; - -using Framework.Application; -using Framework.Application.Repository; -using Framework.AutomationCore.RootServiceProviderContainer; -using Framework.AutomationCore.ServiceProviderPool; -using Framework.BLL.DTOMapping.Domain; -using Framework.Configuration.BLL; -using Framework.Configuration.Domain; -using Framework.Core; -using Framework.Core.Helpers; -using Framework.Database; -using Framework.Notification.DTO; - -using Microsoft.Extensions.DependencyInjection; - -using Anch.SecuritySystem; - -namespace Framework.AutomationCore; - -public abstract class IntegrationTestBase(IServiceProviderPool rootServiceProviderPool) - : IntegrationTestBase(rootServiceProviderPool), IRootServiceProviderContainer - where TBLLContext : IServiceProviderContainer -{ - public Task EvaluateAsync( - DBSessionMode sessionMode, - UserCredential? customUserCredential, - Func> getResult) => - this.RootServiceProvider.GetRequiredService>().EvaluateAsync(sessionMode, customUserCredential, getResult); - - - protected IConfigurationBLLContext GetConfigurationBLLContext(TBLLContext context) => context.ServiceProvider.GetRequiredService(); - - /// - /// Отчистка списка нотифицаций - /// - public override void ClearNotifications() => - this.EvaluateWrite(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectNotification.Pipe(bll => bll.GetFullList().ForEach(bll.Remove))); - - /// - /// Получение списка модификаций - /// - /// - protected virtual List> GetModifications() => - this.EvaluateRead(context => - - this.GetConfigurationBLLContext(context).Logics.DomainObjectModification.GetFullList() - .ToList(mod => new ObjectModificationInfoDTO - { - Identity = mod.DomainObjectId, - ModificationType = mod.Type, - Revision = mod.Revision, - TypeInfoDescription = new TypeInfoDescriptionDTO { Name = mod.DomainType.Name, Namespace = mod.DomainType.Namespace } - })); - - /// - /// Отчистка списка модификаций - /// - protected virtual void ClearModifications() => - this.EvaluateWrite(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectModification.Pipe(bll => bll.GetFullList().ForEach(bll.Remove))); - - /// - /// Отчистка интеграционных евентов - /// - public override void ClearIntegrationEvents() - { - this.ClearModifications(); - - this.EvaluateWrite(context => - { - var bll = this.GetConfigurationBLLContext(context).Logics.Default.Create(); - - bll.GetFullList().ForEach(bll.Remove); - }); - } - - protected int GetIntegrationEventCount() => - this.EvaluateRead(ctx => ctx.ServiceProvider.GetRequiredService>().Create().GetQueryable().Count()); - - - /// - /// Получение интегационных евентов - /// - /// - protected virtual List GetIntegrationEvents(string queueTag = "default") - { - var serializeType = typeof(T).FullName; - - return this.EvaluateRead(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectEvent - .GetListBy(v => v.SerializeType == serializeType && v.QueueTag == queueTag) - .ToList(obj => DataContractSerializerHelper.Deserialize(obj.SerializeData))); - } - - /// - /// Получение списка нотификаций - /// - /// - protected virtual List GetNotifications() => - this.EvaluateRead(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectNotification.GetFullList() - .ToList(obj => DataContractSerializerHelper.Deserialize(obj.SerializeData))); -} diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/RootServiceProviderContainer/RootServiceProviderContainer.cs b/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/RootServiceProviderContainer/RootServiceProviderContainer.cs deleted file mode 100644 index f13c8b40f..000000000 --- a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment.LegacyContext/RootServiceProviderContainer/RootServiceProviderContainer.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace Framework.AutomationCore.RootServiceProviderContainer; - -public abstract class RootServiceProviderContainer(IServiceProvider rootServiceProvider) - : RootServiceProviderContainer(rootServiceProvider), IRootServiceProviderContainer; diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/Framework.AutomationCore.ServiceEnvironment.csproj b/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/Framework.AutomationCore.ServiceEnvironment.csproj deleted file mode 100644 index d413da5e6..000000000 --- a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/Framework.AutomationCore.ServiceEnvironment.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - Luxoft.Framework.AutomationCore.ServiceEnvironment - Framework.AutomationCore - - - - - - - - - - - - - - - - diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/IntegrationTestBase.cs b/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/IntegrationTestBase.cs deleted file mode 100644 index a0bcb5cf1..000000000 --- a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/IntegrationTestBase.cs +++ /dev/null @@ -1,82 +0,0 @@ -using Framework.AutomationCore.Enums; -using Framework.AutomationCore.ServiceEnvironment.Services; -using Framework.AutomationCore.ServiceProviderPool; -using Framework.AutomationCore.Utils.DatabaseUtils; - -using Microsoft.Extensions.DependencyInjection; - -using Anch.SecuritySystem.Testing; - -namespace Framework.AutomationCore; - -public abstract class IntegrationTestBase(IServiceProviderPool rootServiceProviderPool) - : RootServiceProviderContainer.RootServiceProviderContainer(rootServiceProviderPool.Get()) -{ - public virtual void Initialize() - { - this.ReattachDatabase(); - this.ClearNotifications(); - this.ClearIntegrationEvents(); - this.ResetServices(); - } - - public virtual void Cleanup() - { - try - { - this.DropDatabaseAfterTest(); - this.CleanupTestEnvironment(); - } - finally - { - this.ReleaseServiceProvider(); - } - } - - protected virtual void ResetServices() - { - this.RootServiceProvider.GetService()?.Reset(); - this.RootServiceProvider.GetService()?.Reset(); - } - - protected virtual void DropDatabaseAfterTest() - { - if (this.AutomationFrameworkSettings.UseLocalDb || this.AutomationFrameworkSettings.TestRunMode == TestRunMode.DefaultRunModeOnEmptyDatabase) - { - AssemblyInitializeAndCleanupBase.RunAction("Drop Database", this.DatabaseContext.Drop); - } - } - - protected virtual void ReleaseServiceProvider() - => rootServiceProviderPool.Release(this.RootServiceProvider); - - protected virtual void ReattachDatabase() - { - switch (this.AutomationFrameworkSettings.TestRunMode) - { - case TestRunMode.DefaultRunModeOnEmptyDatabase: - case TestRunMode.RestoreDatabaseUsingAttach: - AssemblyInitializeAndCleanupBase.RunAction("Drop Database", this.DatabaseContext.Drop); - AssemblyInitializeAndCleanupBase.RunAction("Restore Databases", this.DatabaseContext.AttachDatabase); - break; - } - } - - protected virtual void CleanupTestEnvironment() - { - } - - /// - /// Отчистка списка нотифицаций - /// - public virtual void ClearNotifications() - { - } - - /// - /// Отчистка интеграционных евентов - /// - public virtual void ClearIntegrationEvents() - { - } -} diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/RootServiceProviderContainer/IRootServiceProviderContainer.cs b/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/RootServiceProviderContainer/IRootServiceProviderContainer.cs deleted file mode 100644 index ed88e6f66..000000000 --- a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/RootServiceProviderContainer/IRootServiceProviderContainer.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Framework.AutomationCore.RootServiceProviderContainer; - -public interface IRootServiceProviderContainer -{ - IServiceProvider RootServiceProvider { get; } -} diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/RootServiceProviderContainer/RootServiceProviderContainer.cs b/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/RootServiceProviderContainer/RootServiceProviderContainer.cs deleted file mode 100644 index 461122bdb..000000000 --- a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/RootServiceProviderContainer/RootServiceProviderContainer.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Framework.Application.FinancialYear; -using Framework.AutomationCore.ServiceEnvironment; -using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.DependencyInjection; - -using Anch.SecuritySystem; - -namespace Framework.AutomationCore.RootServiceProviderContainer; - -public abstract class RootServiceProviderContainer(IServiceProvider rootServiceProvider) : IRootServiceProviderContainer -{ - public virtual IServiceProvider RootServiceProvider { get; } = rootServiceProvider; - - public AutomationFrameworkSettings AutomationFrameworkSettings => this.GetAutomationFrameworkSettings(); - - public TimeProvider TimeProvider => this.GetTimeProvider(); - - public IFinancialYearService FinancialYearService => this.RootServiceProvider.GetRequiredService(); - - public IDatabaseContext DatabaseContext => this.GetDatabaseContext(); - - public virtual ControllerEvaluator GetControllerEvaluator(UserCredential? userCredential = null) - where TController : ControllerBase => - this.RootServiceProvider.GetDefaultControllerEvaluator(userCredential); -} diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/RootServiceProviderContainer/RootServiceProviderContainerExtensions.cs b/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/RootServiceProviderContainer/RootServiceProviderContainerExtensions.cs deleted file mode 100644 index f41948f98..000000000 --- a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/RootServiceProviderContainer/RootServiceProviderContainerExtensions.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Linq.Expressions; - -using Framework.AutomationCore.ServiceEnvironment; -using Framework.AutomationCore.ServiceEnvironment.Services; -using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; - -namespace Framework.AutomationCore.RootServiceProviderContainer; - -public static class RootServiceProviderContainerExtensions -{ - extension(IRootServiceProviderContainer rootServiceProviderContainer) - { - public IDatabaseContext GetDatabaseContext() => rootServiceProviderContainer.RootServiceProvider.GetRequiredService(); - - public AutomationFrameworkSettings GetAutomationFrameworkSettings() => rootServiceProviderContainer.RootServiceProvider.GetRequiredService>().Value; - - public TimeProvider GetTimeProvider() => rootServiceProviderContainer.RootServiceProvider.GetRequiredService(); - - public void SetCurrentDateTime(DateTime newDateTime) => rootServiceProviderContainer.RootServiceProvider.GetRequiredService().SetCurrentDateTime(newDateTime); - - public TResult EvaluateController(Expression> func) - where TController : ControllerBase => - rootServiceProviderContainer.RootServiceProvider.GetDefaultControllerEvaluator().Evaluate(func); - - public void EvaluateController(Expression> action) - where TController : ControllerBase => - rootServiceProviderContainer.RootServiceProvider.GetDefaultControllerEvaluator().Evaluate(action); - } -} diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/TestInitializeAndCleanup.cs b/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/TestInitializeAndCleanup.cs deleted file mode 100644 index 8a26d3115..000000000 --- a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/TestInitializeAndCleanup.cs +++ /dev/null @@ -1,62 +0,0 @@ -using Framework.AutomationCore.Enums; -using Framework.AutomationCore.ServiceEnvironment.Services; -using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Utils.DatabaseUtils; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -using Microsoft.Extensions.Options; - -using Anch.SecuritySystem.Testing; - -namespace Framework.AutomationCore; - -public class TestInitializeAndCleanup( - IOptions settings, - IDatabaseContext databaseContext, - IntegrationTestTimeProvider timeProvider, - RootImpersonateServiceState rootImpersonateServiceState) -{ - private readonly AutomationFrameworkSettings settings = settings.Value; - - public virtual async Task InitializeAsync() - { - this.ReattachDatabase(); - this.ResetServices(); - } - - public virtual async Task CleanupAsync() - { - this.DropDatabaseAfterTest(); - this.CleanupTestEnvironment(); - } - - protected virtual void ResetServices() - { - timeProvider.Reset(); - rootImpersonateServiceState.Reset(); - } - - protected virtual void DropDatabaseAfterTest() - { - if (this.settings.UseLocalDb || this.settings.TestRunMode == TestRunMode.DefaultRunModeOnEmptyDatabase || this.settings.TestsParallelize) - { - AssemblyInitializeAndCleanupBase.RunAction("Drop Database", databaseContext.Drop); - } - } - - protected virtual void ReattachDatabase() - { - switch (this.settings.TestRunMode) - { - case TestRunMode.DefaultRunModeOnEmptyDatabase: - case TestRunMode.RestoreDatabaseUsingAttach: - AssemblyInitializeAndCleanupBase.RunAction("Drop Database", databaseContext.Drop); - AssemblyInitializeAndCleanupBase.RunAction("Restore Databases", databaseContext.AttachDatabase); - break; - } - } - - protected virtual void CleanupTestEnvironment() - { - } -} diff --git a/src/AutomationCore/Framework.AutomationCore.Xunit/Framework.AutomationCore.Xunit.csproj b/src/AutomationCore/Framework.AutomationCore.Xunit/Framework.AutomationCore.Xunit.csproj index d92a0413a..995539b25 100644 --- a/src/AutomationCore/Framework.AutomationCore.Xunit/Framework.AutomationCore.Xunit.csproj +++ b/src/AutomationCore/Framework.AutomationCore.Xunit/Framework.AutomationCore.Xunit.csproj @@ -8,12 +8,4 @@ - - - - - - - - diff --git a/src/AutomationCore/Framework.AutomationCore.Xunit/ServiceEnvironment/DiAssemblyInitializeAndCleanup.cs b/src/AutomationCore/Framework.AutomationCore.Xunit/ServiceEnvironment/DiAssemblyInitializeAndCleanup.cs deleted file mode 100644 index a578f2d4a..000000000 --- a/src/AutomationCore/Framework.AutomationCore.Xunit/ServiceEnvironment/DiAssemblyInitializeAndCleanup.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Bss.Testing.Xunit.Interfaces; - -using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -using Microsoft.Extensions.Options; - -namespace Framework.AutomationCore.Xunit.ServiceEnvironment; - -public class DiAssemblyInitializeAndCleanup( - IOptions settings, - ITestDatabaseGenerator databaseGenerator) - : AssemblyInitializeAndCleanupBase, IAssemblyInitializeAndCleanup -{ - private readonly AutomationFrameworkSettings settings = settings.Value; - - public async Task EnvironmentInitializeAsync() => await this.InitializeAsync(this.settings, databaseGenerator); - - public async Task EnvironmentCleanupAsync() => await this.CleanupAsync(this.settings, databaseGenerator); -} diff --git a/src/AutomationCore/Framework.AutomationCore.Xunit/ServiceEnvironment/DiTestInitializeAndCleanup.cs b/src/AutomationCore/Framework.AutomationCore.Xunit/ServiceEnvironment/DiTestInitializeAndCleanup.cs deleted file mode 100644 index 0abbf7997..000000000 --- a/src/AutomationCore/Framework.AutomationCore.Xunit/ServiceEnvironment/DiTestInitializeAndCleanup.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Bss.Testing.Xunit.Interfaces; - -using Framework.AutomationCore.ServiceEnvironment.Services; -using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -using Microsoft.Extensions.Options; - -using Anch.SecuritySystem.Testing; - -namespace Framework.AutomationCore.Xunit.ServiceEnvironment; - -public class DiTestInitializeAndCleanup( - IOptions settings, - IDatabaseContext databaseContext, - IntegrationTestTimeProvider timeProvider, - RootImpersonateServiceState rootImpersonateServiceState) - : TestInitializeAndCleanup(settings, databaseContext, timeProvider, rootImpersonateServiceState), - ITestInitializeAndCleanup; diff --git a/src/AutomationCore/Framework.AutomationCore.Xunit/ServiceProviderPool/DiServiceProviderPool.cs b/src/AutomationCore/Framework.AutomationCore.Xunit/ServiceProviderPool/DiServiceProviderPool.cs deleted file mode 100644 index 879bf7ce8..000000000 --- a/src/AutomationCore/Framework.AutomationCore.Xunit/ServiceProviderPool/DiServiceProviderPool.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Collections.Concurrent; - -using Bss.Testing.Xunit.Interfaces; - -namespace Framework.AutomationCore.Xunit.ServiceProviderPool; - -public class DiServiceProviderPool(ServiceProviderPoolFunc createServiceProviderFunc) : ITestServiceProviderPool -{ - private readonly Func createServiceProviderFunc = createServiceProviderFunc.Value; - private readonly ConcurrentBag providersCache = []; - - public IServiceProvider Get() => - this.providersCache.TryTake(out var provider) ? provider : this.createServiceProviderFunc.Invoke(); - - public void Release(IServiceProvider serviceProvider) => this.providersCache.Add(serviceProvider); -} diff --git a/src/AutomationCore/Framework.AutomationCore.Xunit/ServiceProviderPool/ServiceProviderPoolFunc.cs b/src/AutomationCore/Framework.AutomationCore.Xunit/ServiceProviderPool/ServiceProviderPoolFunc.cs deleted file mode 100644 index 15409c654..000000000 --- a/src/AutomationCore/Framework.AutomationCore.Xunit/ServiceProviderPool/ServiceProviderPoolFunc.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Framework.AutomationCore.Xunit.ServiceProviderPool; - -public class ServiceProviderPoolFunc(Func func) -{ - public readonly Func Value = func; -} diff --git a/src/AutomationCore/Framework.AutomationCore/AssemblyInitializeAndCleanup.cs b/src/AutomationCore/Framework.AutomationCore/AssemblyInitializeAndCleanup.cs deleted file mode 100644 index e20aa7a52..000000000 --- a/src/AutomationCore/Framework.AutomationCore/AssemblyInitializeAndCleanup.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; - -namespace Framework.AutomationCore; - -public class AssemblyInitializeAndCleanup( - Func getServiceProviderAction, - Action releaseServiceProviderAction) - : AssemblyInitializeAndCleanupBase -{ - public async Task EnvironmentInitializeAsync() - { - var serviceProvider = getServiceProviderAction.Invoke(); - - try - { - await this.InitializeAsync(serviceProvider); - } - finally - { - releaseServiceProviderAction(serviceProvider); - } - } - - public async Task EnvironmentCleanupAsync() - { - var serviceProvider = getServiceProviderAction.Invoke(); - try - { - await this.CleanupAsync(serviceProvider); - } - finally - { - releaseServiceProviderAction(serviceProvider); - } - } - - protected async Task CleanupAsync(IServiceProvider serviceProvider) - { - var settings = serviceProvider.GetRequiredService>(); - var databaseGenerator = serviceProvider.GetRequiredService(); - - await this.CleanupAsync(settings.Value, databaseGenerator); - } - - protected async Task InitializeAsync(IServiceProvider serviceProvider) - { - var settings = serviceProvider.GetRequiredService>(); - var databaseGenerator = serviceProvider.GetRequiredService(); - - await this.InitializeAsync(settings.Value, databaseGenerator); - } -} diff --git a/src/AutomationCore/Framework.AutomationCore/AssemblyInitializeAndCleanupBase.cs b/src/AutomationCore/Framework.AutomationCore/AssemblyInitializeAndCleanupBase.cs deleted file mode 100644 index 84a8a1fe6..000000000 --- a/src/AutomationCore/Framework.AutomationCore/AssemblyInitializeAndCleanupBase.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System.Diagnostics; - -using Framework.AutomationCore.Enums; -using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Utils.DatabaseUtils; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -namespace Framework.AutomationCore; - -public class AssemblyInitializeAndCleanupBase -{ - public static void RunAction(string name, Action action) - { - var watch = new Stopwatch(); - - Console.WriteLine(name); - - watch.Start(); - action(); - watch.Stop(); - - Console.WriteLine("Elapsed time - {0}", watch.Elapsed); - Console.WriteLine(); - Console.WriteLine(); - } - - protected virtual async Task CleanupAsync(AutomationFrameworkSettings settings, ITestDatabaseGenerator databaseGenerator) - { - switch (settings.TestRunMode) - { - case TestRunMode.DefaultRunModeOnEmptyDatabase: - await databaseGenerator.CheckTestDatabaseAsync(); - databaseGenerator.DatabaseContext.Drop(); - databaseGenerator.DeleteDetachedFiles(); - databaseGenerator.DeleteLocalDb(); - break; - - default: - databaseGenerator.DeleteLocalDb(); - break; - } - } - - - protected virtual async Task InitializeAsync(AutomationFrameworkSettings settings, ITestDatabaseGenerator databaseGenerator) - { - switch (settings.TestRunMode) - { - case TestRunMode.RestoreDatabaseUsingAttach: - databaseGenerator.CreateLocalDb(); - await databaseGenerator.CheckTestDatabaseAsync(); - await databaseGenerator.CheckAndCreateDetachedFilesAsync(); - databaseGenerator.DatabaseContext.Drop(); - break; - case TestRunMode.GenerateTestDataOnExistingDatabase: - break; - default: - databaseGenerator.CreateLocalDb(); - await databaseGenerator.CheckTestDatabaseAsync(); - databaseGenerator.DeleteDetachedFiles(); - databaseGenerator.DatabaseContext.ReCreate(); - await databaseGenerator.GenerateDatabasesAsync(); - databaseGenerator.ExecuteInsertsForDatabases(); - await databaseGenerator.GenerateTestDataAsync(); - databaseGenerator.DatabaseContext.CopyDetachedFiles(); - databaseGenerator.DatabaseContext.Drop(); - break; - } - } -} diff --git a/src/AutomationCore/Framework.AutomationCore/Enums/TestRunMode.cs b/src/AutomationCore/Framework.AutomationCore/Enums/TestRunMode.cs deleted file mode 100644 index 60ce04af9..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Enums/TestRunMode.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Framework.AutomationCore.Enums; - -public enum TestRunMode -{ - DefaultRunModeOnEmptyDatabase = 0, - - RestoreDatabaseUsingAttach = 1, - - GenerateTestDataOnExistingDatabase = 2, -} diff --git a/src/AutomationCore/Framework.AutomationCore/Environment/TestEnvironment.cs b/src/AutomationCore/Framework.AutomationCore/Environment/TestEnvironment.cs deleted file mode 100644 index 2475bd399..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Environment/TestEnvironment.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Framework.AutomationCore.ServiceProviderPool; - -namespace Framework.AutomationCore.Environment; - -public class TestEnvironment -{ - public readonly AssemblyInitializeAndCleanup AssemblyInitializeAndCleanup; - - public readonly IServiceProviderPool ServiceProviderPool; - - internal TestEnvironment(IServiceProviderPool serviceProviderPool, AssemblyInitializeAndCleanup assemblyInitializeAndCleanup) - { - this.AssemblyInitializeAndCleanup = assemblyInitializeAndCleanup; - this.ServiceProviderPool = serviceProviderPool; - } -} diff --git a/src/AutomationCore/Framework.AutomationCore/Environment/TestEnvironmentBuilder.cs b/src/AutomationCore/Framework.AutomationCore/Environment/TestEnvironmentBuilder.cs deleted file mode 100644 index 21d93ee64..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Environment/TestEnvironmentBuilder.cs +++ /dev/null @@ -1,169 +0,0 @@ -using Anch.DependencyInjection; - -using Framework.AutomationCore.Extensions; -using Framework.AutomationCore.ServiceProviderPool; -using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Utils.DatabaseUtils; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using Microsoft.Extensions.Options; - -namespace Framework.AutomationCore.Environment; - -public class TestEnvironmentBuilder -{ - private IConfiguration? withConfiguration; - - private Func? withServiceProviderBuildFunc; - - private Action withServiceProvAfterBuildAction = _ => { }; - - private Action withAutomationFrameworkSettings = _ => { }; - - private Type? withDatabaseGenerator; - - public TestEnvironmentBuilder WithConfiguration(IConfiguration rootConfiguration) - { - this.withConfiguration = rootConfiguration; - - return this; - } - - public TestEnvironmentBuilder WithDefaultConfiguration( - string environmentVariablesPrefix = "", - string settingsFileName = "appsettings.json") - { - this.withConfiguration = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile(settingsFileName, false) - .AddJsonFile($@"{System.Environment.MachineName}.{settingsFileName}", true) - .AddEnvironmentVariables(environmentVariablesPrefix) - .Build(); - - return this; - } - - public TestEnvironmentBuilder WithAutomationFrameworkSettings(Action settings) - { - this.withAutomationFrameworkSettings = settings; - - return this; - } - - public TestEnvironmentBuilder WithServiceProviderBuildFunc(Func buildFunc) - { - this.withServiceProviderBuildFunc = buildFunc; - - return this; - } - - public TestEnvironmentBuilder WithServiceProviderAfterBuildAction(Action afterBuildAction) - { - this.withServiceProvAfterBuildAction = afterBuildAction; - - return this; - } - - public TestEnvironmentBuilder WithDatabaseGenerator() where T: ITestDatabaseGenerator - { - this.withDatabaseGenerator = typeof(T); - - return this; - } - - public TestEnvironment Build() - { - if (this.withConfiguration == null) - { - this.WithDefaultConfiguration(); - } - - if (this.withDatabaseGenerator == null) - { - throw new ArgumentException("Please provide DatabaseGenerator via '.WithDatabaseGenerator()'"); - } - - if (this.withServiceProviderBuildFunc == null) - { - throw new ArgumentException("Please provide ServiceProvider build function via '.WithServiceProviderBuildFunc()'"); - } - - var serviceProviderPool = this.GetServiceProviderPool( - this.withConfiguration!, - this.withServiceProviderBuildFunc, - this.withServiceProvAfterBuildAction, - this.withDatabaseGenerator, - this.withAutomationFrameworkSettings); - - return new TestEnvironment( - serviceProviderPool, - this.GetAssemblyInitializeAndCleanup(serviceProviderPool)); - } - - protected virtual AssemblyInitializeAndCleanup GetAssemblyInitializeAndCleanup( - IServiceProviderPool serviceProviderPool) => - new( - serviceProviderPool.Get, - serviceProviderPool.Release); - - protected virtual IServiceProvider BuildServiceProvider(IServiceCollection serviceCollection) => - serviceCollection - .AddValidator() - .Validate() - .BuildServiceProvider( - new ServiceProviderOptions { ValidateOnBuild = true, ValidateScopes = true }); - - protected virtual IServiceProviderPool GetServiceProviderPool( - IConfiguration rootConfiguration, - Func serviceProviderBuildFunc, - Action serviceProviderAfterBuildAction, - Type databaseGenerator, - Action settingsAction) => - new ServiceProviderPool.ServiceProviderPool( - () => this.ServiceProviderGenerationFunc( - serviceProviderBuildFunc, - serviceProviderAfterBuildAction, - rootConfiguration, - databaseGenerator, - settingsAction), - rootConfiguration.GetValue("TestsParallelize"), - rootConfiguration.GetValue("DisableServiceProviderPoolLimiter")); - - private IServiceProvider ServiceProviderGenerationFunc( - Func serviceProviderBuildFunc, - Action serviceProviderAfterBuildAction, - IConfiguration rootConfiguration, - Type databaseGeneratorType, - Action settingsAction) - { - var settings = GetSettings(rootConfiguration, settingsAction); - var databaseContext = new DatabaseContext(rootConfiguration, settings); - - var cfg = rootConfiguration.BuildFromRootWithConnectionStrings(databaseContext); - - var environmentServices = new ServiceCollection(); - serviceProviderBuildFunc.Invoke(cfg, environmentServices); - environmentServices.TryAddSingleton(settings); - environmentServices.TryAddSingleton(databaseContext); - environmentServices.AddSingleton(cfg) - .AddSingleton(typeof(ITestDatabaseGenerator), databaseGeneratorType); - - var environmentServiceProvider = this.BuildServiceProvider(environmentServices); - - serviceProviderAfterBuildAction(environmentServiceProvider); - - return environmentServiceProvider; - } - - private static IOptions GetSettings(IConfiguration configuration, Action action) - { - var settings = new AutomationFrameworkSettings(); - configuration.GetSection(nameof(AutomationFrameworkSettings)).Bind(settings); - action(settings); - - return Options.Create(settings); - } -} diff --git a/src/AutomationCore/Framework.AutomationCore/Extensions/ConfigurationExtensions.cs b/src/AutomationCore/Framework.AutomationCore/Extensions/ConfigurationExtensions.cs deleted file mode 100644 index 3fa66d88a..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Extensions/ConfigurationExtensions.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -using Microsoft.Extensions.Configuration; - -namespace Framework.AutomationCore.Extensions; - -public static class ConfigurationExtensions -{ - public static IConfiguration BuildFromRootWithConnectionStrings( - this IConfiguration rootConfiguration, - IDatabaseContext databaseContext) => - new ConfigurationBuilder() - .AddConfiguration(rootConfiguration) - .AddInMemoryCollection( - rootConfiguration.GetSection("ConnectionStrings") - .GetChildren() - .ToDictionary(x => $"ConnectionStrings:{x.Key}", _ => databaseContext.Main.ConnectionString)) - .Build(); -} diff --git a/src/AutomationCore/Framework.AutomationCore/Extensions/Excel/Column.cs b/src/AutomationCore/Framework.AutomationCore/Extensions/Excel/Column.cs deleted file mode 100644 index 551701f63..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Extensions/Excel/Column.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Framework.AutomationCore.Extensions.Excel; - -[AttributeUsage(AttributeTargets.All)] -public class Column : Attribute -{ - public string Name { get; set; } - - public int? Index { get; } - - public Column(string name) => this.Name = name; - - public Column(int index) => this.Index = index; -} diff --git a/src/AutomationCore/Framework.AutomationCore/Extensions/ObjectExtensions.cs b/src/AutomationCore/Framework.AutomationCore/Extensions/ObjectExtensions.cs deleted file mode 100644 index 2b6b6a7aa..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Extensions/ObjectExtensions.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.ComponentModel; -using System.Reflection; - -namespace Framework.AutomationCore.Extensions; - -public static class ObjectExtensions -{ - public static string GetDescription(this Enum obj, string propertyName) - { - var propertyInfo = obj.GetType().GetProperty(propertyName); - var attr = propertyInfo?.GetCustomAttribute(typeof(DescriptionAttribute)); - - return attr != null - ? ((DescriptionAttribute)attr).Description - : propertyName; - } -} diff --git a/src/AutomationCore/Framework.AutomationCore/Extensions/StreamExtensions.cs b/src/AutomationCore/Framework.AutomationCore/Extensions/StreamExtensions.cs deleted file mode 100644 index fd55604d5..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Extensions/StreamExtensions.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Framework.AutomationCore.Extensions; - -public static class StreamExtensions -{ - public static void Save(this Stream stream, string folder, string? fileName = null, string extension = "xlsx") - { - fileName = fileName != null ? $"{fileName}.{extension}" : $"report_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.{extension}"; - var filePath = Path.Combine(folder, fileName); - - using var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write); - stream.CopyTo(fileStream); - stream.Close(); - fileStream.Close(); - } -} diff --git a/src/AutomationCore/Framework.AutomationCore/Framework.AutomationCore.csproj b/src/AutomationCore/Framework.AutomationCore/Framework.AutomationCore.csproj index 8d54dbe86..ca0628a4d 100644 --- a/src/AutomationCore/Framework.AutomationCore/Framework.AutomationCore.csproj +++ b/src/AutomationCore/Framework.AutomationCore/Framework.AutomationCore.csproj @@ -9,24 +9,13 @@ - - - - - - - - - - - - - - + + - + + diff --git a/src/AutomationCore/Framework.AutomationCore/Helpers/DatabaseHelper.cs b/src/AutomationCore/Framework.AutomationCore/Helpers/DatabaseHelper.cs deleted file mode 100644 index 0ca7568ac..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Helpers/DatabaseHelper.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Reflection; - -using Dapper; -using Dapper.Contrib.Extensions; - -using Microsoft.Data.SqlClient; - -namespace Framework.AutomationCore.Helpers; - -public static class DatabaseHelper -{ - public static List GetAll(string connectionString) - where T : class - { - var tableName = GetTableName(typeof(T)); - - using (var connection = new SqlConnection(connectionString)) - { - connection.Open(); - return connection.Query($"SELECT * FROM {tableName}").ToList(); - } - } - - private static string GetTableName(Type type) - { - var tableAttrName = - type.GetCustomAttribute(false)?.Name - ?? (type.GetCustomAttributes(false).FirstOrDefault(attr => attr.GetType().Name == "TableAttribute") as dynamic)?.Name; - - if (tableAttrName != null) - { - return tableAttrName; - } - - throw new Exception($"Table name for '{type.Name}' not found"); - } -} diff --git a/src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/IRootServiceProviderContainer.cs b/src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/IRootServiceProviderContainer.cs new file mode 100644 index 000000000..d23a71ac3 --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/IRootServiceProviderContainer.cs @@ -0,0 +1,16 @@ +using Anch.SecuritySystem; + +using Framework.AutomationCore.ServiceEnvironment; + +using Microsoft.AspNetCore.Mvc; + +namespace Framework.AutomationCore.RootServiceProviderContainer; + +public interface IRootServiceProviderContainer +{ + IServiceProvider RootServiceProvider { get; } + + ControllerEvaluator GetControllerEvaluator(UserCredential? userCredential = null) + where TController : ControllerBase => + this.RootServiceProvider.GetDefaultControllerEvaluator(userCredential); +} diff --git a/src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/RootServiceProviderContainer.cs b/src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/RootServiceProviderContainer.cs new file mode 100644 index 000000000..652eacd57 --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/RootServiceProviderContainer.cs @@ -0,0 +1,16 @@ +using Anch.SecuritySystem; + +using Framework.AutomationCore.ServiceEnvironment; + +using Microsoft.AspNetCore.Mvc; + +namespace Framework.AutomationCore.RootServiceProviderContainer; + +public class RootServiceProviderContainer(IServiceProvider rootServiceProvider) : IRootServiceProviderContainer +{ + public IServiceProvider RootServiceProvider { get; } = rootServiceProvider; + + public virtual ControllerEvaluator GetControllerEvaluator(UserCredential? userCredential = null) + where TController : ControllerBase => + this.RootServiceProvider.GetDefaultControllerEvaluator(userCredential); +} diff --git a/src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/RootServiceProviderContainerExtensions.cs b/src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/RootServiceProviderContainerExtensions.cs new file mode 100644 index 000000000..5682b84db --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/RootServiceProviderContainerExtensions.cs @@ -0,0 +1,45 @@ +using System.Linq.Expressions; + +using Anch.SecuritySystem; + +using Framework.Application.FinancialYear; +using Framework.AutomationCore.ServiceEnvironment; +using Framework.AutomationCore.ServiceEnvironment.Services; +using Framework.AutomationCore.Settings; +//using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; + +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; + +namespace Framework.AutomationCore.RootServiceProviderContainer; + +public static class RootServiceProviderContainerExtensions +{ + extension(IRootServiceProviderContainer rootServiceProviderContainer) + { + //public IDatabaseContext GetDatabaseContext() => rootServiceProviderContainer.RootServiceProvider.GetRequiredService(); + + + + public AutomationFrameworkSettings AutomationFrameworkSettings => rootServiceProviderContainer.RootServiceProvider.GetRequiredService>().Value; + + public TimeProvider TimeProvider => rootServiceProviderContainer.RootServiceProvider.GetRequiredService(); + + public IFinancialYearService FinancialYearService => rootServiceProviderContainer.RootServiceProvider.GetRequiredService(); + + //public IDatabaseContext DatabaseContext => this.GetDatabaseContext(); + + + public void SetCurrentDateTime(DateTime newDateTime) => rootServiceProviderContainer.RootServiceProvider.GetRequiredService().SetCurrentDateTime(newDateTime); + + public TResult EvaluateController(Expression> func) + where TController : ControllerBase => + + rootServiceProviderContainer.GetControllerEvaluator().Evaluate(func); + + public void EvaluateController(Expression> action) + where TController : ControllerBase => + rootServiceProviderContainer.GetControllerEvaluator().Evaluate(action); + } +} diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/ServiceEnvironment/ControllerEvaluator.cs b/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ControllerEvaluator.cs similarity index 98% rename from src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/ServiceEnvironment/ControllerEvaluator.cs rename to src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ControllerEvaluator.cs index 76f61dfc8..b1895ff8e 100644 --- a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/ServiceEnvironment/ControllerEvaluator.cs +++ b/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ControllerEvaluator.cs @@ -25,7 +25,7 @@ public void Evaluate(Expression> actionExpr) => this.InternalEvaluateAsync(actionExpr, async c => { actionExpr.Compile().Invoke(c); - return default; + return null; }).GetAwaiter().GetResult(); public T Evaluate(Expression> funcExpr) @@ -39,7 +39,7 @@ public async Task EvaluateAsync(Expression> actionExpr) await this.InternalEvaluateAsync(actionExpr, async c => { await actionExpr.Compile().Invoke(c); - return default; + return null; }); public async Task EvaluateAsync(Expression>> funcExpr) => await this.InternalEvaluateAsync(funcExpr, funcExpr.Compile()); diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/ServiceEnvironment/ServiceProviderExtensions.cs b/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ServiceProviderExtensions.cs similarity index 100% rename from src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/ServiceEnvironment/ServiceProviderExtensions.cs rename to src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ServiceProviderExtensions.cs diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/ServiceEnvironment/Services/BssTestingEvaluator.cs b/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/Services/BssTestingEvaluator.cs similarity index 100% rename from src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/ServiceEnvironment/Services/BssTestingEvaluator.cs rename to src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/Services/BssTestingEvaluator.cs diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/ServiceEnvironment/Services/IntegrationTestTimeProvider.cs b/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/Services/IntegrationTestTimeProvider.cs similarity index 100% rename from src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/ServiceEnvironment/Services/IntegrationTestTimeProvider.cs rename to src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/Services/IntegrationTestTimeProvider.cs diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/ServiceEnvironment/TestWebApiCurrentMethodResolver.cs b/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/TestWebApiCurrentMethodResolver.cs similarity index 100% rename from src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/ServiceEnvironment/TestWebApiCurrentMethodResolver.cs rename to src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/TestWebApiCurrentMethodResolver.cs diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/ServiceEnvironment/TestWebApiExceptionExpander.cs b/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/TestWebApiExceptionExpander.cs similarity index 100% rename from src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/ServiceEnvironment/TestWebApiExceptionExpander.cs rename to src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/TestWebApiExceptionExpander.cs diff --git a/src/AutomationCore/Framework.AutomationCore/ServiceProviderPool/IServiceProviderPool.cs b/src/AutomationCore/Framework.AutomationCore/ServiceProviderPool/IServiceProviderPool.cs deleted file mode 100644 index bbdb7e2aa..000000000 --- a/src/AutomationCore/Framework.AutomationCore/ServiceProviderPool/IServiceProviderPool.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Framework.AutomationCore.ServiceProviderPool; - -public interface IServiceProviderPool -{ - IServiceProvider Get(); - void Release(IServiceProvider serviceProvider); -} diff --git a/src/AutomationCore/Framework.AutomationCore/ServiceProviderPool/ServiceProviderPool.cs b/src/AutomationCore/Framework.AutomationCore/ServiceProviderPool/ServiceProviderPool.cs deleted file mode 100644 index 36c40979a..000000000 --- a/src/AutomationCore/Framework.AutomationCore/ServiceProviderPool/ServiceProviderPool.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Collections.Concurrent; - -namespace Framework.AutomationCore.ServiceProviderPool; - -public class ServiceProviderPool : IServiceProviderPool -{ - private readonly Func createServiceProviderFunc; - private readonly ConcurrentBag providersCache = []; - private readonly SemaphoreSlim semaphore; - private readonly bool enableLimiter; - - public ServiceProviderPool(Func createServiceProviderFunc, bool parallelExecutionEnabled, bool disableLimiter) - { - this.enableLimiter = !disableLimiter; - if (this.enableLimiter) - { - this.semaphore = parallelExecutionEnabled - ? new SemaphoreSlim(System.Environment.ProcessorCount, System.Environment.ProcessorCount) - : new SemaphoreSlim(1, 1); - } - - this.createServiceProviderFunc = createServiceProviderFunc; - } - - public IServiceProvider Get() - { - if (this.enableLimiter) - { - this.semaphore.Wait(); - } - - try - { - return this.providersCache.TryTake(out var provider) ? provider : this.createServiceProviderFunc.Invoke(); - } - catch (Exception) - { - if (this.enableLimiter) - { - this.semaphore.Release(); - } - - throw; - } - - } - - public void Release(IServiceProvider serviceProvider) - { - this.providersCache.Add(serviceProvider); - if (this.enableLimiter) - { - this.semaphore.Release(); - } - } -} diff --git a/src/AutomationCore/Framework.AutomationCore/Settings/AutomationFrameworkSettings.cs b/src/AutomationCore/Framework.AutomationCore/Settings/AutomationFrameworkSettings.cs index 5804e0638..24bcdf838 100644 --- a/src/AutomationCore/Framework.AutomationCore/Settings/AutomationFrameworkSettings.cs +++ b/src/AutomationCore/Framework.AutomationCore/Settings/AutomationFrameworkSettings.cs @@ -1,4 +1,4 @@ -using Framework.AutomationCore.Enums; +using Anch.Testing.Database; namespace Framework.AutomationCore.Settings; @@ -6,7 +6,7 @@ public class AutomationFrameworkSettings { public string IntegrationTestUserName { get; set; } = "IntegrationTestRootUser"; - public TestRunMode TestRunMode { get; set; } = TestRunMode.DefaultRunModeOnEmptyDatabase; + public DatabaseInitMode DatabaseInitMode { get; set; } = DatabaseInitMode.RebuildSnapshot; public bool UseLocalDb { get; set; } @@ -14,7 +14,7 @@ public class AutomationFrameworkSettings public string DatabaseCollation { get; set; } = ""; - public string TestRunServerRootFolder { get; set; } = default!; + public string TestRunServerRootFolder { get; set; } = null!; public string DbDataDirectory => Path.Combine(this.TestRunServerRootFolder, "data"); diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.Helper.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.Helper.cs deleted file mode 100644 index 816d7220d..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.Helper.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.Text.RegularExpressions; - -using Microsoft.SqlServer.Management.Smo; - -namespace Framework.AutomationCore.Utils.DatabaseUtils; - -public static partial class CoreDatabaseUtil -{ - private static readonly Regex InitialCatalogRegex = new("Initial Catalog=(\\w+);", RegexOptions.Compiled); - - public static string CutInitialCatalog(string inputConnectionString) => - InitialCatalogRegex.Replace(inputConnectionString,""); - - private static string GetInitialCatalog(string connectionString) => - InitialCatalogRegex.Matches(connectionString).First().Value; - - private static Table GetTable(this Server server, string databaseName, string tableName) - { - var database = server.GetDatabase(databaseName); - - return database?.Tables[tableName]; - } - - public static long TableRowCount(this Server server, string databaseName, string tableName) => server.GetTable(databaseName, tableName)?.RowCount ?? 0; - - private static void SetModeRestrictedUser(this Server server, string databaseName) - { - if (server.GetDatabase(databaseName) == null) - { - return; - } - - try - { - server.KillAllProcesses(databaseName); - } - catch (FailedOperationException) - { - ExecuteSql(server.ConnectionContext.SqlConnectionObject,$"ALTER DATABASE [{databaseName}] SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE"); - } - } - - private static void SetModeMultiUser(this Server server, Database database) - => ExecuteSql(server.ConnectionContext.SqlConnectionObject, $"ALTER DATABASE [{database.Name}] SET MULTI_USER"); - - private static Database GetDatabase(this Server server, string name) => server.Databases.Contains(name) ? server.Databases[name] : null; -} diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.cs deleted file mode 100644 index 89e5e78f0..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.cs +++ /dev/null @@ -1,317 +0,0 @@ -using System.Collections.Specialized; -using System.Data; -using System.Text.RegularExpressions; - -using Anch.Core; - -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -using MartinCostello.SqlLocalDb; - -using Microsoft.Data.SqlClient; -using Microsoft.SqlServer.Management.Smo; - -namespace Framework.AutomationCore.Utils.DatabaseUtils; - -public static partial class CoreDatabaseUtil -{ - public static void ExecuteSqlFromFolder(string connectionString, string folder, string? initialCatalog = null) - { - string[] filePaths; - - if (!Directory.Exists(folder)) - { - Console.WriteLine("No directory found for path: {0}", folder); - return; - } - - try - { - filePaths = Directory.GetFiles(folder); - } - catch (Exception) - { - return; - } - - var builder = new SqlConnectionStringBuilder(connectionString); - - if (initialCatalog != null) - { - builder.InitialCatalog = initialCatalog; - } - - ExecuteSqlScripts(filePaths, builder); - } - - private static void ExecuteSqlScripts(string[] sqlPaths, SqlConnectionStringBuilder connectionBuilder) - { - using (var connection = new SqlConnection(connectionBuilder.ConnectionString)) - { - connection.Open(); - - ExecuteSql(connection, "EXEC sp_msforeachtable \"ALTER TABLE ? NOCHECK CONSTRAINT all\""); - - foreach (var filePath in sqlPaths) - { - try - { - ExecuteSql(connection, filePath); - } - catch (Exception ex) - { - Console.WriteLine(filePath); - - Console.WriteLine(ex.Message); - Console.WriteLine(); - Console.WriteLine(ex.StackTrace); - Console.WriteLine(); - Console.WriteLine(); - throw new Exception($"file: {filePath}: ", ex); - } - } - - ExecuteSql(connection, "exec sp_msforeachtable \"ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all\""); - connection.Close(); - } - } - - public static void ExecuteSql(SqlConnection connection, string sqlFileOrText) - { - string sql; - - if (sqlFileOrText.EndsWith(".sql", StringComparison.InvariantCultureIgnoreCase)) - { - using (var stream = File.OpenRead(sqlFileOrText)) - { - var reader = new StreamReader(stream); - sql = reader.ReadToEnd(); - } - } - else - { - sql = sqlFileOrText; - } - - var regex = new Regex("^GO(\r\n|\n|\r)", RegexOptions.Multiline | RegexOptions.IgnoreCase); - string[] lines = regex.Split(sql).Select(z => z.Replace("$Database", connection.Database)).ToArray(); - - using (var cmd = connection.CreateCommand()) - { - cmd.Connection = connection; - - foreach (var line in lines) - { - if (line.Length > 0) - { - cmd.CommandText = line; - cmd.CommandType = CommandType.Text; - cmd.CommandTimeout = 30; - - cmd.ExecuteNonQuery(); - } - } - } - } - - public static void ExecuteSql(string connectionString, string sqlFileOrText, string? initialCatalog = null) - { - var builder = new SqlConnectionStringBuilder(connectionString); - - if (initialCatalog != null) - { - builder.InitialCatalog = initialCatalog; - } - - using (var connection = new SqlConnection(builder.ConnectionString)) - { - connection.Open(); - - ExecuteSql(connection, sqlFileOrText); - connection.Close(); - } - } - - public static void Drop(this IDatabaseContext databaseContext) - { - Drop(databaseContext.Server, databaseContext.Main.DatabaseName); - databaseContext.Secondary?.Foreach(x => Drop(databaseContext.Server, x.Value.DatabaseName)); - } - - private static void Drop(Server server, string databaseName) - { - var database = server.GetDatabase(databaseName); - - if (database == null) - { - return; - } - - server.Drop(database); - } - - - public static void Drop(this Server server, Database database) - { - try - { - server.SetModeRestrictedUser(database.Name); - database.Drop(); - } - catch (FailedOperationException) - { - try - { - server.KillDatabase(database.Name); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - catch (Exception ex) - { - server.SetModeMultiUser(database); - Console.WriteLine(ex.Message); - } - } - - public static void ReCreate(this IDatabaseContext databaseContext) - { - databaseContext.Drop(); - databaseContext.Create(); - } - - public static void Create(this IDatabaseContext databaseContext) - { - Create(databaseContext.Server, databaseContext.Main); - databaseContext.Secondary?.Foreach(x => Create(databaseContext.Server, x.Value)); - } - - private static void Create(Server server, IDatabaseItem database) - { - var db = new Database(server, database.DatabaseName); - if (!string.IsNullOrEmpty(database.DatabaseCollation)) - { - db.Collation = database.DatabaseCollation; - } - - CheckDirectoryAndCreateIfNotExists(database.DbDataDirectory); - - var fileGroup = new FileGroup(db, "PRIMARY"); - - var dataFile = new DataFile( - fileGroup, - database.DatabaseName, - database.SourceDataPath) - { - Size = 5.5 * 1024.0, GrowthType = FileGrowthType.KB, Growth = 1.0 * 1024.0 - }; - - fileGroup.Files.Add(dataFile); - - db.FileGroups.Add(fileGroup); - - var logFile = new LogFile( - db, - database.DatabaseName + "_log", - database.SourceLogPath) - { - Size = 1.0 * 1024.0, GrowthType = FileGrowthType.Percent, Growth = 10.0 - }; - - db.LogFiles.Add(logFile); - - db.Create(); - - server.Refresh(); - } - - public static void CopyDetachedFiles(this IDatabaseContext databaseContext) - { - CopyDetachedFiles(databaseContext.Server, databaseContext.Main); - databaseContext.Secondary?.Foreach(x => CopyDetachedFiles(databaseContext.Server, x.Value)); - } - - private static void CopyDetachedFiles(Server server, DatabaseItem database) - { - server.DetachDatabase(database.DatabaseName); - CheckDirectoryAndCreateIfNotExists(database.DbDataDirectory); - - new FileInfo(database.SourceDataPath).MoveTo(database.CopyDataPath, true); - new FileInfo(database.SourceLogPath).MoveTo(database.CopyLogPath, true); - } - - public static void AttachDatabase(this IDatabaseContext databaseContext) - { - AttachDatabase(databaseContext.Server, databaseContext.Main); - databaseContext.Secondary?.Foreach(x => AttachDatabase(databaseContext.Server, x.Value)); - } - - private static void AttachDatabase(Server server, IDatabaseItem database) - { - new FileInfo(database.CopyDataPath).CopyTo(database.SourceDataPath, true); - new FileInfo(database.CopyLogPath).CopyTo(database.SourceLogPath, true); - - server.AttachDatabase(database.DatabaseName, new StringCollection { database.SourceDataPath, database.SourceLogPath }); - } - - public static void DetachDatabase(this Server server, string databaseName) - { - server.SetModeRestrictedUser(databaseName); - - server.DetachDatabase(databaseName, false); - } - - public static void CreateLocalDb(string instanceName) - { - using (var localDb = new SqlLocalDbApi()) - { - var instanceInfo = localDb.GetInstanceInfo(instanceName); - localDb.AutomaticallyDeleteInstanceFiles = true; - - if (!instanceInfo.Exists) - { - localDb.CreateInstance(instanceInfo.Name); - } - - if (!instanceInfo.IsRunning) - { - localDb.StartInstance(instanceInfo.Name); - } - } - } - - public static void DeleteLocalDb(string instanceName, StopInstanceOptions stopOptions = StopInstanceOptions.KillProcess) - { - using (var localDb = new SqlLocalDbApi()) - { - var instanceInfo = localDb.GetInstanceInfo(instanceName); - - if (instanceInfo.IsRunning) - { - localDb.StopInstance(instanceInfo.Name, stopOptions, TimeSpan.FromSeconds(1)); - } - - localDb.DeleteInstance(instanceName); - } - } - - public static bool LocalDbInstanceExists(string instanceName) - { - using (var localDbApi = new SqlLocalDbApi()) - { - var instanceInfo = localDbApi.GetInstanceInfo(instanceName); - - return instanceInfo.Exists; - } - } - - private static void CheckDirectoryAndCreateIfNotExists(string path) - { - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path!); - } - } -} diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs deleted file mode 100644 index aefdfb771..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System.Text.RegularExpressions; - -using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -using Microsoft.Data.SqlClient; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Options; -using Microsoft.SqlServer.Management.Common; -using Microsoft.SqlServer.Management.Smo; - -namespace Framework.AutomationCore.Utils.DatabaseUtils; - -public class DatabaseContext : IDatabaseContext -{ - static DatabaseContext() => - LocalDbInstanceName = $"Test_{TextRandomizer.RandomString(10)}"; - - private static readonly string LocalDbInstanceName; - - public DatabaseItem Main { get; } - - private readonly Server server; - - public Dictionary Secondary { get; } - - public DatabaseContext( - IConfiguration configuration, - IOptions settings) - : this(configuration, settings.Value) - { - } - - private DatabaseContext( - IConfiguration configuration, - AutomationFrameworkSettings settings) - { - var connectionString = this.GetConnectionString(configuration, settings); - - this.Main = new DatabaseItem( - connectionString, - settings.DatabaseCollation, - settings.DbDataDirectory, - null, - settings.TestsParallelize); - - if (settings.SecondaryDatabases != null) - { - this.Secondary = new Dictionary(); - foreach (var database in settings.SecondaryDatabases) - { - this.Secondary.Add( - database, - new DatabaseItem( - connectionString, - settings.DatabaseCollation, - settings.DbDataDirectory, - database, - settings.TestsParallelize)); - } - } - - this.server = new Server(new ServerConnection(new SqlConnection( - CoreDatabaseUtil.CutInitialCatalog(this.Main.ConnectionString)))); - } - - public Server Server - { - get - { - this.server.Refresh(); - return this.server; - } - } - - private string GetConnectionString( - IConfiguration configuration, - AutomationFrameworkSettings settings) - { - var connectionString = configuration.GetConnectionString(settings.ConnectionStringName); - - if (settings.UseLocalDb) - { - connectionString = this.GetLocalDbConnectionString(connectionString, LocalDbInstanceName); - } - - return connectionString; - } - - private string GetLocalDbConnectionString(string connectionString, string instanceName) - => DataSourceRegex.Replace(connectionString, $"Data Source=(localdb)\\{instanceName}"); - - private static readonly Regex DataSourceRegex = new("Data Source=([^;]*)", RegexOptions.Compiled | RegexOptions.NonBacktracking); -} - - diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseItem.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseItem.cs deleted file mode 100644 index def25cdc1..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseItem.cs +++ /dev/null @@ -1,74 +0,0 @@ -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -using Microsoft.Data.SqlClient; - -namespace Framework.AutomationCore.Utils.DatabaseUtils; - -public class DatabaseItem : IDatabaseItem -{ - private readonly SqlConnectionStringBuilder builder; - - public DatabaseItem( - string connectionString, - string databaseCollation, - string dbDataDirectory, - string? initialCatalog = null, - bool randomizeDatabaseName = false) - { - this.DbDataDirectory = dbDataDirectory; - this.builder = new SqlConnectionStringBuilder(connectionString); - initialCatalog ??= this.builder.InitialCatalog; - this.DatabaseName = randomizeDatabaseName - ? $"{initialCatalog}{TextRandomizer.RandomString(5)}" - : initialCatalog; - - var fileName = $"{this.InstanceName}_{this.DatabaseName}_{TextRandomizer.RandomString(5)}"; - - this.CopyDataPath = this.ToCopyDataPath(initialCatalog); - this.CopyLogPath = this.ToCopyLogPath(initialCatalog); - this.SourceDataPath = this.ToSourceDataPath(fileName); - this.SourceLogPath = this.ToSourceLogPath(fileName); - this.DatabaseCollation = databaseCollation; - this.builder.InitialCatalog = this.DatabaseName; - } - - public string DataSource => this.builder.DataSource; - - public string InitialCatalog => this.builder.InitialCatalog; - - public string UserId => this.builder.UserID; - - public string Password => this.builder.Password; - - public bool IntegratedSecurity => this.builder.IntegratedSecurity; - - public string ConnectionString => this.builder.ConnectionString; - - public string InstanceName => this.builder.DataSource.Split('\\').LastOrDefault(); - - public string DatabaseName { get; } - public string DbDataDirectory { get; } - public string CopyDataPath { get; } - public string CopyLogPath { get; } - public string SourceDataPath { get; } - public string SourceLogPath { get; } - public string DatabaseCollation { get; } - - private string ToSourceDataPath(string fileName) => this.ToWorkPath(SourceDataFile(fileName)); - - private string ToSourceLogPath(string fileName) => this.ToWorkPath(SourceLogFile(fileName)); - - private string ToCopyDataPath(string initialCatalog) => this.ToWorkPath(this.CopyDataFile(initialCatalog)); - - private string ToCopyLogPath(string initialCatalog) => this.ToWorkPath(this.CopyLogFile(initialCatalog)); - - private string CopyDataFile(string initialCatalog) =>$"{System.Environment.UserName}_{initialCatalog}.mdf"; - - private string CopyLogFile(string initialCatalog) => $"{System.Environment.UserName}_{initialCatalog}_log.ldf"; - - private static string SourceDataFile(string fileName) => $"{fileName}.mdf"; - - private static string SourceLogFile(string fileName) => $"{fileName}_log.ldf"; - - private string ToWorkPath(string fileName) => Path.Combine(this.DbDataDirectory, fileName); -} diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseContext.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseContext.cs deleted file mode 100644 index 6e2f61640..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseContext.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.SqlServer.Management.Smo; - -namespace Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -public interface IDatabaseContext -{ - public DatabaseItem Main { get; } - - public Dictionary Secondary { get; } - - public Server Server { get; } -} diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseItem.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseItem.cs deleted file mode 100644 index cae555a76..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseItem.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -public interface IDatabaseItem -{ - public string DatabaseName { get; } - public string DbDataDirectory { get; } - public string CopyDataPath { get; } - public string CopyLogPath { get; } - public string SourceDataPath { get; } - public string SourceLogPath { get; } - public string DatabaseCollation { get; } -} diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/ITestDatabaseGenerator.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/ITestDatabaseGenerator.cs deleted file mode 100644 index e9faf1c6e..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/ITestDatabaseGenerator.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -public interface ITestDatabaseGenerator -{ - IEnumerable TestServers { get; } - - IDatabaseContext DatabaseContext { get; } - - void CreateLocalDb(); - - void DeleteLocalDb(); - - void DropAllDatabases(); - - void ExecuteInsertsForDatabases(); - - Task GenerateDatabasesAsync(); - - void DeleteDetachedFiles(); - - Task CheckAndCreateDetachedFilesAsync(); - - Task CheckTestDatabaseAsync(); - - void CheckServerAllowed(); - - Task GenerateTestDataAsync(); -} diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/TestDatabaseGenerator.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/TestDatabaseGenerator.cs deleted file mode 100644 index f17c511b3..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/TestDatabaseGenerator.cs +++ /dev/null @@ -1,93 +0,0 @@ -using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -using Microsoft.Extensions.Options; -using Microsoft.SqlServer.Management.Smo; - -namespace Framework.AutomationCore.Utils.DatabaseUtils; - -public abstract class TestDatabaseGenerator( - IDatabaseContext databaseContext, - IOptions settings) : ITestDatabaseGenerator -{ - public virtual IEnumerable TestServers => []; - - public IDatabaseContext DatabaseContext { get; } = databaseContext; - - private readonly AutomationFrameworkSettings settings = settings.Value; - - public void CreateLocalDb() - { - if (this.settings.UseLocalDb && !CoreDatabaseUtil.LocalDbInstanceExists(this.DatabaseContext.Main.InstanceName)) - { - CoreDatabaseUtil.CreateLocalDb(this.DatabaseContext.Main.InstanceName); - } - } - - public virtual void DeleteLocalDb() - { - if (this.settings.UseLocalDb) - { - CoreDatabaseUtil.DeleteLocalDb(this.DatabaseContext.Main.InstanceName); - } - } - - public virtual void DropAllDatabases() => - this.DatabaseContext.Server.Databases.Cast() - .Where(x => x.Name.Equals(this.DatabaseContext.Main.InitialCatalog)) - .ToList() - .ForEach(x => x.Drop()); - - public virtual void ExecuteInsertsForDatabases() => - CoreDatabaseUtil.ExecuteSqlFromFolder( - this.DatabaseContext.Main.ConnectionString, - @"__Support\Scripts", - this.DatabaseContext.Main.DatabaseName); - - public void DeleteDetachedFiles() - { - if (!Directory.Exists(this.settings.DbDataDirectory)) - { - return; - } - - Directory.GetFiles(this.settings.DbDataDirectory) - .Where(i => i.Contains(this.DatabaseContext.Main.InstanceName)) - .ToList() - .ForEach(File.Delete); - } - - public virtual void CheckServerAllowed() - { - if (this.DatabaseContext.Server.NetName.Equals(System.Environment.MachineName, StringComparison.InvariantCultureIgnoreCase)) - { - return; - } - - if (!this.TestServers.Select(s => s.ToUpper()) - .ToList() - .Contains(this.DatabaseContext.Server.NetName.ToUpper())) - { - throw new Exception( - $"Server name {this.DatabaseContext.Server.NetName} is not specified in allowed list of test servers: {string.Join(", ", this.TestServers.Select(s => s.ToUpper()).ToList())}"); - } - } - - public async Task CheckAndCreateDetachedFilesAsync() - { - if (!new FileInfo(this.DatabaseContext.Main.CopyDataPath).Exists) - { - this.DatabaseContext.ReCreate(); - await this.GenerateDatabasesAsync(); - this.ExecuteInsertsForDatabases(); - await this.GenerateTestDataAsync(); - this.DatabaseContext.CopyDetachedFiles(); - } - } - - public abstract Task GenerateDatabasesAsync(); - - public abstract Task GenerateTestDataAsync(); - - public virtual Task CheckTestDatabaseAsync() => Task.CompletedTask; -} diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/TextRandomizer.cs b/src/AutomationCore/Framework.AutomationCore/Utils/TextRandomizer.cs deleted file mode 100644 index 35d35b5ac..000000000 --- a/src/AutomationCore/Framework.AutomationCore/Utils/TextRandomizer.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Text; - -namespace Framework.AutomationCore.Utils; - -public static class TextRandomizer -{ - public static string UniqueString(string startsWith = "") => $"{startsWith}{Random.Shared.Next(1000000, 9999999)}"; - - public static string RandomString(string startsWith, int size) => $"{startsWith}{RandomString(size - startsWith.Length)}"; - - public static string RandomString(int size) - { - var builder = new StringBuilder(); - - for (var i = 0; i < size; i++) - { - var ch = Convert.ToChar(Convert.ToInt32(Math.Floor((26 * Random.Shared.NextDouble()) + 65))); - builder.Append(ch); - } - - return builder.ToString(); - } -} diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/WebApi/IntegrationWebApiBase.cs b/src/AutomationCore/Framework.AutomationCore/WebApi/IntegrationWebApiBase.cs similarity index 81% rename from src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/WebApi/IntegrationWebApiBase.cs rename to src/AutomationCore/Framework.AutomationCore/WebApi/IntegrationWebApiBase.cs index f9b8bf7d7..8b0eee642 100644 --- a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/WebApi/IntegrationWebApiBase.cs +++ b/src/AutomationCore/Framework.AutomationCore/WebApi/IntegrationWebApiBase.cs @@ -9,5 +9,5 @@ public abstract class IntegrationWebApiBase(IServiceProvider rootServiceProvider protected abstract string IntegrationUserName { get; } public override ControllerEvaluator GetControllerEvaluator(UserCredential? userCredential = null) => - base.GetControllerEvaluator(userCredential ?? this.IntegrationUserName); + base.GetControllerEvaluator(userCredential ?? this.IntegrationUserName); } diff --git a/src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/WebApi/WebApiBase.cs b/src/AutomationCore/Framework.AutomationCore/WebApi/WebApiBase.cs similarity index 100% rename from src/AutomationCore/Framework.AutomationCore.ServiceEnvironment/WebApi/WebApiBase.cs rename to src/AutomationCore/Framework.AutomationCore/WebApi/WebApiBase.cs diff --git a/src/BLL/Framework.BLL.Domain/Extensions/EnumerableExtensions.cs b/src/BLL/Framework.BLL.Domain/Extensions/EnumerableExtensions.cs index 5cc9ed7e8..1685921a1 100644 --- a/src/BLL/Framework.BLL.Domain/Extensions/EnumerableExtensions.cs +++ b/src/BLL/Framework.BLL.Domain/Extensions/EnumerableExtensions.cs @@ -37,7 +37,7 @@ private static Func TryGetNotFoundByNameExceptionFactory(str { if (name == null) throw new ArgumentNullException(nameof(name)); - return raiseIfNotFound ? () => GetNotFoundException(name, nameof(name)) : default(Func); + return raiseIfNotFound ? () => GetNotFoundException(name, nameof(name)) : null; } private static Exception GetNotFoundException(string identity, string identityName) => throw new Exception($"{typeof (TSource).Name} with {identityName} \"{identity}\" not found"); diff --git a/src/BssFramework.slnx b/src/BssFramework.slnx index 16eb0b238..aaad9c732 100644 --- a/src/BssFramework.slnx +++ b/src/BssFramework.slnx @@ -8,8 +8,7 @@ - - + @@ -184,7 +183,6 @@ - @@ -193,6 +191,7 @@ + diff --git a/src/CodeGeneration/Framework.CodeGeneration.DTOGenerator/FileFactory/BaseCodeDomHelper.cs b/src/CodeGeneration/Framework.CodeGeneration.DTOGenerator/FileFactory/BaseCodeDomHelper.cs index ee0aaac6d..0d66eae50 100644 --- a/src/CodeGeneration/Framework.CodeGeneration.DTOGenerator/FileFactory/BaseCodeDomHelper.cs +++ b/src/CodeGeneration/Framework.CodeGeneration.DTOGenerator/FileFactory/BaseCodeDomHelper.cs @@ -56,7 +56,7 @@ public static CodeMemberMethod GenerateIdConstructor(this IFileF public static IEnumerable GenerateStrictConstructors(this IDTOSource source) where TConfiguration : class, IDTOGeneratorConfiguration => source.GetActualStrictConstructorFileTypes() - .Concat([default(MainDTOFileType)]) + .Concat([null]) .Windowed2((fileType, baseFileType) => new[] { false, true}.Select(withoutMappingParameter => source.GenerateStrictConstructor(fileType, baseFileType, withoutMappingParameter))) .SelectMany(); diff --git a/src/Database/Framework.Database.NHibernate.DBGenerator.Tests/Framework.Database.NHibernate.DBGenerator.Tests.csproj b/src/Database/Framework.Database.NHibernate.DBGenerator.Tests/Framework.Database.NHibernate.DBGenerator.Tests.csproj index aed4ece68..bd384e3d7 100644 --- a/src/Database/Framework.Database.NHibernate.DBGenerator.Tests/Framework.Database.NHibernate.DBGenerator.Tests.csproj +++ b/src/Database/Framework.Database.NHibernate.DBGenerator.Tests/Framework.Database.NHibernate.DBGenerator.Tests.csproj @@ -7,7 +7,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Database/Framework.Database.NHibernate.DBGenerator/AuditDBGenerator/AuditDatabaseScriptGenerator.cs b/src/Database/Framework.Database.NHibernate.DBGenerator/AuditDBGenerator/AuditDatabaseScriptGenerator.cs index 9a3ba23a2..3b37a43a5 100644 --- a/src/Database/Framework.Database.NHibernate.DBGenerator/AuditDBGenerator/AuditDatabaseScriptGenerator.cs +++ b/src/Database/Framework.Database.NHibernate.DBGenerator/AuditDBGenerator/AuditDatabaseScriptGenerator.cs @@ -279,7 +279,7 @@ private static IEnumerable CreateForegnKey(AuditTableGenerateContext con .FirstOrDefault(z => string.Equals($"{database.Name}.{z.Schema}.{z.Name}", fqn, StringComparison.InvariantCultureIgnoreCase) || string.Equals($"{z.Schema}.{z.Name}", fqn, StringComparison.InvariantCultureIgnoreCase)); - bool create = true; + var create = true; if (table != null) { @@ -332,7 +332,7 @@ private IEnumerable GetIterateScripts(DatabaseMetadata databaseMetadata, { foreach (var generator in this.IterateGenerators(cfg, dialect)) { - string key = generator.GeneratorKey(); + var key = generator.GeneratorKey(); if (!databaseMetadata.IsSequence(key) && !databaseMetadata.IsTable(key)) { return generator.SqlCreateStrings(dialect); @@ -356,8 +356,8 @@ private IEnumerable IterateGenerators(Configurat { var generators = new Dictionary(); var properties = configuration.Properties; - string defaultCatalog = PropertiesHelper.GetString(Environment.DefaultCatalog, properties, null); - string defaultSchema = PropertiesHelper.GetString(Environment.DefaultSchema, properties, null); + var defaultCatalog = PropertiesHelper.GetString(Environment.DefaultCatalog, properties, null); + var defaultSchema = PropertiesHelper.GetString(Environment.DefaultSchema, properties, null); foreach (var pc in configuration.ClassMappings) { diff --git a/src/Database/Framework.Database.NHibernate.DBGenerator/AuditDBGenerator/AuditSqlScriptGenerator.cs b/src/Database/Framework.Database.NHibernate.DBGenerator/AuditDBGenerator/AuditSqlScriptGenerator.cs index a1158e8fb..3886c1159 100644 --- a/src/Database/Framework.Database.NHibernate.DBGenerator/AuditDBGenerator/AuditSqlScriptGenerator.cs +++ b/src/Database/Framework.Database.NHibernate.DBGenerator/AuditDBGenerator/AuditSqlScriptGenerator.cs @@ -29,7 +29,7 @@ public string[] GenerateCreateScripts(AuditTableGenerateContext context) .Append(' ') .Append(context.GetQualifiedTableName()).Append(" ("); - bool identityColumn = table.IdentifierValue != null && table.IdentifierValue.IsIdentityColumn(dialect); + var identityColumn = table.IdentifierValue != null && table.IdentifierValue.IsIdentityColumn(dialect); // try to find out the name of the pk to create it as identity if the // identitygenerator is used @@ -114,14 +114,14 @@ public string[] GenerateCreateScripts(AuditTableGenerateContext context) buf.Append(StringHelper.CommaSpace).Append(table.PrimaryKey.SqlConstraintString(dialect, defaultSchema)); } - foreach (UniqueKey uk in table.UniqueKeyIterator) + foreach (var uk in table.UniqueKeyIterator) { buf.Append(',').Append(uk.SqlConstraintString(dialect)); } if (dialect.SupportsTableCheck) { - foreach (string checkConstraint in table.CheckConstraintsIterator) + foreach (var checkConstraint in table.CheckConstraintsIterator) { buf.Append(", check (").Append(checkConstraint).Append(") "); } diff --git a/src/Database/Framework.Database.NHibernate.DBGenerator/AuditDBGenerator/AuditTableGenerateContext.cs b/src/Database/Framework.Database.NHibernate.DBGenerator/AuditDBGenerator/AuditTableGenerateContext.cs index 68685cff1..3e1dcb778 100644 --- a/src/Database/Framework.Database.NHibernate.DBGenerator/AuditDBGenerator/AuditTableGenerateContext.cs +++ b/src/Database/Framework.Database.NHibernate.DBGenerator/AuditDBGenerator/AuditTableGenerateContext.cs @@ -45,9 +45,9 @@ public string GetQualifiedTableName() { return "( " + this.Table.Subselect + " )"; } - string quotedName = this.GetQuotedName(this.Table.Name); - string usedSchema = this.Table.Schema == null ? this.DefaultSchema : this.GetQuotedName(this.Table.Schema); - string usedCatalog = this.Table.Catalog ?? this.DefaultCatalog; + var quotedName = this.GetQuotedName(this.Table.Name); + var usedSchema = this.Table.Schema == null ? this.DefaultSchema : this.GetQuotedName(this.Table.Schema); + var usedCatalog = this.Table.Catalog ?? this.DefaultCatalog; return this.Dialect.Qualify(usedCatalog, usedSchema, quotedName); } diff --git a/src/Database/Framework.Database.NHibernate.DBGenerator/ScriptGeneratorBuilder/Impl/MigrationDBScriptGeneratorBuilder.cs b/src/Database/Framework.Database.NHibernate.DBGenerator/ScriptGeneratorBuilder/Impl/MigrationDBScriptGeneratorBuilder.cs index 9ebc7454b..63ef247b2 100644 --- a/src/Database/Framework.Database.NHibernate.DBGenerator/ScriptGeneratorBuilder/Impl/MigrationDBScriptGeneratorBuilder.cs +++ b/src/Database/Framework.Database.NHibernate.DBGenerator/ScriptGeneratorBuilder/Impl/MigrationDBScriptGeneratorBuilder.cs @@ -134,19 +134,16 @@ private void Execute(string commandText, IDatabaseScriptGeneratorContext context { try { - using (var connection = context.SqlDatabaseFactory.Server.ConnectionContext.SqlConnectionObject) - { - connection.Open(); - ////var nextCommandText = commandText.Replace("GO", string.Empty); - var replaceTargetDBText = commandText.Replace("$Database", context.DatabaseName.Name); - - context.SqlDatabaseFactory.Server.ConnectionContext.ExecuteNonQuery(replaceTargetDBText); + using var connection = context.SqlDatabaseFactory.Server.ConnectionContext.SqlConnectionObject; + connection.Open(); + ////var nextCommandText = commandText.Replace("GO", string.Empty); + var replaceTargetDBText = commandText.Replace("$Database", context.DatabaseName.Name); - ////var command = new SqlCommand(replaceTargetDBText, connection); - ////command.CommandType = CommandType.Text; - ////command.ExecuteNonQuery(); - } + context.SqlDatabaseFactory.Server.ConnectionContext.ExecuteNonQuery(replaceTargetDBText); + ////var command = new SqlCommand(replaceTargetDBText, connection); + ////command.CommandType = CommandType.Text; + ////command.ExecuteNonQuery(); } catch (Exception e) { @@ -157,20 +154,18 @@ private void Execute(string commandText, IDatabaseScriptGeneratorContext context private List GetExecutedMigrationScripts(IDatabaseScriptGeneratorContext context) { var result = new List(); - using (var connection = context.SqlDatabaseFactory.Server.ConnectionContext.SqlConnectionObject) + using var connection = context.SqlDatabaseFactory.Server.ConnectionContext.SqlConnectionObject; + connection.Open(); + var cmd = $"select name, scheme, version from {context.DatabaseName}.[{this.tableName}]"; + var command = new Microsoft.Data.SqlClient.SqlCommand(cmd, connection); + var sqlResult = command.ExecuteReader(); + + while (sqlResult.Read()) { - connection.Open(); - var cmd = $"select name, scheme, version from {context.DatabaseName}.[{this.tableName}]"; - var command = new Microsoft.Data.SqlClient.SqlCommand(cmd, connection); - var sqlResult = command.ExecuteReader(); - - while (sqlResult.Read()) - { - result.Add(new MigrationDbScriptHeader( - sqlResult.GetString(0), - sqlResult.GetString(1), - sqlResult.GetString(2))); - } + result.Add(new MigrationDbScriptHeader( + sqlResult.GetString(0), + sqlResult.GetString(1), + sqlResult.GetString(2))); } return result; diff --git a/src/Database/Framework.Database.NHibernate.Runtime/Audit/AuditInterceptor.cs b/src/Database/Framework.Database.NHibernate.Runtime/Audit/AuditInterceptor.cs index 995cc8f94..0c2901861 100644 --- a/src/Database/Framework.Database.NHibernate.Runtime/Audit/AuditInterceptor.cs +++ b/src/Database/Framework.Database.NHibernate.Runtime/Audit/AuditInterceptor.cs @@ -15,7 +15,7 @@ internal sealed class AuditInterceptor(IEnumerable createAuditPr public override bool OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, IType[] types) { - bool result = false; + var result = false; if (entity is IAuditObject) { result = @@ -29,12 +29,12 @@ public override bool OnFlushDirty(object entity, object id, object[] currentStat public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types) { - bool result = false; + var result = false; if (entity is IAuditObject) { var domainObjectDescription = AuditPropertiesSetter.DomainObjectDescription.Get(entity.GetType(), propertyNames); - bool createSetterRes = this.createSetter.SetAuditFields(domainObjectDescription, ref state); - bool modifySetterRes = this.modifySetter.SetAuditFields(domainObjectDescription, ref state); + var createSetterRes = this.createSetter.SetAuditFields(domainObjectDescription, ref state); + var modifySetterRes = this.modifySetter.SetAuditFields(domainObjectDescription, ref state); result = createSetterRes | modifySetterRes; } diff --git a/src/Database/Framework.Database.NHibernate.Runtime/Audit/AuditPropertiesSetter.cs b/src/Database/Framework.Database.NHibernate.Runtime/Audit/AuditPropertiesSetter.cs index ea2979505..b80635bef 100644 --- a/src/Database/Framework.Database.NHibernate.Runtime/Audit/AuditPropertiesSetter.cs +++ b/src/Database/Framework.Database.NHibernate.Runtime/Audit/AuditPropertiesSetter.cs @@ -62,7 +62,7 @@ private static Func GetSetAuditAction getAuditValue = null; - string domainObjectPropertyName = auditProperty.PropertyExpr.GetMemberName(); + var domainObjectPropertyName = auditProperty.PropertyExpr.GetMemberName(); if (!string.IsNullOrEmpty(domainObjectPropertyName)) { var property = typeof(TDomainObject).GetProperty(domainObjectPropertyName, true); @@ -72,7 +72,7 @@ private static Func GetSetAuditAction { - bool result = false; + var result = false; if (propertyIndex.HasValue) { var auditValue = (getAuditValue != null) ? getAuditValue.Invoke() : default(TProperty); @@ -92,7 +92,7 @@ private static Func GetSetAuditAction GetMapping(PrimitiveTypeFieldMetadata fi var isNullable = !(field.IsVersion && new[] { typeof(int), typeof(long) }.Contains(field.Type) || isPrimaryKey); - string defaultConstraint = field.IsVersion && new[] { typeof(int), typeof(long) }.Contains(field.Type) ? "0" : null; + var defaultConstraint = field.IsVersion && new[] { typeof(int), typeof(long) }.Contains(field.Type) ? "0" : null; yield return new SqlFieldMappingInfo( field.Type.ToDataType(field.Attributes), diff --git a/src/Database/Framework.Tracking.Tests/Framework.Tracking.Tests.csproj b/src/Database/Framework.Tracking.Tests/Framework.Tracking.Tests.csproj index 5590b0e2f..4d40750b7 100644 --- a/src/Database/Framework.Tracking.Tests/Framework.Tracking.Tests.csproj +++ b/src/Database/Framework.Tracking.Tests/Framework.Tracking.Tests.csproj @@ -7,7 +7,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 5baac85f3..1907b7573 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -36,7 +36,7 @@ false true - 1591, CS9107 + 1591, CS9107, CS9124, xUnit1041 true false diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index d59de37e5..17be547d1 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -2,10 +2,12 @@ true false - 3.4.0.1 + 3.4.1.0 [1.6.2] + + @@ -29,14 +31,13 @@ - + - @@ -70,7 +71,7 @@ - + diff --git a/src/Framework.Core/CoreEnumerableExtensions.cs b/src/Framework.Core/CoreEnumerableExtensions.cs index cd1a34fe4..9ac8bb971 100644 --- a/src/Framework.Core/CoreEnumerableExtensions.cs +++ b/src/Framework.Core/CoreEnumerableExtensions.cs @@ -58,21 +58,17 @@ public static void Merge( public static bool SequenceEqual(this IEnumerable first, IEnumerable second, Func compareFunc) { - using (var enumerator1 = first.GetEnumerator()) + using var enumerator1 = first.GetEnumerator(); + using var enumerator2 = second.GetEnumerator(); + while (enumerator1.MoveNext()) { - using (var enumerator2 = second.GetEnumerator()) - { - while (enumerator1.MoveNext()) - { - if (!enumerator2.MoveNext() || !compareFunc(enumerator1.Current, enumerator2.Current)) - return false; - } - - if (enumerator2.MoveNext()) - return false; - } + if (!enumerator2.MoveNext() || !compareFunc(enumerator1.Current, enumerator2.Current)) + return false; } + if (enumerator2.MoveNext()) + return false; + return true; } @@ -97,24 +93,20 @@ public static IEnumerable IfEmpty(this IEnumerable source, Func(this IEnumerable source, Func func) if (source == null) throw new ArgumentNullException(nameof(source)); if (func == null) throw new ArgumentNullException(nameof(func)); - using (var enumerator = source.GetEnumerator()) - { - return enumerator.MoveNext() ? enumerator.Current : func(); - } + using var enumerator = source.GetEnumerator(); + return enumerator.MoveNext() ? enumerator.Current : func(); } public static void Override(this ICollection source, IEnumerable newItems) @@ -169,15 +159,13 @@ public static TSource First(this IEnumerable source, Func> Split(this IEnumerable< if (source == null) throw new ArgumentNullException(nameof(source)); if (size < 1) throw new ArgumentException("count"); - using (var enumerator = source.GetEnumerator()) + using var enumerator = source.GetEnumerator(); + while (enumerator.MoveNext()) { - while (enumerator.MoveNext()) - { - yield return enumerator.InnerSplit(size).ToList(); - } + yield return enumerator.InnerSplit(size).ToList(); } } @@ -406,31 +392,29 @@ public static IEnumerable Skip(this IEnumerable source, T expectedEleme if (source == null) throw new ArgumentNullException(nameof(source)); if (equalityComparer == null) throw new ArgumentNullException(nameof(equalityComparer)); - using (var enumerator = source.GetEnumerator()) + using var enumerator = source.GetEnumerator(); + if (enumerator.MoveNext()) { - if (enumerator.MoveNext()) + if (!equalityComparer.Equals(enumerator.Current, expectedElement)) { - if (!equalityComparer.Equals(enumerator.Current, expectedElement)) + if (raiseIfNotEquals) { - if (raiseIfNotEquals) - { - throw new ArgumentException("Unexpected first element", nameof(source)); - } - - yield return enumerator.Current; + throw new ArgumentException("Unexpected first element", nameof(source)); } - while (enumerator.MoveNext()) - { - yield return enumerator.Current; - } + yield return enumerator.Current; } - else + + while (enumerator.MoveNext()) { - if (raiseIfNotEquals) - { - throw new ArgumentException("EmptyCollection", nameof(source)); - } + yield return enumerator.Current; + } + } + else + { + if (raiseIfNotEquals) + { + throw new ArgumentException("EmptyCollection", nameof(source)); } } } diff --git a/src/Framework.Core/CoreStringExtensions.cs b/src/Framework.Core/CoreStringExtensions.cs index 1e92c8fb2..56010e2ea 100644 --- a/src/Framework.Core/CoreStringExtensions.cs +++ b/src/Framework.Core/CoreStringExtensions.cs @@ -156,7 +156,7 @@ public static IEnumerable GetChartWhile(this string source, char stopChar) [Obsolete("v10 This method will be protected in future")] public static IEnumerable GetCharsAfter(this string source, char afterChar) { - bool isReturn = false; + var isReturn = false; foreach (var s in source) { if (isReturn) diff --git a/src/Framework.Core/CoreTypeExtensions.cs b/src/Framework.Core/CoreTypeExtensions.cs index 8b4ba7ee2..3b6169ea6 100644 --- a/src/Framework.Core/CoreTypeExtensions.cs +++ b/src/Framework.Core/CoreTypeExtensions.cs @@ -235,7 +235,7 @@ public static Func WithLock(this Func func, object? b if (type == null) throw new ArgumentNullException(nameof(type)); if (memberName == null) throw new ArgumentNullException(nameof(memberName)); - return type.GetMemberType(memberName, raiseIfNotFound ? () => new Exception($"Member \"{memberName}\" not found in type \"{type.Name}\"") : default(Func)); + return type.GetMemberType(memberName, raiseIfNotFound ? () => new Exception($"Member \"{memberName}\" not found in type \"{type.Name}\"") : null); } public static Type? GetMemberType(this Type type, string memberName, Func? raiseIfNotFoundException) @@ -277,7 +277,7 @@ public static Func WithLock(this Func func, object? b if (propertyName == null) throw new ArgumentNullException(nameof(propertyName)); return type.GetProperty(propertyName, stringComparison, raiseIfNotFound ? () => new Exception( - $"Property \"{propertyName}\" not found in type \"{type.Name}\"") : default(Func)); + $"Property \"{propertyName}\" not found in type \"{type.Name}\"") : null); } public static PropertyInfo? GetProperty(this Type type, string propertyName, StringComparison stringComparison, Func? raiseIfNotFoundException) @@ -309,7 +309,7 @@ where typeof(T).IsAssignableFrom(prop.PropertyType) if (type == null) throw new ArgumentNullException(nameof(type)); if (propertyName == null) throw new ArgumentNullException(nameof(propertyName)); - return type.GetProperty(propertyName, raiseIfNotFound ? () => new Exception($"Property \"{propertyName}\" not found in type \"{type.Name}\"") : default(Func)); + return type.GetProperty(propertyName, raiseIfNotFound ? () => new Exception($"Property \"{propertyName}\" not found in type \"{type.Name}\"") : null); } public static PropertyInfo? GetProperty(this Type type, string propertyName, Func? raiseIfNotFoundException) @@ -343,7 +343,7 @@ where typeof(T).IsAssignableFrom(prop.PropertyType) if (type == null) throw new ArgumentNullException(nameof(type)); if (methodName == null) throw new ArgumentNullException(nameof(methodName)); - return type.GetMethod(methodName, bindingFlags, raiseIfNotFound ? () => new Exception($"Method \"{methodName}\" not found") : default(Func)); + return type.GetMethod(methodName, bindingFlags, raiseIfNotFound ? () => new Exception($"Method \"{methodName}\" not found") : null); } public static MethodInfo? GetMethod(this Type type, string methodName, BindingFlags bindingFlags, Func? raiseIfNotFoundException) @@ -475,22 +475,20 @@ public static IEnumerable Windowed2(this IEnumerable< if (source == null) throw new ArgumentNullException(nameof(source)); if (selector == null) throw new ArgumentNullException(nameof(selector)); - using (var enumerator = source.GetEnumerator()) + using var enumerator = source.GetEnumerator(); + if (enumerator.MoveNext()) { + var prev = enumerator.Current; + if (enumerator.MoveNext()) { - var prev = enumerator.Current; - - if (enumerator.MoveNext()) - { - var next = enumerator.Current; + var next = enumerator.Current; - yield return selector(prev, next); + yield return selector(prev, next); - while (enumerator.MoveNext()) - { - yield return selector(next, next = enumerator.Current); - } + while (enumerator.MoveNext()) + { + yield return selector(next, next = enumerator.Current); } } } @@ -509,7 +507,7 @@ public static IEnumerable Windowed2(this IEnumerable< if (type == null) throw new ArgumentNullException(nameof(type)); if (methodName == null) throw new ArgumentNullException(nameof(methodName)); - return type.GetMethod(methodName, raiseIfNotFound ? () => new Exception($"Method \"{methodName}\" not found") : default(Func)); + return type.GetMethod(methodName, raiseIfNotFound ? () => new Exception($"Method \"{methodName}\" not found") : null); } public static MethodInfo? GetMethod(this Type type, string methodName, Func? raiseIfNotFoundException) diff --git a/src/Framework.Core/ExceptionEvaluator.cs b/src/Framework.Core/ExceptionEvaluator.cs index 8182dedea..b0cb13579 100644 --- a/src/Framework.Core/ExceptionEvaluator.cs +++ b/src/Framework.Core/ExceptionEvaluator.cs @@ -9,10 +9,8 @@ public static TResult Evaluate(this IEnumerable sourc if (selector == null) throw new ArgumentNullException(nameof(selector)); if (getAggregateException == null) throw new ArgumentNullException(nameof(getAggregateException)); - using (var enumerator = source.GetEnumerator()) - { - return enumerator.Evaluate(selector, [], getAggregateException); - } + using var enumerator = source.GetEnumerator(); + return enumerator.Evaluate(selector, [], getAggregateException); } private static TResult Evaluate(this IEnumerator source, Func selector, IEnumerable exceptions, Func, Exception> getAggregateException) diff --git a/src/Framework.Core/Helpers/DataContractSerializerHelper.cs b/src/Framework.Core/Helpers/DataContractSerializerHelper.cs index 68b2808b6..04d5a8b83 100644 --- a/src/Framework.Core/Helpers/DataContractSerializerHelper.cs +++ b/src/Framework.Core/Helpers/DataContractSerializerHelper.cs @@ -12,11 +12,9 @@ public static T Deserialize(string source) { var serializer = new DataContractSerializer(typeof(T)); - using (var textReader = new StringReader (source)) - using (var xmlReader = new XmlTextReader(textReader)) - { - return (T)serializer.ReadObject(xmlReader); - } + using var textReader = new StringReader (source); + using var xmlReader = new XmlTextReader(textReader); + return (T)serializer.ReadObject(xmlReader); } public static string Serialize(T source, Encoding encoding = null) @@ -24,15 +22,13 @@ public static string Serialize(T source, Encoding encoding = null) var serializer = new DataContractSerializer(typeof(T) == typeof(object) ? source.GetType() : typeof(T)); var sb = new StringBuilder(); - using (var stringWriter = new EncodingStringWriter(sb, encoding)) - using (var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { Indent = true, Encoding = encoding ?? Encoding.Unicode })) - { - serializer.WriteObject(xmlWriter, source); + using var stringWriter = new EncodingStringWriter(sb, encoding); + using var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { Indent = true, Encoding = encoding ?? Encoding.Unicode }); + serializer.WriteObject(xmlWriter, source); - xmlWriter.Flush(); + xmlWriter.Flush(); - return sb.ToString(); - } + return sb.ToString(); } @@ -40,31 +36,25 @@ public static T XmlClone(this T source) { var serializer = new DataContractSerializer(typeof(T)); - using (var stream = new MemoryStream()) - { - serializer.WriteObject(stream, source); + using var stream = new MemoryStream(); + serializer.WriteObject(stream, source); - stream.Position = 0; + stream.Position = 0; - return (T)serializer.ReadObject(stream); - } + return (T)serializer.ReadObject(stream); } public static bool XmlEquals(this T source, T other) { var serializer = new DataContractSerializer(typeof(T)); - using (var stream1 = new MemoryStream()) - { - serializer.WriteObject(stream1, source); + using var stream1 = new MemoryStream(); + serializer.WriteObject(stream1, source); - using (var stream2 = new MemoryStream()) - { - serializer.WriteObject(stream2, other); + using var stream2 = new MemoryStream(); + serializer.WriteObject(stream2, other); - return stream1.ToArray().SequenceEqual(stream2.ToArray()); - } - } + return stream1.ToArray().SequenceEqual(stream2.ToArray()); } diff --git a/src/Framework.Core/Serialization/Base85Convert.cs b/src/Framework.Core/Serialization/Base85Convert.cs index 2d77dd67f..862bd99e0 100644 --- a/src/Framework.Core/Serialization/Base85Convert.cs +++ b/src/Framework.Core/Serialization/Base85Convert.cs @@ -20,12 +20,12 @@ public static string Encode(byte[] bytes) throw new ArgumentNullException(nameof(bytes)); // preallocate a StringBuilder with enough room to store the encoded bytes - StringBuilder sb = new StringBuilder(bytes.Length * 5 / 4); + var sb = new StringBuilder(bytes.Length * 5 / 4); // walk the bytes - int count = 0; + var count = 0; uint value = 0; - foreach (byte b in bytes) + foreach (var b in bytes) { // build a 32-bit value from the bytes value |= ((uint)b) << (24 - (count * 8)); @@ -61,77 +61,76 @@ public static byte[] Decode(string encoded) throw new ArgumentNullException(nameof(encoded)); // preallocate a memory stream with enough capacity to hold the decoded data - using (MemoryStream stream = new MemoryStream(encoded.Length * 4 / 5)) + using var stream = new MemoryStream(encoded.Length * 4 / 5); + + // walk the input string + var count = 0; + uint value = 0; + foreach (var ch in encoded) { - // walk the input string - int count = 0; - uint value = 0; - foreach (char ch in encoded) + if (ch == 'z' && count == 0) + { + // handle "z" block specially + DecodeValue(stream, value, 0); + } + else if (ch < CFirstCharacter || ch > CLastCharacter) + { + throw new FormatException($"Invalid character '{ch}' in Ascii85 block."); + } + else { - if (ch == 'z' && count == 0) + // build a 32-bit value from the input characters + try { - // handle "z" block specially - DecodeValue(stream, value, 0); + checked { value += (uint)(SPowersOf85[count] * (ch - CFirstCharacter)); } } - else if (ch < CFirstCharacter || ch > CLastCharacter) + catch (OverflowException ex) { - throw new FormatException($"Invalid character '{ch}' in Ascii85 block."); + throw new FormatException("The current group of characters decodes to a value greater than UInt32.MaxValue.", ex); } - else + + count++; + + // every five characters, convert the characters into the equivalent byte array + if (count == 5) { - // build a 32-bit value from the input characters - try - { - checked { value += (uint)(SPowersOf85[count] * (ch - CFirstCharacter)); } - } - catch (OverflowException ex) - { - throw new FormatException("The current group of characters decodes to a value greater than UInt32.MaxValue.", ex); - } - - count++; - - // every five characters, convert the characters into the equivalent byte array - if (count == 5) - { - DecodeValue(stream, value, 0); - count = 0; - value = 0; - } + DecodeValue(stream, value, 0); + count = 0; + value = 0; } } + } - if (count == 1) - { - throw new FormatException("The final Ascii85 block must contain more than one character."); - } - else if (count > 1) + if (count == 1) + { + throw new FormatException("The final Ascii85 block must contain more than one character."); + } + else if (count > 1) + { + // decode any remaining characters + for (var padding = count; padding < 5; padding++) { - // decode any remaining characters - for (int padding = count; padding < 5; padding++) + try + { + checked { value += 84 * SPowersOf85[padding]; } + } + catch (OverflowException ex) { - try - { - checked { value += 84 * SPowersOf85[padding]; } - } - catch (OverflowException ex) - { - throw new FormatException("The current group of characters decodes to a value greater than UInt32.MaxValue.", ex); - } + throw new FormatException("The current group of characters decodes to a value greater than UInt32.MaxValue.", ex); } - DecodeValue(stream, value, 5 - count); } - - return stream.ToArray(); + DecodeValue(stream, value, 5 - count); } + + return stream.ToArray(); } // Writes the Ascii85 characters for a 32-bit value to a StringBuilder. private static void EncodeValue(StringBuilder sb, uint value, int paddingBytes) { - char[] encoded = new char[5]; + var encoded = new char[5]; - for (int index = 4; index >= 0; index--) + for (var index = 4; index >= 0; index--) { encoded[index] = (char)((value % 85) + CFirstCharacter); value /= 85; diff --git a/src/Framework.Core/XDocumentExtensions.cs b/src/Framework.Core/XDocumentExtensions.cs index 1309eeb1d..be53eb8a2 100644 --- a/src/Framework.Core/XDocumentExtensions.cs +++ b/src/Framework.Core/XDocumentExtensions.cs @@ -29,21 +29,17 @@ public static XmlDocument ToXmlDocument(this XDocument xDocument) { var xmlDocument = new XmlDocument(); - using (var xmlReader = xDocument.CreateReader()) - { - xmlDocument.Load(xmlReader); - } + using var xmlReader = xDocument.CreateReader(); + xmlDocument.Load(xmlReader); return xmlDocument; } public static XDocument ToXDocument(this XmlDocument xmlDocument) { - using (var nodeReader = new XmlNodeReader(xmlDocument)) - { - nodeReader.MoveToContent(); + using var nodeReader = new XmlNodeReader(xmlDocument); + nodeReader.MoveToContent(); - return XDocument.Load(nodeReader); - } + return XDocument.Load(nodeReader); } } diff --git a/src/Framework.ExpressionParsers.Tests/Framework.ExpressionParsers.Tests.csproj b/src/Framework.ExpressionParsers.Tests/Framework.ExpressionParsers.Tests.csproj index 0df487830..3350dd9e4 100644 --- a/src/Framework.ExpressionParsers.Tests/Framework.ExpressionParsers.Tests.csproj +++ b/src/Framework.ExpressionParsers.Tests/Framework.ExpressionParsers.Tests.csproj @@ -6,7 +6,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Framework.ExpressionParsers/CSharp/CSharpNativeExpressionParser.cs b/src/Framework.ExpressionParsers/CSharp/CSharpNativeExpressionParser.cs index 5f9c811ab..6fc171378 100644 --- a/src/Framework.ExpressionParsers/CSharp/CSharpNativeExpressionParser.cs +++ b/src/Framework.ExpressionParsers/CSharp/CSharpNativeExpressionParser.cs @@ -66,7 +66,7 @@ private IEnumerable GetParametersNames(string expression) } var currentResult = new List(); - Func returnFunc = () => + var returnFunc = () => { var result = new string(currentResult.ToArray()); currentResult.Clear(); diff --git a/src/Framework.ExpressionParsers/CSharp/MicrosoftCSharpExpressionParserImplement.cs b/src/Framework.ExpressionParsers/CSharp/MicrosoftCSharpExpressionParserImplement.cs index 71c1b1d74..b986634cb 100644 --- a/src/Framework.ExpressionParsers/CSharp/MicrosoftCSharpExpressionParserImplement.cs +++ b/src/Framework.ExpressionParsers/CSharp/MicrosoftCSharpExpressionParserImplement.cs @@ -29,7 +29,7 @@ public override string ToString() var props = this.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); var sb = new StringBuilder(); sb.Append("{"); - for (int i = 0; i < props.Length; i++) + for (var i = 0; i < props.Length; i++) { if (i > 0) { @@ -81,7 +81,7 @@ public Signature(IEnumerable properties) { this.Properties = properties.ToArray(); this.HashCode = 0; - foreach (DynamicProperty p in properties) + foreach (var p in properties) { this.HashCode ^= p.Name.GetHashCode() ^ p.Type.GetHashCode(); } @@ -94,7 +94,7 @@ public Signature(IEnumerable properties) public bool Equals(Signature other) { if (this.Properties.Length != other.Properties.Length) return false; - for (int i = 0; i < this.Properties.Length; i++) + for (var i = 0; i < this.Properties.Length; i++) { if (this.Properties[i].Name != other.Properties[i].Name || this.Properties[i].Type != other.Properties[i].Type) return false; } @@ -115,8 +115,8 @@ static ClassFactory() { } // Trigger lazy initialization of static fields private ClassFactory() { - AssemblyName name = new AssemblyName("DynamicClasses"); - AssemblyBuilder assembly = AssemblyBuilder.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run); + var name = new AssemblyName("DynamicClasses"); + var assembly = AssemblyBuilder.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run); #if ENABLE_LINQ_PARTIAL_TRUST new ReflectionPermission(PermissionState.Unrestricted).Assert(); #endif @@ -139,7 +139,7 @@ public Type GetDynamicClass(IEnumerable properties) this.rwLock.AcquireReaderLock(Timeout.Infinite); try { - Signature signature = new Signature(properties); + var signature = new Signature(properties); Type type; if (!this.classes.TryGetValue(signature, out type)) { @@ -156,18 +156,18 @@ public Type GetDynamicClass(IEnumerable properties) Type CreateDynamicClass(DynamicProperty[] properties) { - LockCookie cookie = this.rwLock.UpgradeToWriterLock(Timeout.Infinite); + var cookie = this.rwLock.UpgradeToWriterLock(Timeout.Infinite); try { - string typeName = "DynamicClass" + (this.classCount + 1); + var typeName = "DynamicClass" + (this.classCount + 1); #if ENABLE_LINQ_PARTIAL_TRUST new ReflectionPermission(PermissionState.Unrestricted).Assert(); #endif try { - TypeBuilder tb = this.module.DefineType(typeName, TypeAttributes.Class | - TypeAttributes.Public, typeof(DynamicClass)); - FieldInfo[] fields = this.GenerateProperties(tb, properties); + var tb = this.module.DefineType(typeName, TypeAttributes.Class | + TypeAttributes.Public, typeof(DynamicClass)); + var fields = this.GenerateProperties(tb, properties); this.GenerateEquals(tb, fields); this.GenerateGetHashCode(tb, fields); Type result = tb.CreateTypeInfo(); @@ -190,7 +190,7 @@ Type CreateDynamicClass(DynamicProperty[] properties) FieldInfo[] GenerateProperties(TypeBuilder tb, DynamicProperty[] properties) { FieldInfo[] fields = new FieldBuilder[properties.Length]; - for (int i = 0; i < properties.Length; i++) + for (var i = 0; i < properties.Length; i++) { var dp = properties[i]; var fb = tb.DefineField("_" + dp.Name, dp.Type, FieldAttributes.Private); @@ -236,10 +236,10 @@ void GenerateEquals(TypeBuilder tb, FieldInfo[] fields) gen.Emit(OpCodes.Ldc_I4_0); gen.Emit(OpCodes.Ret); gen.MarkLabel(next); - foreach (FieldInfo field in fields) + foreach (var field in fields) { - Type ft = field.FieldType; - Type ct = typeof(EqualityComparer<>).MakeGenericType(ft); + var ft = field.FieldType; + var ct = typeof(EqualityComparer<>).MakeGenericType(ft); next = gen.DefineLabel(); gen.EmitCall(OpCodes.Call, ct.GetMethod("get_Default"), null); gen.Emit(OpCodes.Ldarg_0); @@ -264,10 +264,10 @@ void GenerateGetHashCode(TypeBuilder tb, FieldInfo[] fields) typeof(int), Type.EmptyTypes); var gen = mb.GetILGenerator(); gen.Emit(OpCodes.Ldc_I4_0); - foreach (FieldInfo field in fields) + foreach (var field in fields) { - Type ft = field.FieldType; - Type ct = typeof(EqualityComparer<>).MakeGenericType(ft); + var ft = field.FieldType; + var ct = typeof(EqualityComparer<>).MakeGenericType(ft); gen.EmitCall(OpCodes.Call, ct.GetMethod("get_Default"), null); gen.Emit(OpCodes.Ldarg_0); gen.Emit(OpCodes.Ldfld, field); @@ -550,9 +550,9 @@ void ProcessParameters(ParameterExpression[] parameters) void ProcessValues(object[] values) { - for (int i = 0; i < values.Length; i++) + for (var i = 0; i < values.Length; i++) { - object value = values[i]; + var value = values[i]; if (i == values.Length - 1 && value is IDictionary) { this.externals = (IDictionary)value; @@ -591,8 +591,8 @@ public IEnumerable ParseOrdering() List orderings = []; while (true) { - Expression expr = this.ParseExpression(); - bool ascending = true; + var expr = this.ParseExpression(); + var ascending = true; if (this.TokenIdentifierIs("asc") || this.TokenIdentifierIs("ascending")) { this.NextToken(); @@ -614,15 +614,15 @@ public IEnumerable ParseOrdering() // ?: operator Expression ParseExpression() { - int errorPos = this.token.Pos; - Expression expr = this.ParseLogicalOr(); + var errorPos = this.token.Pos; + var expr = this.ParseLogicalOr(); if (this.token.Id == TokenId.Question) { this.NextToken(); - Expression expr1 = this.ParseExpression(); + var expr1 = this.ParseExpression(); this.ValidateToken(TokenId.Colon, ExpressionParsersResources.ColonExpected); this.NextToken(); - Expression expr2 = this.ParseExpression(); + var expr2 = this.ParseExpression(); expr = this.GenerateConditional(expr, expr1, expr2, errorPos); } return expr; @@ -631,12 +631,12 @@ Expression ParseExpression() // ||, or operator Expression ParseLogicalOr() { - Expression left = this.ParseLogicalAnd(); + var left = this.ParseLogicalAnd(); while (this.token.Id == TokenId.DoubleBar || this.TokenIdentifierIs("or")) { - Token op = this.token; + var op = this.token; this.NextToken(); - Expression right = this.ParseLogicalAnd(); + var right = this.ParseLogicalAnd(); this.CheckAndPromoteOperands(typeof(ILogicalSignatures), op.Text, ref left, ref right, op.Pos); left = Expression.OrElse(left, right); } @@ -646,12 +646,12 @@ Expression ParseLogicalOr() // &&, and operator Expression ParseLogicalAnd() { - Expression left = this.ParseComparison(); + var left = this.ParseComparison(); while (this.token.Id == TokenId.DoubleAmphersand || this.TokenIdentifierIs("and")) { - Token op = this.token; + var op = this.token; this.NextToken(); - Expression right = this.ParseComparison(); + var right = this.ParseComparison(); this.CheckAndPromoteOperands(typeof(ILogicalSignatures), op.Text, ref left, ref right, op.Pos); left = Expression.AndAlso(left, right); } @@ -661,14 +661,14 @@ Expression ParseLogicalAnd() // =, ==, !=, <>, >, >=, <, <= operators Expression ParseComparison() { - Expression left = this.ParseAdditive(); + var left = this.ParseAdditive(); while (this.token.Id == TokenId.Equal || this.token.Id == TokenId.DoubleEqual || this.token.Id == TokenId.ExclamationEqual || this.token.Id == TokenId.LessGreater || this.token.Id == TokenId.GreaterThan || this.token.Id == TokenId.GreaterThanEqual || this.token.Id == TokenId.LessThan || this.token.Id == TokenId.LessThanEqual) { - Token op = this.token; + var op = this.token; this.NextToken(); - Expression right = this.ParseAdditive(); - bool isEquality = op.Id == TokenId.Equal || op.Id == TokenId.DoubleEqual || - op.Id == TokenId.ExclamationEqual || op.Id == TokenId.LessGreater; + var right = this.ParseAdditive(); + var isEquality = op.Id == TokenId.Equal || op.Id == TokenId.DoubleEqual || + op.Id == TokenId.ExclamationEqual || op.Id == TokenId.LessGreater; if (isEquality && !left.Type.IsValueType && !right.Type.IsValueType) { if (left.Type != right.Type) @@ -741,12 +741,12 @@ Expression ParseComparison() // +, -, & operators Expression ParseAdditive() { - Expression left = this.ParseMultiplicative(); + var left = this.ParseMultiplicative(); while (this.token.Id == TokenId.Plus || this.token.Id == TokenId.Minus || this.token.Id == TokenId.Amphersand) { - Token op = this.token; + var op = this.token; this.NextToken(); - Expression right = this.ParseMultiplicative(); + var right = this.ParseMultiplicative(); switch (op.Id) { case TokenId.Plus: @@ -770,12 +770,12 @@ Expression ParseAdditive() // *, /, %, mod operators Expression ParseMultiplicative() { - Expression left = this.ParseUnary(); + var left = this.ParseUnary(); while (this.token.Id == TokenId.Asterisk || this.token.Id == TokenId.Slash || this.token.Id == TokenId.Percent || this.TokenIdentifierIs("mod")) { - Token op = this.token; + var op = this.token; this.NextToken(); - Expression right = this.ParseUnary(); + var right = this.ParseUnary(); this.CheckAndPromoteOperands(typeof(IArithmeticSignatures), op.Text, ref left, ref right, op.Pos); switch (op.Id) { @@ -799,7 +799,7 @@ Expression ParseUnary() { if (this.token.Id == TokenId.Minus || this.token.Id == TokenId.Exclamation || this.TokenIdentifierIs("not")) { - Token op = this.token; + var op = this.token; this.NextToken(); if (op.Id == TokenId.Minus && (this.token.Id == TokenId.IntegerLiteral || this.token.Id == TokenId.RealLiteral)) { @@ -807,7 +807,7 @@ Expression ParseUnary() this.token.Pos = op.Pos; return this.ParsePrimary(); } - Expression expr = this.ParseUnary(); + var expr = this.ParseUnary(); if (op.Id == TokenId.Minus) { this.CheckAndPromoteOperand(typeof(INegationSignatures), op.Text, ref expr, op.Pos); @@ -825,7 +825,7 @@ Expression ParseUnary() Expression ParsePrimary() { - Expression expr = this.ParsePrimaryStart(); + var expr = this.ParsePrimaryStart(); while (true) { if (this.token.Id == TokenId.Dot) @@ -867,12 +867,12 @@ Expression ParsePrimaryStart() Expression ParseStringLiteral() { this.ValidateToken(TokenId.StringLiteral); - char quote = this.token.Text[0]; - string s = this.token.Text.Substring(1, this.token.Text.Length - 2); - int start = 0; + var quote = this.token.Text[0]; + var s = this.token.Text.Substring(1, this.token.Text.Length - 2); + var start = 0; while (true) { - int i = s.IndexOf(quote, start); + var i = s.IndexOf(quote, start); if (i < 0) break; s = s.Remove(i, 1); start = i + 1; @@ -891,7 +891,7 @@ Expression ParseStringLiteral() Expression ParseIntegerLiteral() { this.ValidateToken(TokenId.IntegerLiteral); - string text = this.token.Text; + var text = this.token.Text; if (text[0] != '-') { ulong value; @@ -918,9 +918,9 @@ Expression ParseIntegerLiteral() Expression ParseRealLiteral() { this.ValidateToken(TokenId.RealLiteral); - string text = this.token.Text; + var text = this.token.Text; object value = null; - char last = text[text.Length - 1]; + var last = text[text.Length - 1]; if (last == 'F' || last == 'f') { float f; @@ -947,7 +947,7 @@ Expression ParseRealLiteral() Expression CreateLiteral(object value, string text) { - ConstantExpression expr = Expression.Constant(value); + var expr = Expression.Constant(value); this.literals.Add(expr, text); return expr; } @@ -1013,9 +1013,9 @@ Expression ParseIt() Expression ParseIif() { - int errorPos = this.token.Pos; + var errorPos = this.token.Pos; this.NextToken(); - Expression[] args = this.ParseArgumentList(); + var args = this.ParseArgumentList(); if (args.Length != 3) throw this.ParseError(errorPos, ExpressionParsersResources.IifRequiresThreeArgs); return this.GenerateConditional(args[0], args[1], args[2], errorPos); @@ -1027,8 +1027,8 @@ Expression GenerateConditional(Expression test, Expression expr1, Expression exp throw this.ParseError(errorPos, ExpressionParsersResources.FirstExprMustBeBool); if (expr1.Type != expr2.Type) { - Expression expr1As2 = expr2 != NullLiteral ? this.PromoteExpression(expr1, expr2.Type, true) : null; - Expression expr2As1 = expr1 != NullLiteral ? this.PromoteExpression(expr2, expr1.Type, true) : null; + var expr1As2 = expr2 != NullLiteral ? this.PromoteExpression(expr1, expr2.Type, true) : null; + var expr2As1 = expr1 != NullLiteral ? this.PromoteExpression(expr2, expr1.Type, true) : null; if (expr1As2 != null && expr2As1 == null) { expr1 = expr1As2; @@ -1039,8 +1039,8 @@ Expression GenerateConditional(Expression test, Expression expr1, Expression exp } else { - string type1 = expr1 != NullLiteral ? expr1.Type.Name : "null"; - string type2 = expr2 != NullLiteral ? expr2.Type.Name : "null"; + var type1 = expr1 != NullLiteral ? expr1.Type.Name : "null"; + var type2 = expr2 != NullLiteral ? expr2.Type.Name : "null"; if (expr1As2 != null && expr2As1 != null) throw this.ParseError(errorPos, ExpressionParsersResources.BothTypesConvertToOther, type1, type2); throw this.ParseError(errorPos, ExpressionParsersResources.NeitherTypeConvertsToOther, type1, type2); @@ -1076,8 +1076,8 @@ private Expression ParseDynamicType() var expressions = new List(); while (true) { - int exprPos = this.token.Pos; - Expression expr = this.ParseExpression(); + var exprPos = this.token.Pos; + var expr = this.ParseExpression(); string propName; if (this.TokenIdentifierIs("as")) { @@ -1103,7 +1103,7 @@ private Expression ParseDynamicType() this.NextToken(); var type = CreateClass(properties); var bindings = new MemberBinding[properties.Count]; - for (int i = 0; i < bindings.Length; i++) + for (var i = 0; i < bindings.Length; i++) { bindings[i] = Expression.Bind(type.GetProperty(properties[i].Name), expressions[i]); } @@ -1112,7 +1112,7 @@ private Expression ParseDynamicType() Expression ParseExpressionInvocation(LambdaExpression lambda) { - int errorPos = this.token.Pos; + var errorPos = this.token.Pos; this.NextToken(); var args = this.ParseArgumentList(); if (!(this.FindMethod(lambda.Type, "Invoke", false, args) is FindMethodsResult.SimpleResult)) @@ -1124,7 +1124,7 @@ Expression ParseExpressionInvocation(LambdaExpression lambda) Expression ParseTypeAccess(Type type) { - int errorPos = this.token.Pos; + var errorPos = this.token.Pos; this.NextToken(); if (this.token.Id == TokenId.Question) { @@ -1135,7 +1135,7 @@ Expression ParseTypeAccess(Type type) } if (this.token.Id == TokenId.OpenParen) { - Expression[] args = this.ParseArgumentList(); + var args = this.ParseArgumentList(); var result = this.FindBestMethod(type.GetConstructors(), args); if (result is FindMethodsResult.NoneResult) { @@ -1158,7 +1158,7 @@ Expression ParseTypeAccess(Type type) Expression GenerateConversion(Expression expr, Type type, int errorPos) { - Type exprType = expr.Type; + var exprType = expr.Type; if (exprType == type) return expr; if (exprType.IsValueType && type.IsValueType) { @@ -1263,9 +1263,9 @@ static Type FindGenericType(Type generic, Type type) if (type.IsGenericTypeImplementation(generic)) return type; if (generic.IsInterface) { - foreach (Type intfType in type.GetInterfaces()) + foreach (var intfType in type.GetInterfaces()) { - Type found = FindGenericType(generic, intfType); + var found = FindGenericType(generic, intfType); if (found != null) return found; } } @@ -1278,7 +1278,7 @@ Expression[] ParseArgumentList() { this.ValidateToken(TokenId.OpenParen, ExpressionParsersResources.OpenParenExpected); this.NextToken(); - Expression[] args = this.token.Id != TokenId.CloseParen ? this.ParseArguments() : []; + var args = this.token.Id != TokenId.CloseParen ? this.ParseArguments() : []; this.ValidateToken(TokenId.CloseParen, ExpressionParsersResources.CloseParenOrCommaExpected); this.NextToken(); return args; @@ -1298,17 +1298,17 @@ Expression[] ParseArguments() Expression ParseElementAccess(Expression expr) { - int errorPos = this.token.Pos; + var errorPos = this.token.Pos; this.ValidateToken(TokenId.OpenBracket, ExpressionParsersResources.OpenParenExpected); this.NextToken(); - Expression[] args = this.ParseArguments(); + var args = this.ParseArguments(); this.ValidateToken(TokenId.CloseBracket, ExpressionParsersResources.CloseBracketOrCommaExpected); this.NextToken(); if (expr.Type.IsArray) { if (expr.Type.GetArrayRank() != 1 || args.Length != 1) throw this.ParseError(errorPos, ExpressionParsersResources.CannotIndexMultiDimArray); - Expression index = this.PromoteExpression(args[0], typeof(int), true); + var index = this.PromoteExpression(args[0], typeof(int), true); if (index == null) throw this.ParseError(errorPos, ExpressionParsersResources.InvalidIndex); return Expression.ArrayIndex(expr, index); @@ -1332,7 +1332,7 @@ Expression ParseElementAccess(Expression expr) static bool IsPredefinedType(Type type) { - foreach (Type t in PredefinedTypes) if (t == type) return true; + foreach (var t in PredefinedTypes) if (t == type) return true; return false; } @@ -1342,8 +1342,8 @@ static bool IsPredefinedType(Type type) static string GetTypeName(Type type) { - Type baseType = GetNonNullableType(type); - string s = baseType.Name; + var baseType = GetNonNullableType(type); + var s = baseType.Name; if (type != baseType) s += '?'; return s; } @@ -1409,12 +1409,12 @@ Exception IncompatibleOperandsError(string opName, Expression left, Expression r MemberInfo FindPropertyOrField(Type type, string memberName, bool staticAccess) { - BindingFlags flags = BindingFlags.Public | BindingFlags.DeclaredOnly | - (staticAccess ? BindingFlags.Static : BindingFlags.Instance); - foreach (Type t in SelfAndBaseTypes(type)) + var flags = BindingFlags.Public | BindingFlags.DeclaredOnly | + (staticAccess ? BindingFlags.Static : BindingFlags.Instance); + foreach (var t in SelfAndBaseTypes(type)) { - MemberInfo[] members = t.FindMembers(MemberTypes.Property | MemberTypes.Field, - flags, Type.FilterNameIgnoreCase, memberName); + var members = t.FindMembers(MemberTypes.Property | MemberTypes.Field, + flags, Type.FilterNameIgnoreCase, memberName); if (members.Length != 0) return members[0]; } return null; @@ -1459,7 +1459,7 @@ FindMethodsResult FindMethod(Type type, string methodName, bool staticAccess, Ex FindMethodsResult FindIndexer(Type type, Expression[] args) { - foreach (Type t in SelfAndBaseTypes(type)) + foreach (var t in SelfAndBaseTypes(type)) { var members = t.GetDefaultMembers(); @@ -1506,7 +1506,7 @@ static void AddInterface(List types, Type type) if (!types.Contains(type)) { types.Add(type); - foreach (Type t in type.GetInterfaces()) AddInterface(types, t); + foreach (var t in type.GetInterfaces()) AddInterface(types, t); } } @@ -1549,11 +1549,11 @@ bool IsApplicable(MethodData method, Expression[] args) { if (method.Parameters.Length != args.Length) return false; var promotedArgs = new Expression[args.Length]; - for (int i = 0; i < args.Length; i++) + for (var i = 0; i < args.Length; i++) { - ParameterInfo pi = method.Parameters[i]; + var pi = method.Parameters[i]; if (pi.IsOut) return false; - Expression promoted = this.PromoteExpression(args[i], pi.ParameterType, false); + var promoted = this.PromoteExpression(args[i], pi.ParameterType, false); if (promoted == null) return false; promotedArgs[i] = promoted; } @@ -1566,7 +1566,7 @@ Expression PromoteExpression(Expression expr, Type type, bool exact) if (expr.Type == type) return expr; if (expr is ConstantExpression) { - ConstantExpression ce = (ConstantExpression)expr; + var ce = (ConstantExpression)expr; if (ce == NullLiteral) { if (!type.IsValueType || IsNullableType(type)) @@ -1577,7 +1577,7 @@ Expression PromoteExpression(Expression expr, Type type, bool exact) string text; if (this.literals.TryGetValue(ce, out text)) { - Type target = GetNonNullableType(type); + var target = GetNonNullableType(type); object value = null; switch (Type.GetTypeCode(ce.Type)) { @@ -1663,9 +1663,9 @@ static object ParseEnum(string name, Type type) { if (type.IsEnum) { - MemberInfo[] memberInfos = type.FindMembers(MemberTypes.Field, - BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Static, - Type.FilterNameIgnoreCase, name); + var memberInfos = type.FindMembers(MemberTypes.Field, + BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Static, + Type.FilterNameIgnoreCase, name); if (memberInfos.Length != 0) return ((FieldInfo)memberInfos[0]).GetValue(null); } return null; @@ -1675,11 +1675,11 @@ static bool IsCompatibleWith(Type source, Type target) { if (source == target) return true; if (!target.IsValueType) return target.IsAssignableFrom(source); - Type st = GetNonNullableType(source); - Type tt = GetNonNullableType(target); + var st = GetNonNullableType(source); + var tt = GetNonNullableType(target); if (st != source && tt == target) return false; - TypeCode sc = st.IsEnum ? TypeCode.Object : Type.GetTypeCode(st); - TypeCode tc = tt.IsEnum ? TypeCode.Object : Type.GetTypeCode(tt); + var sc = st.IsEnum ? TypeCode.Object : Type.GetTypeCode(st); + var tc = tt.IsEnum ? TypeCode.Object : Type.GetTypeCode(tt); switch (sc) { case TypeCode.SByte: @@ -1797,10 +1797,10 @@ static bool IsCompatibleWith(Type source, Type target) static bool IsBetterThan(Expression[] args, MethodData m1, MethodData m2) { - bool better = false; - for (int i = 0; i < args.Length; i++) + var better = false; + for (var i = 0; i < args.Length; i++) { - int c = CompareConversions(args[i].Type, + var c = CompareConversions(args[i].Type, m1.Parameters[i].ParameterType, m2.Parameters[i].ParameterType); if (c < 0) @@ -1823,8 +1823,8 @@ static int CompareConversions(Type s, Type t1, Type t2) if (t1 == t2) return 0; if (s == t1) return 1; if (s == t2) return -1; - bool t1T2 = IsCompatibleWith(t1, t2); - bool t2T1 = IsCompatibleWith(t2, t1); + var t1T2 = IsCompatibleWith(t1, t2); + var t2T1 = IsCompatibleWith(t2, t1); if (t1T2 && !t2T1) return 1; if (t2T1 && !t1T2) return -1; if (IsSignedIntegralType(t1) && IsUnsignedIntegralType(t2)) return 1; @@ -1920,7 +1920,7 @@ void NextToken() this.NextChar(); } TokenId t; - int tokenPos = this.textPos; + var tokenPos = this.textPos; switch (this.currentChar) { case '!': @@ -2054,7 +2054,7 @@ void NextToken() break; case '"': case '\'': - char quote = this.currentChar; + var quote = this.currentChar; do { this.NextChar(); @@ -2128,7 +2128,7 @@ void NextToken() string GetIdentifier() { this.ValidateToken(TokenId.Identifier, ExpressionParsersResources.IdentifierExpected); - string id = this.token.Text; + var id = this.token.Text; if (id.Length > 1 && id[0] == '@') { id = id.Substring(1); diff --git a/src/Framework.ExpressionParsers/CSharp/RoslynCSharpExpressionParser.cs b/src/Framework.ExpressionParsers/CSharp/RoslynCSharpExpressionParser.cs index b1a9e7b7e..a42c389af 100644 --- a/src/Framework.ExpressionParsers/CSharp/RoslynCSharpExpressionParser.cs +++ b/src/Framework.ExpressionParsers/CSharp/RoslynCSharpExpressionParser.cs @@ -64,27 +64,25 @@ public Expression Parse(ParameterExpression[] parameters, Type returnType, strin .AddReferences(references) .AddSyntaxTrees(CSharpSyntaxTree.ParseText(source)); - using (var stream = new MemoryStream()) - { - var compileResult = compilation.Emit(stream); + using var stream = new MemoryStream(); + var compileResult = compilation.Emit(stream); - if (compileResult.Success) - { - stream.Position = 0; + if (compileResult.Success) + { + stream.Position = 0; - var assembly = AssemblyLoadContext.Default.LoadFromStream(stream); + var assembly = AssemblyLoadContext.Default.LoadFromStream(stream); - var expressionParserType = assembly.GetType($"{namespaceName}.{typeName}"); + var expressionParserType = assembly.GetType($"{namespaceName}.{typeName}"); - return expressionParserType.GetMethod(methodName).Invoke(null); - } - else - { + return expressionParserType.GetMethod(methodName).Invoke(null); + } + else + { - var errorTextBuilder = compileResult.Diagnostics.Join(",", d => $"{d.Id}: {d.GetMessage()}"); - var exception = new ParseException(errorTextBuilder, 0); - throw exception; - } + var errorTextBuilder = compileResult.Diagnostics.Join(",", d => $"{d.Id}: {d.GetMessage()}"); + var exception = new ParseException(errorTextBuilder, 0); + throw exception; } } } diff --git a/src/Framework.ExpressionParsers/CSharp/ScriptEngineService.cs b/src/Framework.ExpressionParsers/CSharp/ScriptEngineService.cs index 2030df9c5..53caf1f8d 100644 --- a/src/Framework.ExpressionParsers/CSharp/ScriptEngineService.cs +++ b/src/Framework.ExpressionParsers/CSharp/ScriptEngineService.cs @@ -160,7 +160,7 @@ private IEnumerable GetParametersNames(string expression) } var currentResult = new List(); - Func returnFunc = () => + var returnFunc = () => { var result = new string(currentResult.ToArray()); currentResult.Clear(); diff --git a/src/Validation/Framework.Validation.Tests/Framework.Validation.Tests.csproj b/src/Validation/Framework.Validation.Tests/Framework.Validation.Tests.csproj index 38eaac1ee..ff6a13808 100644 --- a/src/Validation/Framework.Validation.Tests/Framework.Validation.Tests.csproj +++ b/src/Validation/Framework.Validation.Tests/Framework.Validation.Tests.csproj @@ -8,7 +8,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/_Authorization/Framework.Authorization.TestGenerate/Framework.Authorization.TestGenerate.csproj b/src/_Authorization/Framework.Authorization.TestGenerate/Framework.Authorization.TestGenerate.csproj index 54bba630f..9ab77be06 100644 --- a/src/_Authorization/Framework.Authorization.TestGenerate/Framework.Authorization.TestGenerate.csproj +++ b/src/_Authorization/Framework.Authorization.TestGenerate/Framework.Authorization.TestGenerate.csproj @@ -6,7 +6,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/_Configuration/Framework.Configuration.TestGenerate/Framework.Configuration.TestGenerate.csproj b/src/_Configuration/Framework.Configuration.TestGenerate/Framework.Configuration.TestGenerate.csproj index 2a4eb0a91..65f51ee5d 100644 --- a/src/_Configuration/Framework.Configuration.TestGenerate/Framework.Configuration.TestGenerate.csproj +++ b/src/_Configuration/Framework.Configuration.TestGenerate/Framework.Configuration.TestGenerate.csproj @@ -6,7 +6,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/_Configuration/Framework.Configuration.WebApi/Impl/QueueService.cs b/src/_Configuration/Framework.Configuration.WebApi/Impl/QueueService.cs index 6ca1de455..c56b86b72 100644 --- a/src/_Configuration/Framework.Configuration.WebApi/Impl/QueueService.cs +++ b/src/_Configuration/Framework.Configuration.WebApi/Impl/QueueService.cs @@ -20,7 +20,7 @@ public int ProcessModifications(int limit) context.Authorization.SecuritySystem.CheckAccessAsync(SecurityRole.SystemIntegration, this.HttpContext.RequestAborted).GetAwaiter().GetResult(); - return context.Logics.DomainObjectModification.Process(limit == default(int) ? 1000 : limit); + return context.Logics.DomainObjectModification.Process(limit == 0 ? 1000 : limit); }); return result.Match(v => v, ex => throw ex); diff --git a/src/_SampleSystem/SampleSystem.WebApiCore/Services/IntegrationEventProcessor.cs b/src/_SampleSystem/SampleSystem.WebApiCore/Services/IntegrationEventProcessor.cs index f124c218f..b870d0b9b 100644 --- a/src/_SampleSystem/SampleSystem.WebApiCore/Services/IntegrationEventProcessor.cs +++ b/src/_SampleSystem/SampleSystem.WebApiCore/Services/IntegrationEventProcessor.cs @@ -17,6 +17,6 @@ public Task ProcessAsync(IIntegrationEvent @event, CancellationToken cancellatio async x => { await x.GetRequiredService().Publish(@event, cancellationToken); - return default!; + return null!; }); } diff --git a/src/_SampleSystem/_Tests/SampleSystem.CheckGenTests/SampleSystem.CheckGenTests.csproj b/src/_SampleSystem/_Tests/SampleSystem.CheckGenTests/SampleSystem.CheckGenTests.csproj index 04d220bc4..a9d425e4e 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.CheckGenTests/SampleSystem.CheckGenTests.csproj +++ b/src/_SampleSystem/_Tests/SampleSystem.CheckGenTests/SampleSystem.CheckGenTests.csproj @@ -6,7 +6,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/_SampleSystem/_Tests/SampleSystem.CodeGenerate/SampleSystem.CodeGenerate.csproj b/src/_SampleSystem/_Tests/SampleSystem.CodeGenerate/SampleSystem.CodeGenerate.csproj index ed496d254..1d70df975 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.CodeGenerate/SampleSystem.CodeGenerate.csproj +++ b/src/_SampleSystem/_Tests/SampleSystem.CodeGenerate/SampleSystem.CodeGenerate.csproj @@ -5,7 +5,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/_SampleSystem/_Tests/SampleSystem.DbGenerate.NHibernate/SampleSystem.DbGenerate.NHibernate.csproj b/src/_SampleSystem/_Tests/SampleSystem.DbGenerate.NHibernate/SampleSystem.DbGenerate.NHibernate.csproj index b6386c9f6..0ed7653da 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.DbGenerate.NHibernate/SampleSystem.DbGenerate.NHibernate.csproj +++ b/src/_SampleSystem/_Tests/SampleSystem.DbGenerate.NHibernate/SampleSystem.DbGenerate.NHibernate.csproj @@ -8,7 +8,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AsyncControllerTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AsyncControllerTests.cs index ebb2d7c04..fcf24902e 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AsyncControllerTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AsyncControllerTests.cs @@ -4,7 +4,7 @@ namespace SampleSystem.IntegrationTests; -public class AsyncControllerTests : TestBase +public class AsyncControllerTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public async Task TestSaveLocation_LocationSaved() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuditTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuditTests.cs index 82820a277..4eaf33474 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuditTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuditTests.cs @@ -14,7 +14,7 @@ namespace SampleSystem.IntegrationTests; -public class AuditTests : TestBase +public class AuditTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void GetObjectRevisions_CheckCount_Correct() @@ -35,7 +35,7 @@ public void GetObjectRevisions_CheckCount_Correct() var employeeIdentity = employeeController.Evaluate(c => c.SaveEmployee(employeeStrictDto)); - for (int q = 0; q < testCount; q++) + for (var q = 0; q < testCount; q++) { var employeeFull = employeeController.Evaluate(c => c.GetFullEmployee(employeeIdentity)); var employeeStrict = employeeFull.ToStrict(); @@ -68,7 +68,7 @@ public void GetObjectByRevision_CheckState_Correct() var employeeIdentity = employeeController.Evaluate(c => c.SaveEmployee(employeeStrictDto)); - for (int q = 0; q < testCount; q++) + for (var q = 0; q < testCount; q++) { var employeeFull = employeeController.Evaluate(c => c.GetFullEmployee(employeeIdentity)); var employeeStrict = employeeFull.ToStrict(); @@ -143,7 +143,7 @@ public void GetObjectPropertyRevisions_ChangePrimitiveProperty_CorrectRevisions( var employeeIdentity = employeeController.Evaluate(c => c.SaveEmployee(employeeStrictDto)); - for (int q = 0; q < testCount; q++) + for (var q = 0; q < testCount; q++) { var employeeFull = employeeController.Evaluate(c => c.GetFullEmployee(employeeIdentity)); var employeeStrict = employeeFull.ToStrict(); @@ -188,7 +188,7 @@ public void GetObjectPropertyRevisions_CheckFirstRevisioins_HasAddedState() var employeeIdentity = employeeController.Evaluate(c => c.SaveEmployee(employeeStrictDto)); - for (int q = 0; q < testCount; q++) + for (var q = 0; q < testCount; q++) { var employeeFull = employeeController.Evaluate(c => c.GetFullEmployee(employeeIdentity)); var employeeStrict = employeeFull.ToStrict(); @@ -233,7 +233,7 @@ public void GetObjectPropertyRevisions_CheckAfterFirstRevisioins_AllModifiedStat var employeeIdentity = employeeController.Evaluate(c => c.SaveEmployee(employeeStrictDto)); - for (int q = 0; q < testCount; q++) + for (var q = 0; q < testCount; q++) { var employeeFull = employeeController.Evaluate(c => c.GetFullEmployee(employeeIdentity)); var employeeStrict = employeeFull.ToStrict(); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs index 33da392c6..ffb6192fe 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs @@ -11,7 +11,7 @@ namespace SampleSystem.IntegrationTests.Auth; -public class PrincipalTests : TestBase +public class PrincipalTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private const string Name = "luxoft\\Login"; private const string NewName = "luxoft\\ChangeLogin"; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs index 84bdd1bd9..d03532fa1 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs @@ -17,7 +17,7 @@ namespace SampleSystem.IntegrationTests; -public class AuthPerformanceTest : TestBase +public class AuthPerformanceTest(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private IReadOnlyCollection fbuSource; @@ -92,7 +92,7 @@ await this.RootServiceProvider.GetRequiredService().Evaluat var empRep = sp.GetRequiredService>().Create(); var testObjRep = sp.GetRequiredService>().Create(); - int count = 0; + var count = 0; foreach (var fbu in this.fbuSource.Take(Size - 3)) { foreach (var mbu in this.mbuSource.Take(Size - 3)) diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs index d53fabba1..d64ec0e28 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs @@ -12,7 +12,7 @@ namespace SampleSystem.IntegrationTests; -public class AuthPerformanceTests : TestBase +public class AuthPerformanceTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private const string TestUser = "TestUser"; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs index d415e550d..befad639f 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs @@ -8,7 +8,7 @@ namespace SampleSystem.IntegrationTests; -public class BUProjectionTests : TestBase +public class BUProjectionTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private const string TestEmployee0Login = "Test Employee 0"; private const string TestEmployee1Login = "Test Employee 1"; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs index 7632102aa..811883bc0 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs @@ -1,6 +1,5 @@ using Framework.Application; using Framework.AutomationCore.RootServiceProviderContainer; -using Framework.AutomationCore.Utils; using Framework.BLL.Domain.Persistent; using Framework.Core; using Framework.Database; @@ -18,7 +17,7 @@ namespace SampleSystem.IntegrationTests; -public class BusinessUnitTests : TestBase +public class BusinessUnitTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private const string EmployeeName = "TestSecondaryAccessEmployee"; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs index fa7081af3..acb9d4371 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs @@ -9,7 +9,7 @@ namespace SampleSystem.IntegrationTests; -public class CurrentUserManyRelativePathTests : TestBase +public class CurrentUserManyRelativePathTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private Guid[] testEmployeeIdents; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSingleRelativePathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSingleRelativePathTests.cs index 518d53e6b..30841fd13 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSingleRelativePathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSingleRelativePathTests.cs @@ -13,7 +13,7 @@ namespace SampleSystem.IntegrationTests; -public class CurrentUserSingleRelativePathTests : TestBase +public class CurrentUserSingleRelativePathTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private Guid[] testObjectIdents; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs index 0f320c495..8b5441415 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs @@ -9,7 +9,7 @@ namespace SampleSystem.IntegrationTests; -public class CurrentUserSourceTests : TestBase +public class CurrentUserSourceTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void TryGetCurrentUserWithEmployee_CurrentUserResolved() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs index 5f0726e92..a5aed6d4d 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs @@ -9,7 +9,7 @@ namespace SampleSystem.IntegrationTests.DBGeneration; -public class ChangeIndexesStrategyTests : TestBase +public class ChangeIndexesStrategyTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void GenerateLocal_ColumnHasIndexWithIncludedColumns_PreventsDefaultIndexFromGeneration() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/GenerateDBTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/GenerateDBTests.cs index 3f872461f..e96e35ed2 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/GenerateDBTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/GenerateDBTests.cs @@ -5,7 +5,7 @@ namespace SampleSystem.IntegrationTests.DBGeneration; -public class GenerateDBTests : TestBase +public class GenerateDBTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void GenerateDB_SecondTime_ShouldNotFail() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/SchemeUpdateTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/SchemeUpdateTests.cs index 89b0dc47c..f6eb4873e 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/SchemeUpdateTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/SchemeUpdateTests.cs @@ -3,7 +3,7 @@ namespace SampleSystem.IntegrationTests.DBGeneration; -public class SchemeUpdateTests : TestBase +public class SchemeUpdateTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void SchemeUpdate_ExistsDatabase_ShouldNotFail() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs index 04cf66d8c..8d9d3479b 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs @@ -9,7 +9,7 @@ namespace SampleSystem.IntegrationTests.DBGeneration; -public class UniqueGroupDatabaseScriptGeneratorTests : TestBase +public class UniqueGroupDatabaseScriptGeneratorTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void GenerateLocal_UniqueIndexExistsWithLessColumns_RecreatesColumns() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DefaultFieldsTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DefaultFieldsTests.cs index a9aa91eb9..56bd5aeb8 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DefaultFieldsTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DefaultFieldsTests.cs @@ -14,8 +14,8 @@ public void GetDefaultValueFromAttr_CompareWithDTO_DefaultValuesEquals() // Act // Assert - Assert.NotEqual(default(int), dto.IntVal); - Assert.NotEqual(default(string), dto.StrVal); + Assert.NotEqual(0, dto.IntVal); + Assert.NotEqual(null, dto.StrVal); Assert.NotEqual(default(DayOfWeek), dto.EnumVal); Assert.Equal(TestDefaultFieldsMappingObj.IntDefaultVal, dto.IntVal); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs index dd44e6fed..e9ddda724 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs @@ -8,7 +8,7 @@ namespace SampleSystem.IntegrationTests; -public class DependencySecurityTests : TestBase +public class DependencySecurityTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private const string TestEmployeeLogin = "DS SecurityTester"; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs index 6a6fbea61..93df5c5e0 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs @@ -9,7 +9,7 @@ namespace SampleSystem.IntegrationTests; -public class EmployeeProjectionTests : TestBase +public class EmployeeProjectionTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private const string ProjectionPrincipalName = "Projection Tester"; private const string TestEmployee1Login = "Test Employee 1"; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs index 1a2b30708..2b3f739c1 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs @@ -21,7 +21,7 @@ namespace SampleSystem.IntegrationTests; -public class EmployeeTests : TestBase +public class EmployeeTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void GetEmployeeFromDB_FilterByAge_ReturnNotNulRecords() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EnversBug1676.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EnversBug1676.cs index 31cf90094..2e35db7f2 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EnversBug1676.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EnversBug1676.cs @@ -5,7 +5,7 @@ namespace SampleSystem.IntegrationTests; -public class EnversBug1676 : TestBase +public class EnversBug1676(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void OneToOneMapping() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EventDALListenerTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EventDALListenerTests.cs index 6c7772ade..2bac5e8b7 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EventDALListenerTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EventDALListenerTests.cs @@ -6,7 +6,7 @@ namespace SampleSystem.IntegrationTests; -public class EventDALListenerTests : TestBase +public class EventDALListenerTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public async Task Employee_SendCustomEventOperation_ExceptionNotThrow() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs index be131d718..c4d135c77 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs @@ -6,7 +6,7 @@ namespace SampleSystem.IntegrationTests; -public class ExpandPathTests : TestBase +public class ExpandPathTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void LiftToNullableContainsExt_ShouldNotThrowException() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs index 567b01175..f725ae985 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs @@ -16,7 +16,7 @@ namespace SampleSystem.IntegrationTests; -public class ExtraQueryableSecurityPathTests : TestBase +public class ExtraQueryableSecurityPathTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private EmployeeIdentityDTO TestEmployee; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs index a0a36320a..5117c64a4 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs @@ -5,7 +5,7 @@ namespace SampleSystem.IntegrationTests; -public class FixedPropertyValidatorTests : TestBase +public class FixedPropertyValidatorTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void PrimitiveImmutablePropertyChanged_RaisedValidationError() @@ -16,7 +16,7 @@ public void PrimitiveImmutablePropertyChanged_RaisedValidationError() new TestImmutableObjStrictDTO { TestImmutablePrimitiveProperty = "AAA" })); // Act - Action changePropertyAction = () => + var changePropertyAction = () => { var dto = testImmutableObjController.Evaluate(c => c.GetRichTestImmutableObj(identity)); dto.TestImmutablePrimitiveProperty = "BBB"; @@ -38,7 +38,7 @@ public void ReferenceImmutablePropertyChanged_RaisedValidationError() var identity = testImmutableObjController.Evaluate(c => c.SaveTestImmutableObj(new TestImmutableObjStrictDTO { })); // Act - Action changePropertyAction = () => + var changePropertyAction = () => { var dto = testImmutableObjController.Evaluate(c => c.GetRichTestImmutableObj(identity)); dto.TestImmutableRefProperty = this.DataHelper.GetCurrentEmployee(); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs index 05e7d1082..88ae9243f 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs @@ -15,7 +15,7 @@ namespace SampleSystem.IntegrationTests; -public class GetNotificationPrincipalsByHierarchicalContextTests : TestBase +public class GetNotificationPrincipalsByHierarchicalContextTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private BusinessUnitIdentityDTO rootBusinessUnit; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ImpersonateTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ImpersonateTests.cs index 496522ea6..a72fed5e1 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ImpersonateTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ImpersonateTests.cs @@ -3,7 +3,7 @@ namespace SampleSystem.IntegrationTests; -public class ImpersonateTests : TestBase +public class ImpersonateTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public async Task SaveDataWithImpersonate_ImpersonateWork() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/InformationTest.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/InformationTest.cs index 37030a962..57954fcac 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/InformationTest.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/InformationTest.cs @@ -7,7 +7,7 @@ namespace SampleSystem.IntegrationTests; -public class InformationTest : TestBase +public class InformationTest(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void CreateAndRemoveInformation_ContainsIntegrationEvents() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/IntegrationVersionTest.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/IntegrationVersionTest.cs index b725bc52d..5a091e08f 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/IntegrationVersionTest.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/IntegrationVersionTest.cs @@ -9,7 +9,7 @@ namespace SampleSystem.IntegrationTests; -public class IntegrationVersionTest : TestBase +public class IntegrationVersionTest(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void SaveWithMoreVersion_IgnoreLessPolicy_ValueSaved() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JobTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JobTests.cs index 69c90b5d0..d090cda83 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JobTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JobTests.cs @@ -8,7 +8,7 @@ namespace SampleSystem.IntegrationTests; -public class JobTests : TestBase +public class JobTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public async Task InvokeJobs_JobObjectsCreated() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JsonConverterTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JsonConverterTests.cs index fdb2a6232..1d18d9f28 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JsonConverterTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JsonConverterTests.cs @@ -7,7 +7,7 @@ namespace SampleSystem.IntegrationTests; -public class JsonConverterTests : TestBase +public class JsonConverterTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void DateTimeConverted_ResultCorrected() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/LegalEntityProjectionTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/LegalEntityProjectionTests.cs index 5733c4ac1..49edf61a1 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/LegalEntityProjectionTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/LegalEntityProjectionTests.cs @@ -10,7 +10,7 @@ namespace SampleSystem.IntegrationTests; -public class LegalEntityProjectionTests : TestBase +public class LegalEntityProjectionTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void LegalEntityProjectionNestedMappingTest() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManagmentUnitFluentMappingTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManagmentUnitFluentMappingTests.cs index 30a6b962c..e4ed080ee 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManagmentUnitFluentMappingTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManagmentUnitFluentMappingTests.cs @@ -7,7 +7,7 @@ namespace SampleSystem.IntegrationTests; -public class ManagmentUnitFluentMappingTests : TestBase +public class ManagmentUnitFluentMappingTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void CheckBusinessUnitSecondaryAccess_HasAccess() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs index efde84212..f4cb412bb 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs @@ -7,7 +7,7 @@ namespace SampleSystem.IntegrationTests; -public class ManualAndLegacyProjectionSecurityTests : TestBase +public class ManualAndLegacyProjectionSecurityTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private const string TestEmployeeLogin = "MALProjection SecurityTester"; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NH/FullTextSearchTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NH/FullTextSearchTests.cs index 9de1bf9b2..6cf8eaf7a 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NH/FullTextSearchTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NH/FullTextSearchTests.cs @@ -4,7 +4,7 @@ namespace SampleSystem.IntegrationTests.NH; -public class FullTextSearchTests : TestBase +public class FullTextSearchTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { /// /// Тест предназначен для проверки работоспособности диалекта NHibernate, diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NHibFetchTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NHibFetchTests.cs index 3897a20ca..42010ef18 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NHibFetchTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NHibFetchTests.cs @@ -7,7 +7,7 @@ namespace SampleSystem.IntegrationTests; -public class NHibFetchTests : TestBase +public class NHibFetchTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void TestPropCollection_TestPassed() => diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibArrayContainsTest.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibArrayContainsTest.cs index 39eeddeae..98f32c25c 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibArrayContainsTest.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibArrayContainsTest.cs @@ -12,7 +12,7 @@ namespace SampleSystem.IntegrationTests; -public class NhibArrayContainsTest : TestBase +public class NhibArrayContainsTest(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void LinqContainsOverArray_TranslatedAndExecutedCorrectly() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibDateTimeTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibDateTimeTests.cs index e5aab0b26..4800fdaab 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibDateTimeTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibDateTimeTests.cs @@ -6,14 +6,8 @@ namespace SampleSystem.IntegrationTests; -public class NhibDateTimeTests : TestBase +public class NhibDateTimeTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { - private DateTime prevDateTime; - - public NhibDateTimeTests() => this.prevDateTime = this.TimeProvider.GetLocalNow().DateTime; - - protected override void BeforeCleanup() => this.SetCurrentDateTime(this.prevDateTime); - [Fact] public void CreateObject_CreatedDateOverride() { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs index d33bf5abe..6721afe6f 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs @@ -8,7 +8,7 @@ namespace SampleSystem.IntegrationTests; -public class NotificationCountryTests : TestBase +public class NotificationCountryTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void CreateAndUpdateCountry_SingleModificationExists() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/OneToOneTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/OneToOneTests.cs index 6ff21b7e8..3b5057a23 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/OneToOneTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/OneToOneTests.cs @@ -7,7 +7,7 @@ namespace SampleSystem.IntegrationTests; -public class OneToOneTests : TestBase +public class OneToOneTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void GetRequestProjection_ContainsOneToOneDetail_Initialized() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PerfomanceTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PerfomanceTests.cs index 9712ec4c6..6405686f0 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PerfomanceTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PerfomanceTests.cs @@ -10,7 +10,7 @@ namespace SampleSystem.IntegrationTests; -public class PerfomanceTests : TestBase +public class PerfomanceTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void GetEmployee_ToManyFilterParameters_CheckTimeTest() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalTests.cs index 7f0cb5133..59febcc58 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalTests.cs @@ -10,7 +10,7 @@ namespace SampleSystem.IntegrationTests; -public class PrincipalTests : TestBase +public class PrincipalTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void CreatePrincipal_SaveEventExist() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs index d000eecd8..c1d657359 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs @@ -13,7 +13,7 @@ namespace SampleSystem.IntegrationTests; -public class PrincipalWithInitTests : TestBase +public class PrincipalWithInitTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private const string TestPrincipalName = "Duplicate Permission Tester"; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryControllerTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryControllerTests.cs index eb9296df1..916d04057 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryControllerTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryControllerTests.cs @@ -3,7 +3,7 @@ namespace SampleSystem.IntegrationTests; -public class RepositoryControllerTests : TestBase +public class RepositoryControllerTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public async Task TestLoadFromRepository_CurrentEmployeeLoaded() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryWithoutSecurityTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryWithoutSecurityTests.cs index 8802889e2..652f3c74e 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryWithoutSecurityTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryWithoutSecurityTests.cs @@ -3,7 +3,7 @@ namespace SampleSystem.IntegrationTests; -public class RepositoryWithoutSecurityTests : TestBase +public class RepositoryWithoutSecurityTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public async Task GetDataFromUnsecurityRepository_DataLoaded() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs index b45791906..1fc5466a9 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs @@ -14,7 +14,7 @@ namespace SampleSystem.IntegrationTests; -public class RestrictionRoleTests : TestBase +public class RestrictionRoleTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void GetRestrictionObjectsWithRestrictionRole_RestrictionApplied() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SampleSystem.IntegrationTests.NHibernate.csproj b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SampleSystem.IntegrationTests.NHibernate.csproj index c313772ec..8b7cf703a 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SampleSystem.IntegrationTests.NHibernate.csproj +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SampleSystem.IntegrationTests.NHibernate.csproj @@ -9,7 +9,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -23,7 +23,7 @@ - + diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs index 32b52e9a8..3f5d07693 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs @@ -11,7 +11,7 @@ namespace SampleSystem.IntegrationTests; -public class SecurityContextRestrictionFilterTests : TestBase +public class SecurityContextRestrictionFilterTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private static readonly SecurityRole DefaultSecurityRole = SampleSystemSecurityRole.DefaultRole; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityPathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityPathTests.cs index 0b0082bba..ef1c53484 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityPathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityPathTests.cs @@ -12,7 +12,7 @@ namespace SampleSystem.IntegrationTests; -public class SecurityPathTests : TestBase +public class SecurityPathTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void SecurityPathWithContext_EmployeeWithoutContextRestrictions_EmployeeShouldHaveAccess() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs index c04da0fdc..4fdf8f109 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs @@ -14,7 +14,7 @@ namespace SampleSystem.IntegrationTests; -public class SecurityRuleTests : TestBase +public class SecurityRuleTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public async Task ApplyExceptRule_CurrentUserExcepted() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SequenceBllTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SequenceBllTests.cs index 033f42ae2..99c7aad9a 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SequenceBllTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SequenceBllTests.cs @@ -6,7 +6,7 @@ namespace SampleSystem.IntegrationTests; -public class SequenceBllTests : TestBase +public class SequenceBllTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void GetNextNumber_TwoCallsInParallelTransactions_ShouldGiveDifferentNumbers() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs index abf9d326e..25ec8bdcc 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs @@ -9,7 +9,7 @@ namespace SampleSystem.IntegrationTests; -public class SqlParserTests : TestBase +public class SqlParserTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void SaveNullIntoNotNullProperty_RequiredConstraintDALException() @@ -18,7 +18,7 @@ public void SaveNullIntoNotNullProperty_RequiredConstraintDALException() var testObject = new SqlParserTestObj(); // Act - Action action = () => this.EvaluateWrite(context => { context.Logics.SqlParserTestObj.Save(testObject); }); + var action = () => this.EvaluateWrite(context => { context.Logics.SqlParserTestObj.Save(testObject); }); // Assert Assert.Contains("The field \'notNullColumn\' of type SqlParserTestObj must be initialized", Assert.Throws(action).Message); @@ -32,7 +32,7 @@ public void SaveNotUniqueProperty_UniqueViolationConstraintDALException() var testObject2 = new SqlParserTestObj { UniqueColumn = "1", NotNullColumn = "2" }; // Act - Action action = () => this.EvaluateWrite( + var action = () => this.EvaluateWrite( context => { context.Logics.SqlParserTestObj.Save(testObject1); @@ -58,7 +58,7 @@ public void RemoveLinkedObject_RemoveLinkedObjectsDALException() }); // Act - Action action = () => this.EvaluateWrite( + var action = () => this.EvaluateWrite( context => { context.Logics.SqlParserTestObj.Remove(testObject); @@ -95,7 +95,7 @@ public void RemoveHRDepartment_HasEmployeeWithHRDepartment_CorrectExceptionMessa var fullEmployee = employeeController.Evaluate(c => c.GetFullEmployee(employeeIdentity)); // Act - Action action = () => hRDepartmentController.Evaluate(c => c.RemoveHRDepartment(fullEmployee.HRDepartment.Identity)); + var action = () => hRDepartmentController.Evaluate(c => c.RemoveHRDepartment(fullEmployee.HRDepartment.Identity)); // Assert Assert.Equal($"{nameof(HRDepartment)} cannot be removed because it is used in {nameof(Employee)}", Assert.Throws(action).Message); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SubscriptionCustomNotPersistentModelTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SubscriptionCustomNotPersistentModelTests.cs index f248f9958..d28b61ff5 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SubscriptionCustomNotPersistentModelTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SubscriptionCustomNotPersistentModelTests.cs @@ -7,7 +7,7 @@ namespace SampleSystem.IntegrationTests; -public class SubscriptionCustomNotPersistentModelTests : TestBase +public class SubscriptionCustomNotPersistentModelTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void CustomNotPersistentNotificationModel_Always_ShouldNotThrowException() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs index 0f906955d..6b0ca0a57 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs @@ -9,7 +9,7 @@ namespace SampleSystem.IntegrationTests.Subscriptions_Metadata; -public sealed class MetadataSubscriptionSystemServiceTests : TestBase +public sealed class MetadataSubscriptionSystemServiceTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { public MetadataSubscriptionSystemServiceTests() => this.GetNotifications().Clear(); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/TransactionFlushBeforeCommit.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/TransactionFlushBeforeCommit.cs index 52d2c36d5..e5b92c7e6 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/TransactionFlushBeforeCommit.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/TransactionFlushBeforeCommit.cs @@ -7,7 +7,7 @@ namespace SampleSystem.IntegrationTests; -public class TransactionFlushBeforeCommit : TestBase +public class TransactionFlushBeforeCommit(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void ShouldNotConsiderChangesWhileTransactionIsNotCommited() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs index 3264c809c..a4e08313b 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs @@ -4,7 +4,7 @@ namespace SampleSystem.IntegrationTests; -public class UniqueGroupTests : TestBase +public class UniqueGroupTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void UniqueGroup_NonUniqueEntityCreated_ErrorUsesCustomName() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UpdateTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UpdateTests.cs index d9bb6341a..eba14f6a5 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UpdateTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UpdateTests.cs @@ -9,7 +9,7 @@ namespace SampleSystem.IntegrationTests; -public class UpdateTests : TestBase +public class UpdateTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void ExampleContainer_UpdatePropertyChanged1() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs index 4b898f5cf..ac4d44ff2 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs @@ -4,7 +4,7 @@ namespace SampleSystem.IntegrationTests; -public class ValidationTests : TestBase +public class ValidationTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void ValidateByDB_ValidationException() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs index 2cc236498..29c67aa3d 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs @@ -8,7 +8,7 @@ namespace SampleSystem.IntegrationTests; -public class VirtualPermissionTests : TestBase +public class VirtualPermissionTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private (string UserLogin, Guid BuId, Guid EmployeeId)[] Datas; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WebApi/EmployeeTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WebApi/EmployeeTests.cs index a8a036393..40d3d6560 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WebApi/EmployeeTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WebApi/EmployeeTests.cs @@ -2,7 +2,7 @@ namespace SampleSystem.IntegrationTests.WebApi; -public class WebApiTests : TestBase +public class WebApiTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { [Fact] public void WebApi_CallMethod() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs index 7866012bc..c9b1cf198 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs @@ -12,7 +12,7 @@ namespace SampleSystem.IntegrationTests; -public class WrongSecurityMessageTests : TestBase +public class WrongSecurityMessageTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { private static readonly string TestPrincipalName = TextRandomizer.RandomString(10); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/InitializeAndCleanup.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/InitializeAndCleanup.cs index 0a4496d89..8e05e4e6b 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/InitializeAndCleanup.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/InitializeAndCleanup.cs @@ -1,55 +1,55 @@ -using Bss.Platform.Events.Abstractions; +//using Bss.Platform.Events.Abstractions; -using Framework.Application.Jobs; -using Framework.AutomationCore.Environment; -using Framework.AutomationCore.ServiceEnvironment; +//using Framework.Application.Jobs; +//using Framework.AutomationCore.Environment; +//using Framework.AutomationCore.ServiceEnvironment; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting.Internal; +//using Microsoft.Extensions.Configuration; +//using Microsoft.Extensions.DependencyInjection; +//using Microsoft.Extensions.Hosting.Internal; -using SampleSystem.IntegrationTests.__Support.TestData; -using SampleSystem.IntegrationTests.__Support.TestData.Helpers; -using SampleSystem.IntegrationTests.__Support.Utils; -using SampleSystem.ServiceEnvironment; -using SampleSystem.ServiceEnvironment.DependencyInjection; -using SampleSystem.ServiceEnvironment.Jobs; -using SampleSystem.WebApiCore.Controllers.Main; +//using SampleSystem.IntegrationTests.__Support.TestData; +//using SampleSystem.IntegrationTests.__Support.TestData.Helpers; +//using SampleSystem.IntegrationTests.__Support.Utils; +//using SampleSystem.ServiceEnvironment; +//using SampleSystem.ServiceEnvironment.DependencyInjection; +//using SampleSystem.ServiceEnvironment.Jobs; +//using SampleSystem.WebApiCore.Controllers.Main; -namespace SampleSystem.IntegrationTests.__Support; +//namespace SampleSystem.IntegrationTests.__Support; -public class AssemblyFixture : IAsyncLifetime -{ - public static readonly TestEnvironment TestEnvironment = new TestEnvironmentBuilder() - .WithDefaultConfiguration($"{nameof(SampleSystem)}_") - .WithDatabaseGenerator() - .WithServiceProviderBuildFunc(GetServices) - .Build(); +//public class AssemblyFixture : IAsyncLifetime +//{ +// public static readonly TestEnvironment TestEnvironment = new TestEnvironmentBuilder() +// .WithDefaultConfiguration($"{nameof(SampleSystem)}_") +// .WithDatabaseGenerator() +// .WithServiceProviderBuildFunc(GetServices) +// .Build(); - private static IServiceCollection GetServices(IConfiguration configuration, IServiceCollection services) => - services - .AddGeneralDependencyInjection(configuration, new HostingEnvironment(), s => s.AddExtensions(new SampleSystemNHibernateExtension())) +// private static IServiceCollection GetServices(IConfiguration configuration, IServiceCollection services) => +// services +// .AddGeneralDependencyInjection(configuration, new HostingEnvironment(), s => s.AddExtensions(new SampleSystemNHibernateExtension())) - .AddSingleton() +// .AddSingleton() - .AddIntegrationTests() +// .AddIntegrationTests() - .AddScoped() +// .AddScoped() - .AddSingleton(new JobImpersonateData("sampleSystemTestJob")) - .AddJobs([typeof(SampleJob).Assembly]) +// .AddSingleton(new JobImpersonateData("sampleSystemTestJob")) +// .AddJobs([typeof(SampleJob).Assembly]) - .AddTestControllers([typeof(EmployeeController).Assembly]) +// .AddTestControllers([typeof(EmployeeController).Assembly]) - .AddSingleton() +// .AddSingleton() - .AddSingleton(); +// .AddSingleton(); - public Task InitializeAsync() => TestEnvironment.AssemblyInitializeAndCleanup.EnvironmentInitializeAsync(); +// public Task InitializeAsync() => TestEnvironment.AssemblyInitializeAndCleanup.EnvironmentInitializeAsync(); - public async Task DisposeAsync() - { - await TestEnvironment.AssemblyInitializeAndCleanup.EnvironmentCleanupAsync(); - GC.SuppressFinalize(this); - } -} +// public async Task DisposeAsync() +// { +// await TestEnvironment.AssemblyInitializeAndCleanup.EnvironmentCleanupAsync(); +// GC.SuppressFinalize(this); +// } +//} diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestCollection.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestCollection.cs deleted file mode 100644 index 496c777db..000000000 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestCollection.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SampleSystem.IntegrationTests.__Support; - -[CollectionDefinition("Test Collection")] -public class TestCollection : ICollectionFixture -{ -} diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Init.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Init.cs index 49351d4d6..9880dc3c6 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Init.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Init.cs @@ -4,11 +4,13 @@ namespace SampleSystem.IntegrationTests.__Support.TestData.Helpers; -public partial class DataHelper(IServiceProvider rootServiceProvider) : RootServiceProviderContainer(rootServiceProvider) +public partial class DataHelper(IServiceProvider rootServiceProvider) : IRootServiceProviderContainer { private Guid GetGuid(Guid? id) { id = id ?? Guid.NewGuid(); return (Guid)id; } + + public IServiceProvider RootServiceProvider { get; } = rootServiceProvider; } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.cs index 90e68fe01..8263e0f5a 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.cs @@ -433,9 +433,9 @@ public CompanyLegalEntityIdentityDTO SaveCompanyLegalEntity( if (legal == null) { - CompanyLegalEntity parentDomainObject = (parent == null) - ? null - : context.Logics.CompanyLegalEntity.GetById(parent.Value.Id); + var parentDomainObject = (parent == null) + ? null + : context.Logics.CompanyLegalEntity.GetById(parent.Value.Id); legal = new CompanyLegalEntity { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/TestBase.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/TestBase.cs index f5bca4e6e..3e3408a48 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/TestBase.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/TestBase.cs @@ -1,5 +1,4 @@ -using Framework.AutomationCore; -using Framework.AutomationCore.ServiceEnvironment; +using Framework.AutomationCore.ServiceEnvironment; using Microsoft.Extensions.DependencyInjection; @@ -10,13 +9,12 @@ using Anch.SecuritySystem.Testing; +using Framework.AutomationCore.RootServiceProviderContainer; + namespace SampleSystem.IntegrationTests.__Support.TestData; -[Collection("Test Collection")] -public class TestBase : IntegrationTestBase, IDisposable +public class TestBase(IServiceProvider rootServiceProvider) : RootServiceProviderContainer(rootServiceProvider), IAsyncLifetime { - protected TestBase() : base(AssemblyFixture.TestEnvironment.ServiceProviderPool) => base.Initialize(); - public MainWebApi MainWebApi => new(this.RootServiceProvider); public MainAuditWebApi MainAuditWebApi => new(this.RootServiceProvider); @@ -25,17 +23,15 @@ public class TestBase : IntegrationTestBase, IDisposabl protected RootAuthManager AuthManager => this.RootServiceProvider.GetRequiredService(); - public void Dispose() - { - this.BeforeCleanup(); - base.Cleanup(); - } + protected ControllerEvaluator GetAuthControllerEvaluator(string? principalName = null) => + this.GetControllerEvaluator(principalName); + + protected ControllerEvaluator GetConfigurationControllerEvaluator(string? principalName = null) => + this.GetControllerEvaluator(principalName); - protected virtual void BeforeCleanup() - { - } + protected virtual ValueTask InitializeAsync(CancellationToken ct) => ValueTask.CompletedTask; - protected ControllerEvaluator GetAuthControllerEvaluator(string? principalName = null) => this.GetControllerEvaluator(principalName); + ValueTask IAsyncLifetime.InitializeAsync() => this.InitializeAsync(TestContext.Current.CancellationToken); - protected ControllerEvaluator GetConfigurationControllerEvaluator(string? principalName = null) => this.GetControllerEvaluator(principalName); + ValueTask IAsyncDisposable.DisposeAsync() => ValueTask.CompletedTask; } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Utils/SampleSystemTestDatabaseGenerator.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Utils/SampleSystemTestDatabaseGenerator.cs index 55b2b6174..2b4477c5e 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Utils/SampleSystemTestDatabaseGenerator.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Utils/SampleSystemTestDatabaseGenerator.cs @@ -1,52 +1,52 @@ -using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Utils.DatabaseUtils; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; -using Framework.Database.NHibernate.DBGenerator; - -using Microsoft.Extensions.Options; - -using SampleSystem.DbGenerate.NHibernate; -using SampleSystem.IntegrationTests.__Support.FluentMigration; -using SampleSystem.IntegrationTests.__Support.TestData; - -namespace SampleSystem.IntegrationTests.__Support.Utils; - -public class SampleSystemTestDatabaseGenerator( - IDatabaseContext databaseContext, - IOptions settings, - TestDataInitializer testDataInitializer) - : TestDatabaseGenerator(databaseContext, settings) -{ - public override IEnumerable TestServers => new List { "." }; - - public async override Task GenerateDatabasesAsync() => - new DbGeneratorTest().GenerateAllDB( - this.DatabaseContext.Main.DataSource, - mainDatabaseName: this.DatabaseContext.Main.DatabaseName, - credential: DbUserCredential.Create( - this.DatabaseContext.Main.UserId, - this.DatabaseContext.Main.Password)); - - public override async Task CheckTestDatabaseAsync() - { - if (this.DatabaseContext.Server.TableRowCount(this.DatabaseContext.Main.DatabaseName, "Location") > 100) - { - throw new Exception( - "Location row count more than 100. Please ensure that you run tests in Test Environment. If you want to run tests in the environment, please delete all Location rows (Location table) manually and rerun tests."); - } - } - - public override async Task GenerateTestDataAsync() => await testDataInitializer.InitializeAsync(default); - - public override void ExecuteInsertsForDatabases() - { - base.ExecuteInsertsForDatabases(); - - CoreDatabaseUtil.ExecuteSqlFromFolder(this.DatabaseContext.Main.ConnectionString, @"__Support/Scripts/Authorization", this.DatabaseContext.Main.DatabaseName); - CoreDatabaseUtil.ExecuteSqlFromFolder(this.DatabaseContext.Main.ConnectionString,@"__Support/Scripts/Configuration", this.DatabaseContext.Main.DatabaseName); - - CoreDatabaseUtil.ExecuteSqlFromFolder(this.DatabaseContext.Main.ConnectionString,@"__Support/Scripts/SampleSystem", this.DatabaseContext.Main.DatabaseName); - - new BssFluentMigrator(this.DatabaseContext.Main.ConnectionString, typeof(InitNumberInDomainObjectEventMigration).Assembly).Migrate(); - } -} +//using Framework.AutomationCore.Settings; +//using Framework.AutomationCore.Utils.DatabaseUtils; +//using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; +//using Framework.Database.NHibernate.DBGenerator; + +//using Microsoft.Extensions.Options; + +//using SampleSystem.DbGenerate.NHibernate; +//using SampleSystem.IntegrationTests.__Support.FluentMigration; +//using SampleSystem.IntegrationTests.__Support.TestData; + +//namespace SampleSystem.IntegrationTests.__Support.Utils; + +//public class SampleSystemTestDatabaseGenerator( +// IDatabaseContext databaseContext, +// IOptions settings, +// TestDataInitializer testDataInitializer) +// : TestDatabaseGenerator(databaseContext, settings) +//{ +// public override IEnumerable TestServers => new List { "." }; + +// public async override Task GenerateDatabasesAsync() => +// new DbGeneratorTest().GenerateAllDB( +// this.DatabaseContext.Main.DataSource, +// mainDatabaseName: this.DatabaseContext.Main.DatabaseName, +// credential: DbUserCredential.Create( +// this.DatabaseContext.Main.UserId, +// this.DatabaseContext.Main.Password)); + +// public override async Task CheckTestDatabaseAsync() +// { +// if (this.DatabaseContext.Server.TableRowCount(this.DatabaseContext.Main.DatabaseName, "Location") > 100) +// { +// throw new Exception( +// "Location row count more than 100. Please ensure that you run tests in Test Environment. If you want to run tests in the environment, please delete all Location rows (Location table) manually and rerun tests."); +// } +// } + +// public override async Task GenerateTestDataAsync() => await testDataInitializer.InitializeAsync(CancellationToken.None); + +// public override void ExecuteInsertsForDatabases() +// { +// base.ExecuteInsertsForDatabases(); + +// CoreDatabaseUtil.ExecuteSqlFromFolder(this.DatabaseContext.Main.ConnectionString, @"__Support/Scripts/Authorization", this.DatabaseContext.Main.DatabaseName); +// CoreDatabaseUtil.ExecuteSqlFromFolder(this.DatabaseContext.Main.ConnectionString,@"__Support/Scripts/Configuration", this.DatabaseContext.Main.DatabaseName); + +// CoreDatabaseUtil.ExecuteSqlFromFolder(this.DatabaseContext.Main.ConnectionString,@"__Support/Scripts/SampleSystem", this.DatabaseContext.Main.DatabaseName); + +// new BssFluentMigrator(this.DatabaseContext.Main.ConnectionString, typeof(InitNumberInDomainObjectEventMigration).Assembly).Migrate(); +// } +//} diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/SampleSystem.IntegrationTests.Xunit.NHibernate.csproj b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/SampleSystem.IntegrationTests.Xunit.NHibernate.csproj deleted file mode 100644 index 8d147849e..000000000 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/SampleSystem.IntegrationTests.Xunit.NHibernate.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - false - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - Always - - - - - - - - diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/ServiceProviderMemberDataTest.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/ServiceProviderMemberDataTest.cs deleted file mode 100644 index a43f69fe7..000000000 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/ServiceProviderMemberDataTest.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Bss.Testing.Xunit.Sdk; - -using Anch.SecuritySystem; - -using Microsoft.Extensions.DependencyInjection; - -using SampleSystem.IntegrationTests.Xunit.NHibernate.__Support; - -namespace SampleSystem.IntegrationTests.Xunit.NHibernate; - -public class ServiceProviderMemberDataTest(IServiceProvider serviceProvider) : TestBase(serviceProvider) -{ - [BssTheory] - [ServiceProviderMemberData(nameof(GetMemberData))] - public void GetDataFromServiceProvider(FullSecurityRole role) => Assert.NotNull(role.Name); - - protected IEnumerable GetMemberData() => - this.ServiceProvider.GetRequiredService().SecurityRoles.Select(x => new [] { x }); -} diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/Database/DatabaseGenerator.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/Database/DatabaseGenerator.cs deleted file mode 100644 index f3403e2c6..000000000 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/Database/DatabaseGenerator.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Utils.DatabaseUtils; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; -using Framework.Database.NHibernate.DBGenerator; - -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Options; - -using SampleSystem.DbGenerate.NHibernate; -using SampleSystem.IntegrationTests.__Support.FluentMigration; -using SampleSystem.IntegrationTests.Xunit.NHibernate.__Support.TestData; - -namespace SampleSystem.IntegrationTests.Xunit.NHibernate.__Support.Database; - -public class DatabaseGenerator( - IDatabaseContext databaseContext, - IOptions settings, - IConfiguration configuration) - : TestDatabaseGenerator(databaseContext, settings) -{ - public override IEnumerable TestServers => new List { "." }; - - public override async Task GenerateDatabasesAsync() => - new DbGeneratorTest().GenerateAllDB( - this.DatabaseContext.Main.DataSource, - mainDatabaseName: this.DatabaseContext.Main.DatabaseName, - credential: DbUserCredential.Create( - this.DatabaseContext.Main.UserId, - this.DatabaseContext.Main.Password)); - - public override async Task CheckTestDatabaseAsync() - { - if (this.DatabaseContext.Server.TableRowCount(this.DatabaseContext.Main.DatabaseName, "Location") > 100) - { - throw new Exception( - "Location row count more than 100. Please ensure that you run tests in Test Environment. If you want to run tests in the environment, please delete all Location rows (Location table) manually and rerun tests."); - } - } - - public override async Task GenerateTestDataAsync() => await new TestDataInitializer(configuration, this.DatabaseContext) - .InitializeAsync(CancellationToken.None); - public override void ExecuteInsertsForDatabases() - { - base.ExecuteInsertsForDatabases(); - - CoreDatabaseUtil.ExecuteSqlFromFolder(this.DatabaseContext.Main.ConnectionString, @"__Support/Scripts/Authorization", this.DatabaseContext.Main.DatabaseName); - CoreDatabaseUtil.ExecuteSqlFromFolder(this.DatabaseContext.Main.ConnectionString,@"__Support/Scripts/Configuration", this.DatabaseContext.Main.DatabaseName); - CoreDatabaseUtil.ExecuteSqlFromFolder(this.DatabaseContext.Main.ConnectionString,@"__Support/Scripts/SampleSystem", this.DatabaseContext.Main.DatabaseName); - - new BssFluentMigrator(this.DatabaseContext.Main.ConnectionString, typeof(InitNumberInDomainObjectEventMigration).Assembly).Migrate(); - } -} diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/EnvironmentInitializer.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/EnvironmentInitializer.cs deleted file mode 100644 index f854a8bf5..000000000 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/EnvironmentInitializer.cs +++ /dev/null @@ -1,53 +0,0 @@ -using Bss.Platform.Events.Abstractions; -using Bss.Testing.Xunit.Interfaces; - -using Anch.DependencyInjection; - -using Framework.AutomationCore.ServiceEnvironment; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; -using Framework.AutomationCore.Xunit; -using Framework.AutomationCore.Xunit.ServiceEnvironment; - -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting.Internal; - -using SampleSystem.IntegrationTests.__Support.TestData.Helpers; -using SampleSystem.IntegrationTests.__Support.Utils; -using SampleSystem.IntegrationTests.Xunit.NHibernate.__Support.Database; -using SampleSystem.IntegrationTests.Xunit.NHibernate.__Support.TestData; -using SampleSystem.ServiceEnvironment; -using SampleSystem.ServiceEnvironment.DependencyInjection; -using SampleSystem.WebApiCore.Controllers.Main; - -[assembly: CollectionBehavior(CollectionBehavior.CollectionPerClass)] -[assembly: TestFramework("Bss.Testing.Xunit.TestFramework", "Bss.Testing.Xunit")] - -namespace SampleSystem.IntegrationTests.Xunit.NHibernate.__Support; - -public class EnvironmentInitializer : AutomationCoreFrameworkInitializer -{ - public override IServiceCollection ConfigureFramework(IServiceCollection services) => - services - .AddSingleton() - .AddSingleton() - .AddSingleton( - new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json", false) - .AddEnvironmentVariables($"{nameof(SampleSystem)}_") - .Build()); - - public override IServiceProvider ConfigureTestEnvironment(IServiceCollection services, IConfiguration configuration) => - services - .AddGeneralDependencyInjection(configuration, new HostingEnvironment(), s => s.AddExtensions(new SampleSystemNHibernateExtension())) - .AddSingleton() - .AddScoped() - .AddTestControllers([typeof(EmployeeController).Assembly]) - .AddSingleton() - .AddSingleton() - .AddXunitIntegrationTests() - .AddValidator() - .Validate() - .BuildServiceProvider(new ServiceProviderOptions { ValidateOnBuild = true, ValidateScopes = true }); -} diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/TestBase.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/TestBase.cs deleted file mode 100644 index 1a10249b8..000000000 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/TestBase.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SampleSystem.IntegrationTests.Xunit.NHibernate.__Support; - -public class TestBase(IServiceProvider serviceProvider) -{ - protected IServiceProvider ServiceProvider { get; } = serviceProvider; -} diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/TestData/TestDataInitializer.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/TestData/TestDataInitializer.cs deleted file mode 100644 index aa41a2276..000000000 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/__Support/TestData/TestDataInitializer.cs +++ /dev/null @@ -1,264 +0,0 @@ -using Framework.AutomationCore.Extensions; -using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; - -using Anch.SecuritySystem; -using Anch.SecuritySystem.Services; -using Anch.SecuritySystem.Testing; - -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; - -using SampleSystem.Domain.Enums; -using SampleSystem.Domain.Inline; -using SampleSystem.IntegrationTests.__Support.TestData; -using SampleSystem.IntegrationTests.__Support.TestData.Helpers; -using SampleSystem.ServiceEnvironment; - -namespace SampleSystem.IntegrationTests.Xunit.NHibernate.__Support.TestData; - -public class TestDataInitializer -{ - private readonly IServiceProvider serviceProvider; - - private readonly DataHelper dataHelper; - - public TestDataInitializer( - IConfiguration configuration, - IDatabaseContext databaseContext) - { - var generatorConfig = configuration.BuildFromRootWithConnectionStrings(databaseContext); - - this.serviceProvider = new EnvironmentInitializer() - .ConfigureTestEnvironment( - new ServiceCollection() - .AddSingleton(databaseContext) - .AddSingleton(generatorConfig), - generatorConfig); - - this.dataHelper = this.serviceProvider.GetRequiredService(); - } - - public async Task InitializeAsync(CancellationToken cancellationToken) => - await this.serviceProvider - .GetRequiredService() - .WithImpersonateAsync( - nameof(TestDataInitializer), - async () => await this.InitializeAsyncInternal(cancellationToken)); - - public async Task InitializeAsyncInternal(CancellationToken cancellationToken) - { - await this.serviceProvider.GetRequiredService().InitializeAsync(cancellationToken); - var authManager = this.serviceProvider.GetRequiredService(); - - await authManager.For(nameof(TestDataInitializer)).SetAdminRoleAsync(cancellationToken); - await authManager.For(DefaultConstants.NOTIFICATION_ADMIN).SetRoleAsync(SecurityRole.SystemIntegration, cancellationToken); - await authManager.For(DefaultConstants.INTEGRATION_BUS).SetRoleAsync(SecurityRole.SystemIntegration, cancellationToken); - - this.FillMainData(); - - var integrationTestUserName = this.serviceProvider.GetRequiredService>() - .Value.IntegrationTestUserName; - - this.dataHelper.SaveEmployee( - id: DefaultConstants.EMPLOYEE_MY_ID, - nameEng: new Fio { FirstName = DefaultConstants.EMPLOYEE_MY_NAME, LastName = DefaultConstants.EMPLOYEE_MY_NAME }, - login: integrationTestUserName); - - await authManager.For(integrationTestUserName).SetAdminRoleAsync(cancellationToken); - } - - private void FillMainData() - { - this.dataHelper.SaveCountry( - id: DefaultConstants.COUNTRY_RUSSIA_ID, - name: DefaultConstants.COUNTRY_RUSSIA_NAME, - nativeName: DefaultConstants.COUNTRY_RUSSIA_NATIVE_NAME, - code: DefaultConstants.COUNTRY_RUSSIA_CODE, - culture: "ru-RU"); - - this.dataHelper.SaveLocation(id: DefaultConstants.LOCATION_PARENT_ID, name: DefaultConstants.LOCATION_PARENT_NAME); - - var company = this.dataHelper.SaveBusinessUnitType( - DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_ID, - DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_NAME, - isAdministrative: false, - projectStartAllowed: false, - canBeLinkedToDepartment: false, - canBeResourcePool: false, - needVertical: false); - var lob = this.dataHelper.SaveBusinessUnitType( - DefaultConstants.BUSINESS_UNIT_TYPE_LOB_ID, - DefaultConstants.BUSINESS_UNIT_TYPE_LOB_NAME, - projectStartAllowed: true, - canBeLinkedToDepartment: true, - canBeResourcePool: true, - needVertical: false); - - var businessSegment = this.dataHelper.SaveBusinessUnitType( - DefaultConstants.BUSINESS_UNIT_TYPE_BUSINESS_SEGMENT_ID, - DefaultConstants.BUSINESS_UNIT_TYPE_BUSINESS_SEGMENT_NAME, - possibleStartDate: PossibleStartDate.FinYearStart, - isAdministrative: false, - canBeResourcePool: true, - projectStartAllowed: true, - billProjectAreNotAllowed: false, - startBOConfirm: true, - possibleTransferDate: PossibleStartDate.FinYearStart, - transferBOConfirm: true, - needVertical: false, - canBeIsCommission: false, - canBeNewBusiness: false, - possibleParents: [company]); - - var account = this.dataHelper.SaveBusinessUnitType( - DefaultConstants.BUSINESS_UNIT_TYPE_ACCOUNT_ID, - DefaultConstants.BUSINESS_UNIT_TYPE_ACCOUNT_NAME, - possibleStartDate: PossibleStartDate.AnyDay, - isAdministrative: false, - canBeResourcePool: true, - projectStartAllowed: true, - billProjectAreNotAllowed: false, - startBOConfirm: true, - possibleTransferDate: PossibleStartDate.AnyDay, - transferBOConfirm: true, - needVertical: true, - canBeIsCommission: false, - canBeNewBusiness: true, - possibleFinancialProjectTypes: - [ - FinancialProjectType.Commercial, FinancialProjectType.Administrative, - FinancialProjectType.Investment, FinancialProjectType.RnD - ], - possibleParents: [businessSegment, lob, company], - transferTo: [businessSegment, lob, company]); - - this.dataHelper.SaveBusinessUnitType( - DefaultConstants.BUSINESS_UNIT_TYPE_ADMIN_COMMERCIAL_ID, - DefaultConstants.BUSINESS_UNIT_TYPE_ADMIN_COMMERCIAL_NAME, - projectStartAllowed: true, - canBeLinkedToDepartment: true, - canBeResourcePool: true, - needVertical: false); - this.dataHelper.SaveBusinessUnitType( - DefaultConstants.BUSINESS_UNIT_TYPE_ADMIN_SERVICES_ID, - DefaultConstants.BUSINESS_UNIT_TYPE_ADMIN_SERVICES_NAME, - projectStartAllowed: true, - canBeLinkedToDepartment: true, - canBeResourcePool: true, - needVertical: false); - this.dataHelper.SaveBusinessUnitType( - DefaultConstants.BUSINESS_UNIT_TYPE_DIVISION_ID, - DefaultConstants.BUSINESS_UNIT_TYPE_DIVISION_NAME, - projectStartAllowed: true, - canBeLinkedToDepartment: true, - canBeResourcePool: true, - needVertical: false, - possibleParents: [company, account]); - - this.dataHelper.SaveBusinessUnitType( - DefaultConstants.BUSINESS_UNIT_TYPE_NEW_BUSINESS_ID, - DefaultConstants.BUSINESS_UNIT_TYPE_NEW_BUSINESS_NAME, - projectStartAllowed: true, - canBeLinkedToDepartment: true, - canBeResourcePool: true, - needVertical: true, - possibleParents: [company, account, businessSegment]); - - this.dataHelper.SaveBusinessUnitType( - DefaultConstants.BUSINESS_UNIT_TYPE_SERVICE_ID, - DefaultConstants.BUSINESS_UNIT_TYPE_SERVICE_NAME, - projectStartAllowed: true, - canBeLinkedToDepartment: true, - canBeResourcePool: true, - needVertical: false); - this.dataHelper.SaveBusinessUnitType( - DefaultConstants.BUSINESS_UNIT_TYPE_SE_ADMINISTRATIVE_ID, - DefaultConstants.BUSINESS_UNIT_TYPE_SE_ADMINISTRATIVE_NAME, - projectStartAllowed: true, - canBeLinkedToDepartment: true, - canBeResourcePool: true, - needVertical: false); - var seDivision = this.dataHelper.SaveBusinessUnitType( - DefaultConstants.BUSINESS_UNIT_TYPE_SE_DIVISION_ID, - DefaultConstants.BUSINESS_UNIT_TYPE_SE_DIVISION_NAME, - possibleStartDate: PossibleStartDate.AnyDay, - isAdministrative: false, - canBeResourcePool: false, - projectStartAllowed: false, - billProjectAreNotAllowed: false, - startBOConfirm: true, - possibleTransferDate: PossibleStartDate.FinYearStart, - transferBOConfirm: true, - needVertical: false, - canBeIsCommission: false, - canBeNewBusiness: false, - possibleParents: [account], - transferTo: [account]); - this.dataHelper.SaveBusinessUnitType( - DefaultConstants.BUSINESS_UNIT_TYPE_SE_SUB_DIVISION_ID, - DefaultConstants.BUSINESS_UNIT_TYPE_SE_SE_SUB_DIVISION_NAME, - projectStartAllowed: true, - canBeLinkedToDepartment: true, - canBeResourcePool: true, - needVertical: false); - this.dataHelper.SaveBusinessUnitType( - DefaultConstants.BUSINESS_UNIT_TYPE_PRACTICE_ID, - DefaultConstants.BUSINESS_UNIT_TYPE_PRACTICE_NAME, - projectStartAllowed: true, - canBeLinkedToDepartment: true, - canBeResourcePool: true, - needVertical: false); - - this.dataHelper.SaveBusinessUnitType( - DefaultConstants.BUSINESS_UNIT_TYPE_PROGRAM_ID, - DefaultConstants.BUSINESS_UNIT_TYPE_PROGRAM_NAME, - currentTypeInPossibleParents: true, - currentTypeInTransferTo: true, - possibleStartDate: PossibleStartDate.AnyDay, - isAdministrative: false, - canBeResourcePool: true, - projectStartAllowed: true, - billProjectAreNotAllowed: false, - startBOConfirm: true, - possibleTransferDate: PossibleStartDate.AnyDay, - transferBOConfirm: true, - needVertical: false, - canBeIsCommission: true, - canBeNewBusiness: false, - possibleParents: [account, seDivision, businessSegment], - possibleFinancialProjectTypes: - [ - FinancialProjectType.Commercial, FinancialProjectType.Administrative, - FinancialProjectType.Investment, FinancialProjectType.RnD - ], - transferTo: [account, seDivision]); - - this.dataHelper.SaveEmployeePosition( - DefaultConstants.EMPLOYEE_POSITION_TESTER_ID, - DefaultConstants.EMPLOYEE_POSITION_TESTER_NAME); - - this.dataHelper.SaveEmployeeRegistrationType( - DefaultConstants.EMPLOYEE_REGISTRATION_TYPE_STAFF_ID, - DefaultConstants.EMPLOYEE_REGISTRATION_TYPE_STAFF_NAME); - - this.dataHelper.SaveEmployeeRole( - DefaultConstants.EMPLOYEE_ROLE_TESTER_ID, - DefaultConstants.EMPLOYEE_ROLE_TESTER_NAME); - - this.dataHelper.SaveEmployeeRoleDegree( - DefaultConstants.EMPLOYEE_ROLE_DEGREE_REGULAR_ID, - DefaultConstants.EMPLOYEE_ROLE_DEGREE_REGULAR_NAME); - - this.dataHelper.SaveCompanyLegalEntity( - DefaultConstants.COMPANY_LEGAL_ENTITY_ID, - DefaultConstants.COMPANY_LEGAL_ENTITY_NAME); - - this.dataHelper.SaveEmployee(DefaultConstants.HRDepartment_DEFAULT_HEAD_EMPLOYEE_ID, login: "Default_HRDepartment_HEAD", isObjectRequired: false); - - this.dataHelper.SaveHRDepartment( - DefaultConstants.HRDEPARTMENT_PARENT_ID, - DefaultConstants.HRDEPARTMENT_PARENT_NAME); - } -} diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/appsettings.json b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/appsettings.json deleted file mode 100644 index c401e876f..000000000 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.Xunit.NHibernate/appsettings.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "AutomationFrameworkSettings": { - "TestRunServerRootFolder": "/var/opt/mssql/" - }, - - "ConnectionStrings": { - "DefaultConnection": "Data Source=.;Initial Catalog=SampleSystem;User Id=sa;Password=P@ssw0rd;Application Name=SampleSystem;TrustServerCertificate=True", - "WorkflowCoreConnection": "Data Source=.;Initial Catalog=SampleSystem;User Id=sa;Password=P@ssw0rd;Application Name=SampleSystem;TrustServerCertificate=True" - }, - - "Hangfire": { - "ConnectionString": "Server=localhost;Initial Catalog=Jobs;User Id=sa;Password=P@ssw0rd;", - "Jobs": { - "TaskReview": { - "Hour": 1, - "Minutes": 0, - "Period": 1 - } - } - } -} diff --git a/src/_SampleSystem/_Tests/SampleSystem.UnitTests/SampleSystem.UnitTests.csproj b/src/_SampleSystem/_Tests/SampleSystem.UnitTests/SampleSystem.UnitTests.csproj index 4035aeae1..45caffdf6 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.UnitTests/SampleSystem.UnitTests.csproj +++ b/src/_SampleSystem/_Tests/SampleSystem.UnitTests/SampleSystem.UnitTests.csproj @@ -6,7 +6,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 5d0615ff020b2c581dd004b1084232c936d01651 Mon Sep 17 00:00:00 2001 From: iatsuta Date: Mon, 27 Apr 2026 18:21:51 +0200 Subject: [PATCH 02/13] upd --- src/.editorconfig | 2 +- .../Framework.AutomationCore.csproj | 3 + .../RootServiceProviderContainerExtensions.cs | 12 +- .../DatabaseUtils/CoreDatabaseUtil.Helper.cs | 47 +++ .../Utils/DatabaseUtils/CoreDatabaseUtil.cs | 317 ++++++++++++++++++ .../Utils/DatabaseUtils/DatabaseContext.cs | 96 ++++++ .../Utils/DatabaseUtils/DatabaseItem.cs | 74 ++++ .../Interfaces/IDatabaseContext.cs | 12 + .../DatabaseUtils/Interfaces/IDatabaseItem.cs | 12 + .../Interfaces/ITestDatabaseGenerator.cs | 28 ++ .../DatabaseUtils/TestDatabaseGenerator.cs | 92 +++++ .../Utils/TextRandomizer.cs | 23 ++ .../MetadataReader.cs | 2 +- .../AuthPerfomanceTest.cs | 10 +- .../AuthPerformanceTests.cs | 2 +- .../BusinessUnitTests.cs | 86 ++--- .../CurrentUserManyRelativePathTests.cs | 8 +- .../CurrentUserSingleRelativePathTests.cs | 2 +- .../ChangeIndexesStrategyTests.cs | 9 +- .../DBGeneration/GenerateDBTests.cs | 3 +- .../DBGeneration/SchemeUpdateTests.cs | 4 +- ...UniqueGroupDatabaseScriptGeneratorTests.cs | 7 +- .../DependencySecurityTests.cs | 4 +- .../EmployeeProjectionTests.cs | 11 +- .../EmployeeTests.cs | 2 + .../ExpandPathTests.cs | 1 + .../ExtraQueryableSecurityPathTests.cs | 11 +- ...ionPrincipalsByHierarchicalContextTests.cs | 2 +- .../JsonConverterTests.cs | 1 + .../ManualAndLegacyProjectionSecurityTests.cs | 4 +- .../PrincipalWithInitTests.cs | 9 +- .../SecurityContextRestrictionFilterTests.cs | 2 +- .../MetadataSubscriptionSystemServiceTests.cs | 5 +- .../VirtualPermissionTests.cs | 2 +- .../WrongSecurityMessageTests.cs | 3 +- .../TestData/Helpers/DataHelper.Smo.cs | 4 +- 36 files changed, 816 insertions(+), 96 deletions(-) create mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.Helper.cs create mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.cs create mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs create mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseItem.cs create mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseContext.cs create mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseItem.cs create mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/ITestDatabaseGenerator.cs create mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/TestDatabaseGenerator.cs create mode 100644 src/AutomationCore/Framework.AutomationCore/Utils/TextRandomizer.cs diff --git a/src/.editorconfig b/src/.editorconfig index dcf65efd1..ee1c896a8 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -10,7 +10,7 @@ indent_style = space charset = utf-8-bom trim_trailing_whitespace = true insert_final_newline = true -max_line_length = 180 +max_line_length = 160 # Microsoft .NET properties csharp_preserve_single_line_blocks = true diff --git a/src/AutomationCore/Framework.AutomationCore/Framework.AutomationCore.csproj b/src/AutomationCore/Framework.AutomationCore/Framework.AutomationCore.csproj index ca0628a4d..fa36f90bf 100644 --- a/src/AutomationCore/Framework.AutomationCore/Framework.AutomationCore.csproj +++ b/src/AutomationCore/Framework.AutomationCore/Framework.AutomationCore.csproj @@ -11,6 +11,9 @@ + + + diff --git a/src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/RootServiceProviderContainerExtensions.cs b/src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/RootServiceProviderContainerExtensions.cs index 5682b84db..6b2ea9c33 100644 --- a/src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/RootServiceProviderContainerExtensions.cs +++ b/src/AutomationCore/Framework.AutomationCore/RootServiceProviderContainer/RootServiceProviderContainerExtensions.cs @@ -1,11 +1,10 @@ using System.Linq.Expressions; -using Anch.SecuritySystem; - using Framework.Application.FinancialYear; -using Framework.AutomationCore.ServiceEnvironment; using Framework.AutomationCore.ServiceEnvironment.Services; using Framework.AutomationCore.Settings; +using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; + //using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; using Microsoft.AspNetCore.Mvc; @@ -18,18 +17,13 @@ public static class RootServiceProviderContainerExtensions { extension(IRootServiceProviderContainer rootServiceProviderContainer) { - //public IDatabaseContext GetDatabaseContext() => rootServiceProviderContainer.RootServiceProvider.GetRequiredService(); - - - public AutomationFrameworkSettings AutomationFrameworkSettings => rootServiceProviderContainer.RootServiceProvider.GetRequiredService>().Value; public TimeProvider TimeProvider => rootServiceProviderContainer.RootServiceProvider.GetRequiredService(); public IFinancialYearService FinancialYearService => rootServiceProviderContainer.RootServiceProvider.GetRequiredService(); - //public IDatabaseContext DatabaseContext => this.GetDatabaseContext(); - + public IDatabaseContext DatabaseContext => rootServiceProviderContainer.RootServiceProvider.GetRequiredService(); public void SetCurrentDateTime(DateTime newDateTime) => rootServiceProviderContainer.RootServiceProvider.GetRequiredService().SetCurrentDateTime(newDateTime); diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.Helper.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.Helper.cs new file mode 100644 index 000000000..13e2e0df3 --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.Helper.cs @@ -0,0 +1,47 @@ +using System.Text.RegularExpressions; + +using Microsoft.SqlServer.Management.Smo; + +namespace Framework.AutomationCore.Utils.DatabaseUtils; + +public static partial class CoreDatabaseUtil +{ + private static readonly Regex InitialCatalogRegex = new("Initial Catalog=(\\w+);", RegexOptions.Compiled); + + public static string CutInitialCatalog(string inputConnectionString) => + InitialCatalogRegex.Replace(inputConnectionString,""); + + private static string GetInitialCatalog(string connectionString) => + InitialCatalogRegex.Matches(connectionString).First().Value; + + private static Table GetTable(this Server server, string databaseName, string tableName) + { + var database = server.GetDatabase(databaseName); + + return database?.Tables[tableName]; + } + + public static long TableRowCount(this Server server, string databaseName, string tableName) => server.GetTable(databaseName, tableName)?.RowCount ?? 0; + + private static void SetModeRestrictedUser(this Server server, string databaseName) + { + if (server.GetDatabase(databaseName) == null) + { + return; + } + + try + { + server.KillAllProcesses(databaseName); + } + catch (FailedOperationException) + { + ExecuteSql(server.ConnectionContext.SqlConnectionObject,$"ALTER DATABASE [{databaseName}] SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE"); + } + } + + private static void SetModeMultiUser(this Server server, Microsoft.SqlServer.Management.Smo.Database database) + => ExecuteSql(server.ConnectionContext.SqlConnectionObject, $"ALTER DATABASE [{database.Name}] SET MULTI_USER"); + + private static Microsoft.SqlServer.Management.Smo.Database GetDatabase(this Server server, string name) => server.Databases.Contains(name) ? server.Databases[name] : null; +} diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.cs new file mode 100644 index 000000000..47737d9df --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.cs @@ -0,0 +1,317 @@ +using System.Collections.Specialized; +using System.Data; +using System.Text.RegularExpressions; + +using Anch.Core; + +using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; + +using MartinCostello.SqlLocalDb; + +using Microsoft.Data.SqlClient; +using Microsoft.SqlServer.Management.Smo; + +namespace Framework.AutomationCore.Utils.DatabaseUtils; + +public static partial class CoreDatabaseUtil +{ + public static void ExecuteSqlFromFolder(string connectionString, string folder, string? initialCatalog = null) + { + string[] filePaths; + + if (!Directory.Exists(folder)) + { + Console.WriteLine("No directory found for path: {0}", folder); + return; + } + + try + { + filePaths = Directory.GetFiles(folder); + } + catch (Exception) + { + return; + } + + var builder = new SqlConnectionStringBuilder(connectionString); + + if (initialCatalog != null) + { + builder.InitialCatalog = initialCatalog; + } + + ExecuteSqlScripts(filePaths, builder); + } + + private static void ExecuteSqlScripts(string[] sqlPaths, SqlConnectionStringBuilder connectionBuilder) + { + using (var connection = new SqlConnection(connectionBuilder.ConnectionString)) + { + connection.Open(); + + ExecuteSql(connection, "EXEC sp_msforeachtable \"ALTER TABLE ? NOCHECK CONSTRAINT all\""); + + foreach (var filePath in sqlPaths) + { + try + { + ExecuteSql(connection, filePath); + } + catch (Exception ex) + { + Console.WriteLine(filePath); + + Console.WriteLine(ex.Message); + Console.WriteLine(); + Console.WriteLine(ex.StackTrace); + Console.WriteLine(); + Console.WriteLine(); + throw new Exception($"file: {filePath}: ", ex); + } + } + + ExecuteSql(connection, "exec sp_msforeachtable \"ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all\""); + connection.Close(); + } + } + + public static void ExecuteSql(SqlConnection connection, string sqlFileOrText) + { + string sql; + + if (sqlFileOrText.EndsWith(".sql", StringComparison.InvariantCultureIgnoreCase)) + { + using (var stream = File.OpenRead(sqlFileOrText)) + { + var reader = new StreamReader(stream); + sql = reader.ReadToEnd(); + } + } + else + { + sql = sqlFileOrText; + } + + var regex = new Regex("^GO(\r\n|\n|\r)", RegexOptions.Multiline | RegexOptions.IgnoreCase); + string[] lines = regex.Split(sql).Select(z => z.Replace("$Database", connection.Database)).ToArray(); + + using (var cmd = connection.CreateCommand()) + { + cmd.Connection = connection; + + foreach (var line in lines) + { + if (line.Length > 0) + { + cmd.CommandText = line; + cmd.CommandType = CommandType.Text; + cmd.CommandTimeout = 30; + + cmd.ExecuteNonQuery(); + } + } + } + } + + public static void ExecuteSql(string connectionString, string sqlFileOrText, string? initialCatalog = null) + { + var builder = new SqlConnectionStringBuilder(connectionString); + + if (initialCatalog != null) + { + builder.InitialCatalog = initialCatalog; + } + + using (var connection = new SqlConnection(builder.ConnectionString)) + { + connection.Open(); + + ExecuteSql(connection, sqlFileOrText); + connection.Close(); + } + } + + public static void Drop(this IDatabaseContext databaseContext) + { + Drop(databaseContext.Server, databaseContext.Main.DatabaseName); + databaseContext.Secondary?.Foreach(x => Drop(databaseContext.Server, x.Value.DatabaseName)); + } + + private static void Drop(Server server, string databaseName) + { + var database = server.GetDatabase(databaseName); + + if (database == null) + { + return; + } + + server.Drop(database); + } + + + public static void Drop(this Server server, Microsoft.SqlServer.Management.Smo.Database database) + { + try + { + server.SetModeRestrictedUser(database.Name); + database.Drop(); + } + catch (FailedOperationException) + { + try + { + server.KillDatabase(database.Name); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + catch (Exception ex) + { + server.SetModeMultiUser(database); + Console.WriteLine(ex.Message); + } + } + + public static void ReCreate(this IDatabaseContext databaseContext) + { + databaseContext.Drop(); + databaseContext.Create(); + } + + public static void Create(this IDatabaseContext databaseContext) + { + Create(databaseContext.Server, databaseContext.Main); + databaseContext.Secondary?.Foreach(x => Create(databaseContext.Server, x.Value)); + } + + private static void Create(Server server, IDatabaseItem database) + { + var db = new Microsoft.SqlServer.Management.Smo.Database(server, database.DatabaseName); + if (!string.IsNullOrEmpty(database.DatabaseCollation)) + { + db.Collation = database.DatabaseCollation; + } + + CheckDirectoryAndCreateIfNotExists(database.DbDataDirectory); + + var fileGroup = new FileGroup(db, "PRIMARY"); + + var dataFile = new DataFile( + fileGroup, + database.DatabaseName, + database.SourceDataPath) + { + Size = 5.5 * 1024.0, GrowthType = FileGrowthType.KB, Growth = 1.0 * 1024.0 + }; + + fileGroup.Files.Add(dataFile); + + db.FileGroups.Add(fileGroup); + + var logFile = new LogFile( + db, + database.DatabaseName + "_log", + database.SourceLogPath) + { + Size = 1.0 * 1024.0, GrowthType = FileGrowthType.Percent, Growth = 10.0 + }; + + db.LogFiles.Add(logFile); + + db.Create(); + + server.Refresh(); + } + + public static void CopyDetachedFiles(this IDatabaseContext databaseContext) + { + CopyDetachedFiles(databaseContext.Server, databaseContext.Main); + databaseContext.Secondary?.Foreach(x => CopyDetachedFiles(databaseContext.Server, x.Value)); + } + + private static void CopyDetachedFiles(Server server, DatabaseItem database) + { + server.DetachDatabase(database.DatabaseName); + CheckDirectoryAndCreateIfNotExists(database.DbDataDirectory); + + new FileInfo(database.SourceDataPath).MoveTo(database.CopyDataPath, true); + new FileInfo(database.SourceLogPath).MoveTo(database.CopyLogPath, true); + } + + public static void AttachDatabase(this IDatabaseContext databaseContext) + { + AttachDatabase(databaseContext.Server, databaseContext.Main); + databaseContext.Secondary?.Foreach(x => AttachDatabase(databaseContext.Server, x.Value)); + } + + private static void AttachDatabase(Server server, IDatabaseItem database) + { + new FileInfo(database.CopyDataPath).CopyTo(database.SourceDataPath, true); + new FileInfo(database.CopyLogPath).CopyTo(database.SourceLogPath, true); + + server.AttachDatabase(database.DatabaseName, new StringCollection { database.SourceDataPath, database.SourceLogPath }); + } + + public static void DetachDatabase(this Server server, string databaseName) + { + server.SetModeRestrictedUser(databaseName); + + server.DetachDatabase(databaseName, false); + } + + public static void CreateLocalDb(string instanceName) + { + using (var localDb = new SqlLocalDbApi()) + { + var instanceInfo = localDb.GetInstanceInfo(instanceName); + localDb.AutomaticallyDeleteInstanceFiles = true; + + if (!instanceInfo.Exists) + { + localDb.CreateInstance(instanceInfo.Name); + } + + if (!instanceInfo.IsRunning) + { + localDb.StartInstance(instanceInfo.Name); + } + } + } + + public static void DeleteLocalDb(string instanceName, StopInstanceOptions stopOptions = StopInstanceOptions.KillProcess) + { + using (var localDb = new SqlLocalDbApi()) + { + var instanceInfo = localDb.GetInstanceInfo(instanceName); + + if (instanceInfo.IsRunning) + { + localDb.StopInstance(instanceInfo.Name, stopOptions, TimeSpan.FromSeconds(1)); + } + + localDb.DeleteInstance(instanceName); + } + } + + public static bool LocalDbInstanceExists(string instanceName) + { + using (var localDbApi = new SqlLocalDbApi()) + { + var instanceInfo = localDbApi.GetInstanceInfo(instanceName); + + return instanceInfo.Exists; + } + } + + private static void CheckDirectoryAndCreateIfNotExists(string path) + { + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path!); + } + } +} diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs new file mode 100644 index 000000000..aefdfb771 --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs @@ -0,0 +1,96 @@ +using System.Text.RegularExpressions; + +using Framework.AutomationCore.Settings; +using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; + +using Microsoft.Data.SqlClient; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; +using Microsoft.SqlServer.Management.Common; +using Microsoft.SqlServer.Management.Smo; + +namespace Framework.AutomationCore.Utils.DatabaseUtils; + +public class DatabaseContext : IDatabaseContext +{ + static DatabaseContext() => + LocalDbInstanceName = $"Test_{TextRandomizer.RandomString(10)}"; + + private static readonly string LocalDbInstanceName; + + public DatabaseItem Main { get; } + + private readonly Server server; + + public Dictionary Secondary { get; } + + public DatabaseContext( + IConfiguration configuration, + IOptions settings) + : this(configuration, settings.Value) + { + } + + private DatabaseContext( + IConfiguration configuration, + AutomationFrameworkSettings settings) + { + var connectionString = this.GetConnectionString(configuration, settings); + + this.Main = new DatabaseItem( + connectionString, + settings.DatabaseCollation, + settings.DbDataDirectory, + null, + settings.TestsParallelize); + + if (settings.SecondaryDatabases != null) + { + this.Secondary = new Dictionary(); + foreach (var database in settings.SecondaryDatabases) + { + this.Secondary.Add( + database, + new DatabaseItem( + connectionString, + settings.DatabaseCollation, + settings.DbDataDirectory, + database, + settings.TestsParallelize)); + } + } + + this.server = new Server(new ServerConnection(new SqlConnection( + CoreDatabaseUtil.CutInitialCatalog(this.Main.ConnectionString)))); + } + + public Server Server + { + get + { + this.server.Refresh(); + return this.server; + } + } + + private string GetConnectionString( + IConfiguration configuration, + AutomationFrameworkSettings settings) + { + var connectionString = configuration.GetConnectionString(settings.ConnectionStringName); + + if (settings.UseLocalDb) + { + connectionString = this.GetLocalDbConnectionString(connectionString, LocalDbInstanceName); + } + + return connectionString; + } + + private string GetLocalDbConnectionString(string connectionString, string instanceName) + => DataSourceRegex.Replace(connectionString, $"Data Source=(localdb)\\{instanceName}"); + + private static readonly Regex DataSourceRegex = new("Data Source=([^;]*)", RegexOptions.Compiled | RegexOptions.NonBacktracking); +} + + diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseItem.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseItem.cs new file mode 100644 index 000000000..def25cdc1 --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseItem.cs @@ -0,0 +1,74 @@ +using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; + +using Microsoft.Data.SqlClient; + +namespace Framework.AutomationCore.Utils.DatabaseUtils; + +public class DatabaseItem : IDatabaseItem +{ + private readonly SqlConnectionStringBuilder builder; + + public DatabaseItem( + string connectionString, + string databaseCollation, + string dbDataDirectory, + string? initialCatalog = null, + bool randomizeDatabaseName = false) + { + this.DbDataDirectory = dbDataDirectory; + this.builder = new SqlConnectionStringBuilder(connectionString); + initialCatalog ??= this.builder.InitialCatalog; + this.DatabaseName = randomizeDatabaseName + ? $"{initialCatalog}{TextRandomizer.RandomString(5)}" + : initialCatalog; + + var fileName = $"{this.InstanceName}_{this.DatabaseName}_{TextRandomizer.RandomString(5)}"; + + this.CopyDataPath = this.ToCopyDataPath(initialCatalog); + this.CopyLogPath = this.ToCopyLogPath(initialCatalog); + this.SourceDataPath = this.ToSourceDataPath(fileName); + this.SourceLogPath = this.ToSourceLogPath(fileName); + this.DatabaseCollation = databaseCollation; + this.builder.InitialCatalog = this.DatabaseName; + } + + public string DataSource => this.builder.DataSource; + + public string InitialCatalog => this.builder.InitialCatalog; + + public string UserId => this.builder.UserID; + + public string Password => this.builder.Password; + + public bool IntegratedSecurity => this.builder.IntegratedSecurity; + + public string ConnectionString => this.builder.ConnectionString; + + public string InstanceName => this.builder.DataSource.Split('\\').LastOrDefault(); + + public string DatabaseName { get; } + public string DbDataDirectory { get; } + public string CopyDataPath { get; } + public string CopyLogPath { get; } + public string SourceDataPath { get; } + public string SourceLogPath { get; } + public string DatabaseCollation { get; } + + private string ToSourceDataPath(string fileName) => this.ToWorkPath(SourceDataFile(fileName)); + + private string ToSourceLogPath(string fileName) => this.ToWorkPath(SourceLogFile(fileName)); + + private string ToCopyDataPath(string initialCatalog) => this.ToWorkPath(this.CopyDataFile(initialCatalog)); + + private string ToCopyLogPath(string initialCatalog) => this.ToWorkPath(this.CopyLogFile(initialCatalog)); + + private string CopyDataFile(string initialCatalog) =>$"{System.Environment.UserName}_{initialCatalog}.mdf"; + + private string CopyLogFile(string initialCatalog) => $"{System.Environment.UserName}_{initialCatalog}_log.ldf"; + + private static string SourceDataFile(string fileName) => $"{fileName}.mdf"; + + private static string SourceLogFile(string fileName) => $"{fileName}_log.ldf"; + + private string ToWorkPath(string fileName) => Path.Combine(this.DbDataDirectory, fileName); +} diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseContext.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseContext.cs new file mode 100644 index 000000000..6e2f61640 --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseContext.cs @@ -0,0 +1,12 @@ +using Microsoft.SqlServer.Management.Smo; + +namespace Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; + +public interface IDatabaseContext +{ + public DatabaseItem Main { get; } + + public Dictionary Secondary { get; } + + public Server Server { get; } +} diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseItem.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseItem.cs new file mode 100644 index 000000000..cae555a76 --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/IDatabaseItem.cs @@ -0,0 +1,12 @@ +namespace Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; + +public interface IDatabaseItem +{ + public string DatabaseName { get; } + public string DbDataDirectory { get; } + public string CopyDataPath { get; } + public string CopyLogPath { get; } + public string SourceDataPath { get; } + public string SourceLogPath { get; } + public string DatabaseCollation { get; } +} diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/ITestDatabaseGenerator.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/ITestDatabaseGenerator.cs new file mode 100644 index 000000000..e9faf1c6e --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/Interfaces/ITestDatabaseGenerator.cs @@ -0,0 +1,28 @@ +namespace Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; + +public interface ITestDatabaseGenerator +{ + IEnumerable TestServers { get; } + + IDatabaseContext DatabaseContext { get; } + + void CreateLocalDb(); + + void DeleteLocalDb(); + + void DropAllDatabases(); + + void ExecuteInsertsForDatabases(); + + Task GenerateDatabasesAsync(); + + void DeleteDetachedFiles(); + + Task CheckAndCreateDetachedFilesAsync(); + + Task CheckTestDatabaseAsync(); + + void CheckServerAllowed(); + + Task GenerateTestDataAsync(); +} diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/TestDatabaseGenerator.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/TestDatabaseGenerator.cs new file mode 100644 index 000000000..b8e7c7cf4 --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/TestDatabaseGenerator.cs @@ -0,0 +1,92 @@ +using Framework.AutomationCore.Settings; +using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; + +using Microsoft.Extensions.Options; + +namespace Framework.AutomationCore.Utils.DatabaseUtils; + +public abstract class TestDatabaseGenerator( + IDatabaseContext databaseContext, + IOptions settings) : ITestDatabaseGenerator +{ + public virtual IEnumerable TestServers => []; + + public IDatabaseContext DatabaseContext { get; } = databaseContext; + + private readonly AutomationFrameworkSettings settings = settings.Value; + + public void CreateLocalDb() + { + if (this.settings.UseLocalDb && !CoreDatabaseUtil.LocalDbInstanceExists(this.DatabaseContext.Main.InstanceName)) + { + CoreDatabaseUtil.CreateLocalDb(this.DatabaseContext.Main.InstanceName); + } + } + + public virtual void DeleteLocalDb() + { + if (this.settings.UseLocalDb) + { + CoreDatabaseUtil.DeleteLocalDb(this.DatabaseContext.Main.InstanceName); + } + } + + public virtual void DropAllDatabases() => + this.DatabaseContext.Server.Databases + .Where(x => x.Name.Equals(this.DatabaseContext.Main.InitialCatalog)) + .ToList() + .ForEach(x => x.Drop()); + + public virtual void ExecuteInsertsForDatabases() => + CoreDatabaseUtil.ExecuteSqlFromFolder( + this.DatabaseContext.Main.ConnectionString, + @"__Support\Scripts", + this.DatabaseContext.Main.DatabaseName); + + public void DeleteDetachedFiles() + { + if (!Directory.Exists(this.settings.DbDataDirectory)) + { + return; + } + + Directory.GetFiles(this.settings.DbDataDirectory) + .Where(i => i.Contains(this.DatabaseContext.Main.InstanceName)) + .ToList() + .ForEach(File.Delete); + } + + public virtual void CheckServerAllowed() + { + if (this.DatabaseContext.Server.NetName.Equals(System.Environment.MachineName, StringComparison.InvariantCultureIgnoreCase)) + { + return; + } + + if (!this.TestServers.Select(s => s.ToUpper()) + .ToList() + .Contains(this.DatabaseContext.Server.NetName.ToUpper())) + { + throw new Exception( + $"Server name {this.DatabaseContext.Server.NetName} is not specified in allowed list of test servers: {string.Join(", ", this.TestServers.Select(s => s.ToUpper()).ToList())}"); + } + } + + public async Task CheckAndCreateDetachedFilesAsync() + { + if (!new FileInfo(this.DatabaseContext.Main.CopyDataPath).Exists) + { + this.DatabaseContext.ReCreate(); + await this.GenerateDatabasesAsync(); + this.ExecuteInsertsForDatabases(); + await this.GenerateTestDataAsync(); + this.DatabaseContext.CopyDetachedFiles(); + } + } + + public abstract Task GenerateDatabasesAsync(); + + public abstract Task GenerateTestDataAsync(); + + public virtual Task CheckTestDatabaseAsync() => Task.CompletedTask; +} diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/TextRandomizer.cs b/src/AutomationCore/Framework.AutomationCore/Utils/TextRandomizer.cs new file mode 100644 index 000000000..35d35b5ac --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore/Utils/TextRandomizer.cs @@ -0,0 +1,23 @@ +using System.Text; + +namespace Framework.AutomationCore.Utils; + +public static class TextRandomizer +{ + public static string UniqueString(string startsWith = "") => $"{startsWith}{Random.Shared.Next(1000000, 9999999)}"; + + public static string RandomString(string startsWith, int size) => $"{startsWith}{RandomString(size - startsWith.Length)}"; + + public static string RandomString(int size) + { + var builder = new StringBuilder(); + + for (var i = 0; i < size; i++) + { + var ch = Convert.ToChar(Convert.ToInt32(Math.Floor((26 * Random.Shared.NextDouble()) + 65))); + builder.Append(ch); + } + + return builder.ToString(); + } +} diff --git a/src/Database/Framework.Database.Metadata/MetadataReader.cs b/src/Database/Framework.Database.Metadata/MetadataReader.cs index 6aa75179f..b4e2e1664 100644 --- a/src/Database/Framework.Database.Metadata/MetadataReader.cs +++ b/src/Database/Framework.Database.Metadata/MetadataReader.cs @@ -77,7 +77,7 @@ public static class MetadataReader return null; } var result = f.FieldType.IsDomainType(d.AssemblyMetadata.PersistentDomainObjectBaseType) - ? new ReferenceTypeFieldMetadata(f.Name, f.FieldType, f.GetAttributes(d.DomainType).Cast(), d) : null; + ? new ReferenceTypeFieldMetadata(f.Name, f.FieldType, f.GetAttributes(d.DomainType), d) : null; return result; }; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs index d03532fa1..97cfeae90 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs @@ -31,7 +31,7 @@ public class AuthPerformanceTest(IServiceProvider rootServiceProvider) : TestBas private static readonly int Size = 5; - public AuthPerformanceTest() + protected override async ValueTask InitializeAsync(CancellationToken ct) { this.fbuSource = [null, .. Enumerable.Range(0, Size - 1).Select(_ => (BusinessUnitIdentityDTO?)this.DataHelper.SaveBusinessUnit())]; @@ -41,9 +41,9 @@ public AuthPerformanceTest() this.employeeSource = [null, this.DataHelper.SaveEmployee()]; - this.AuthManager.For(PrincipalName).CreatePrincipal(); + await this.AuthManager.For(PrincipalName).CreatePrincipalAsync(ct); - this.GeneratePermission(); + await this.GeneratePermissionAsync(ct); } [Fact] @@ -66,7 +66,7 @@ public async Task LoadGenerateAuthPerformanceObjects_CountEquals() Assert.Equal(findCount, authPerfCount); } - private void GeneratePermission() + private async ValueTask GeneratePermissionAsync(CancellationToken ct) { var request = from fbu in this.fbuSource @@ -78,7 +78,7 @@ from employee in this.employeeSource select new SampleSystemTestPermission(SampleSystemSecurityRole.TestPerformance, fbu, mbu, location, employee).ToManagedPermission(); - this.AuthManager.For(PrincipalName).SetRole(request.ToArray()); + await this.AuthManager.For(PrincipalName).SetRoleAsync([.. request], ct); } private async Task GenerateAuthPerformanceObject() => diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs index d64ec0e28..3addc1dc3 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs @@ -20,7 +20,7 @@ public class AuthPerformanceTests(IServiceProvider rootServiceProvider) : TestBa private const int SplitBy = 25; - public AuthPerformanceTests() + protected override async ValueTask InitializeAsync(CancellationToken ct) { var genLoc = Enumerable.Range(0, Limit).ToList(i => this.DataHelper.SaveLocation()); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs index 811883bc0..5432ed23e 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs @@ -6,6 +6,8 @@ using Anch.SecuritySystem; +using Framework.AutomationCore.Utils; + using SampleSystem.Domain.BU; using SampleSystem.Domain.Enums; using SampleSystem.Generated.DTO; @@ -25,7 +27,7 @@ public class BusinessUnitTests(IServiceProvider rootServiceProvider) : TestBase( private const int ExistedBusinessUnitsInDatabase = 3; - public BusinessUnitTests() + protected override async ValueTask InitializeAsync(CancellationToken ct) { var buTypeId = this.DataHelper.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_ID); @@ -46,10 +48,11 @@ public BusinessUnitTests() type: buTypeId, parent: luxoftBuId); - this.AuthManager.For(EmployeeName).SetRole( + await this.AuthManager.For(EmployeeName).SetRoleAsync( new SampleSystemTestPermission( SampleSystemSecurityRole.TestRole3, - new BusinessUnitIdentityDTO(DefaultConstants.BUSINESS_UNIT_PARENT_PC_ID))); + new BusinessUnitIdentityDTO(DefaultConstants.BUSINESS_UNIT_PARENT_PC_ID)), + ct); } [Fact] @@ -59,13 +62,13 @@ public void CheckBusinessUnitSecondaryAccess_HasAccess() var businessUnitQueryController = this.GetControllerEvaluator(EmployeeName); // Act - var businessUnitTree = businessUnitQueryController.Evaluate( - c => c.GetTestBusinessUnitTreeByOperation( - new GetTestBusinessUnitTreeByOperationAutoRequest - { - OdataQueryString = string.Empty, - SecurityRule = new DomainSecurityRule.ClientSecurityRule(SampleSystemSecurityOperation.EmployeeEdit.Name) - })); + var businessUnitTree = businessUnitQueryController.Evaluate(c => c.GetTestBusinessUnitTreeByOperation( + new GetTestBusinessUnitTreeByOperationAutoRequest + { + OdataQueryString = string.Empty, + SecurityRule = new DomainSecurityRule.ClientSecurityRule( + SampleSystemSecurityOperation.EmployeeEdit.Name) + })); // Assert Assert.Equal(2, businessUnitTree.TotalCount); @@ -82,13 +85,13 @@ public void GetTreeWithFilter() var businessUnitQueryController = this.GetControllerEvaluator(EmployeeName); // Act - var businessUnitTree = businessUnitQueryController.Evaluate( - c => c.GetTestBusinessUnitTreeByOperation( - new GetTestBusinessUnitTreeByOperationAutoRequest - { - OdataQueryString = "$filter=Name eq 'test'", - SecurityRule = new DomainSecurityRule.ClientSecurityRule(SampleSystemSecurityOperation.EmployeeEdit.Name) - })); + var businessUnitTree = businessUnitQueryController.Evaluate(c => c.GetTestBusinessUnitTreeByOperation( + new GetTestBusinessUnitTreeByOperationAutoRequest + { + OdataQueryString = "$filter=Name eq 'test'", + SecurityRule = new DomainSecurityRule.ClientSecurityRule( + SampleSystemSecurityOperation.EmployeeEdit.Name) + })); // Assert Assert.Equal(0, businessUnitTree.TotalCount); @@ -162,31 +165,30 @@ private void CreateBigBuTree() var buAccountId = this.DataHelper.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_ACCOUNT_ID); this.DataHelper - .EvaluateWrite( - context => + .EvaluateWrite(context => + { + var period = new Period( + this.FinancialYearService.GetCurrentFinancialYear().StartDate + .AddYears(-1)); + var accountType = context.Logics.BusinessUnitType.GetById(buAccountId.Id); + + for (var i = 0; i < ParentsCount; i++) { - var period = new Period( - this.FinancialYearService.GetCurrentFinancialYear().StartDate - .AddYears(-1)); - var accountType = context.Logics.BusinessUnitType.GetById(buAccountId.Id); - - for (var i = 0; i < ParentsCount; i++) - { - var accountBu = - new BusinessUnit - { - Id = Guid.NewGuid(), - Active = true, - Name = TextRandomizer.UniqueString("Account"), - IsPool = true, - BusinessUnitStatus = BusinessUnitStatus.Current, - IsProduction = true, - BusinessUnitType = accountType, - Period = period - }; - - context.Logics.Default.Create().Insert(accountBu, accountBu.Id); - } - }); + var accountBu = + new BusinessUnit + { + Id = Guid.NewGuid(), + Active = true, + Name = TextRandomizer.UniqueString("Account"), + IsPool = true, + BusinessUnitStatus = BusinessUnitStatus.Current, + IsProduction = true, + BusinessUnitType = accountType, + Period = period + }; + + context.Logics.Default.Create().Insert(accountBu, accountBu.Id); + } + }); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs index acb9d4371..f6a245956 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs @@ -15,13 +15,11 @@ public class CurrentUserManyRelativePathTests(IServiceProvider rootServiceProvid private Guid testObj; - public CurrentUserManyRelativePathTests() + protected override async ValueTask InitializeAsync(CancellationToken ct) { this.testEmployeeIdents = - Enumerable.Range(0, 3).Select( - _ => { return this.DataHelper.SaveEmployee().Id; }) - .ToArray(); + Enumerable.Range(0, 3).Select(_ => this.DataHelper.SaveEmployee().Id).ToArray(); this.testObj = this.EvaluateWrite( ctx => @@ -32,7 +30,7 @@ public CurrentUserManyRelativePathTests() foreach (var testEmployeeIdent in this.testEmployeeIdents) { - var testEmployee = ctx.Logics.Employee.GetById(testEmployeeIdent, true); + var testEmployee = ctx.Logics.Employee.GetById(testEmployeeIdent, true)!; new TestRelativeEmployeeChildObject(parentObj) { Employee = testEmployee }; } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSingleRelativePathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSingleRelativePathTests.cs index 30841fd13..b1ca668bd 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSingleRelativePathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSingleRelativePathTests.cs @@ -17,7 +17,7 @@ public class CurrentUserSingleRelativePathTests(IServiceProvider rootServiceProv { private Guid[] testObjectIdents; - public CurrentUserSingleRelativePathTests() => + protected override async ValueTask InitializeAsync(CancellationToken ct) => this.testObjectIdents = this.Evaluate( DBSessionMode.Write, ctx => diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs index a5aed6d4d..44e7dc9d2 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs @@ -1,4 +1,5 @@ -using Framework.Database.NHibernate.DBGenerator; +using Framework.AutomationCore.RootServiceProviderContainer; +using Framework.Database.NHibernate.DBGenerator; using Microsoft.SqlServer.Management.Smo; @@ -49,7 +50,7 @@ public void GenerateLocal_ColumnHasIndexWithIncludedColumns_PreventsDefaultIndex var changedTable = this.DataHelper.GetTable(this.DatabaseContext.Main.DatabaseName, tableName); // Assert - var indexes = changedTable.Indexes.Cast().ToList(); + var indexes = changedTable.Indexes.ToList(); Assert.Contains(indexes, x => x.Name == newIndexName); Assert.DoesNotContain(indexes, x => x.Name == baseIndexName); } @@ -80,7 +81,7 @@ public void GenerateLocal_IgnoredIndex_NotCreated() var changedTable = this.DataHelper.GetTable(this.DatabaseContext.Main.DatabaseName, tableName); // Assert - Assert.DoesNotContain(changedTable.Indexes.Cast(), x => x.Name == ignoredIndexName); + Assert.DoesNotContain(changedTable.Indexes, x => x.Name == ignoredIndexName); } [Fact] @@ -101,6 +102,6 @@ public void GenerateLocal_UniqueFieldForFK_NoDuplicates() var changedTable = this.DataHelper.GetTable(this.DatabaseContext.Main.DatabaseName, "Employee"); // Assert - Assert.DoesNotContain(changedTable.Indexes.Cast(), x => x.Name == "IX_ChildEntity_parentId"); + Assert.DoesNotContain(changedTable.Indexes, x => x.Name == "IX_ChildEntity_parentId"); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/GenerateDBTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/GenerateDBTests.cs index e96e35ed2..4e7c43167 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/GenerateDBTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/GenerateDBTests.cs @@ -1,4 +1,5 @@ -using Framework.Database.NHibernate.DBGenerator; +using Framework.AutomationCore.RootServiceProviderContainer; +using Framework.Database.NHibernate.DBGenerator; using SampleSystem.DbGenerate.NHibernate; using SampleSystem.IntegrationTests.__Support.TestData; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/SchemeUpdateTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/SchemeUpdateTests.cs index f6eb4873e..3a7ea7957 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/SchemeUpdateTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/SchemeUpdateTests.cs @@ -1,4 +1,6 @@ -using SampleSystem.DbGenerate.NHibernate; +using Framework.AutomationCore.RootServiceProviderContainer; + +using SampleSystem.DbGenerate.NHibernate; using SampleSystem.IntegrationTests.__Support.TestData; namespace SampleSystem.IntegrationTests.DBGeneration; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs index 8d9d3479b..cd2d2ba46 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs @@ -1,4 +1,5 @@ -using Framework.Database.NHibernate.DBGenerator; +using Framework.AutomationCore.RootServiceProviderContainer; +using Framework.Database.NHibernate.DBGenerator; using Microsoft.SqlServer.Management.Smo; @@ -44,11 +45,11 @@ public void GenerateLocal_UniqueIndexExistsWithLessColumns_RecreatesColumns() var changedTable = this.DataHelper.GetTable(this.DatabaseContext.Main.DatabaseName, tableName); // changedTable.Indexes.Refresh(); - var indexes = changedTable.Indexes.Cast().ToList(); + var indexes = changedTable.Indexes.ToList(); // Assert Assert.Contains(indexes, x => x.Name == indexName); - var indexedColumns = indexes.First(x => x.Name == indexName).IndexedColumns.Cast().ToList(); + var indexedColumns = indexes.First(x => x.Name == indexName).IndexedColumns.ToList(); Assert.Equal(2, indexedColumns.Count); Assert.Contains(indexedColumns, x => x.Name == "roleDegreeId"); Assert.Contains(indexedColumns, x => x.Name == "roleId"); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs index e9ddda724..25a8f43a2 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs @@ -30,7 +30,7 @@ public class DependencySecurityTests(IServiceProvider rootServiceProvider) : Tes private BusinessUnitIdentityDTO bu2Ident; - public DependencySecurityTests() + protected override async ValueTask InitializeAsync(CancellationToken ct) { this.bu1Ident = this.DataHelper.SaveBusinessUnit(); @@ -38,7 +38,7 @@ public DependencySecurityTests() this.DataHelper.SaveEmployee(login: TestEmployeeLogin); - this.AuthManager.For(TestEmployeeLogin).SetRole(new SampleSystemTestPermission(SampleSystemSecurityRole.SeManager, this.bu2Ident)); + await this.AuthManager.For(TestEmployeeLogin).SetRoleAsync(new SampleSystemTestPermission(SampleSystemSecurityRole.SeManager, this.bu2Ident), ct); this.EvaluateWrite( context => diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs index 93df5c5e0..04a52c70a 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs @@ -16,7 +16,7 @@ public class EmployeeProjectionTests(IServiceProvider rootServiceProvider) : Tes private const string TestEmployee2Login = "Test Employee 2"; private const string TestEmployee3Login = "Test Employee 3"; - public EmployeeProjectionTests() + protected override async ValueTask InitializeAsync(CancellationToken ct) { var buTypeId = this.DataHelper.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_ID); @@ -42,13 +42,14 @@ public EmployeeProjectionTests() this.DataHelper.SaveEmployee(login: TestEmployee2Login, coreBusinessUnit: profitBuId); this.DataHelper.SaveEmployee(login: TestEmployee3Login, coreBusinessUnit: costBuId); - this.AuthManager.For(ProjectionPrincipalName).SetRole( + await this.AuthManager.For(ProjectionPrincipalName).SetRoleAsync( new SampleSystemTestPermission( SampleSystemSecurityRole.SeManager, - new BusinessUnitIdentityDTO(DefaultConstants.BUSINESS_UNIT_PARENT_PC_ID))); + new BusinessUnitIdentityDTO(DefaultConstants.BUSINESS_UNIT_PARENT_PC_ID)), + ct); - this.AuthManager.For(TestEmployee1Login).SetRole(SampleSystemSecurityRole.TestRole1); - this.AuthManager.For(TestEmployee3Login).SetRole(SampleSystemSecurityRole.TestRole2); + await this.AuthManager.For(TestEmployee1Login).SetRoleAsync(SampleSystemSecurityRole.TestRole1, ct); + await this.AuthManager.For(TestEmployee3Login).SetRoleAsync(SampleSystemSecurityRole.TestRole2, ct); } [Fact] diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs index 2b3f739c1..e6a71792a 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs @@ -11,6 +11,8 @@ using Anch.SecuritySystem; +using Framework.AutomationCore.RootServiceProviderContainer; + using Microsoft.Extensions.DependencyInjection; using NHibernate.Impl; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs index c4d135c77..e2f878062 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs @@ -1,4 +1,5 @@ using Framework.Application; +using Framework.AutomationCore.RootServiceProviderContainer; using Framework.Core; using Framework.Database; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs index f725ae985..1e50101f5 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs @@ -34,7 +34,7 @@ public class ExtraQueryableSecurityPathTests(IServiceProvider rootServiceProvide private LocationIdentityDTO loc2Ident; - public ExtraQueryableSecurityPathTests() + protected override async ValueTask InitializeAsync(CancellationToken ct) { this.bu1Ident = this.DataHelper.SaveBusinessUnit(); @@ -46,9 +46,12 @@ public ExtraQueryableSecurityPathTests() this.TestEmployee = this.DataHelper.SaveEmployee(login: "EQSP SecurityTester"); - this.AuthManager.For(this.TestEmployee.Id).SetRole( - new SampleSystemTestPermission(SampleSystemSecurityRole.SeManager, this.bu2Ident, null, this.loc1Ident), - new SampleSystemTestPermission(SampleSystemSecurityRole.SeManager, this.bu2Ident, null, this.loc2Ident)); + await this.AuthManager.For(this.TestEmployee.Id).SetRoleAsync( + [ + new SampleSystemTestPermission(SampleSystemSecurityRole.SeManager, this.bu2Ident, null, this.loc1Ident), + new SampleSystemTestPermission(SampleSystemSecurityRole.SeManager, this.bu2Ident, null, this.loc2Ident) + ], + ct); this.TestEmp1 = this.DataHelper.SaveEmployee(coreBusinessUnit: this.bu1Ident, location: this.loc1Ident); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs index 88ae9243f..a97d28240 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs @@ -43,7 +43,7 @@ public class GetNotificationPrincipalsByHierarchicalContextTests(IServiceProvide private string searchNotificationEmployeeLogin2 = nameof(searchNotificationEmployeeLogin2); - public GetNotificationPrincipalsByHierarchicalContextTests() + protected override async ValueTask InitializeAsync(CancellationToken ct) { this.rootBusinessUnit = this.DataHelper.SaveBusinessUnit(id: DefaultConstants.BUSINESS_UNIT_PARENT_CC_ID); this.child_1_0_BusinessUnit = this.DataHelper.SaveBusinessUnit(parent: this.rootBusinessUnit); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JsonConverterTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JsonConverterTests.cs index 1d18d9f28..72e39f532 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JsonConverterTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JsonConverterTests.cs @@ -1,5 +1,6 @@ using System.Text.Json; +using Framework.AutomationCore.RootServiceProviderContainer; using Framework.Core; using Framework.Infrastructure.JsonConverter; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs index f4cb412bb..dfb580b2d 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs @@ -20,7 +20,7 @@ public class ManualAndLegacyProjectionSecurityTests(IServiceProvider rootService private BusinessUnitIdentityDTO bu2Ident; - public ManualAndLegacyProjectionSecurityTests() + protected override async ValueTask InitializeAsync(CancellationToken ct) { this.bu1Ident = this.DataHelper.SaveBusinessUnit(); @@ -28,7 +28,7 @@ public ManualAndLegacyProjectionSecurityTests() this.DataHelper.SaveEmployee(login: TestEmployeeLogin); - this.AuthManager.For(TestEmployeeLogin).SetRole(new SampleSystemTestPermission(SampleSystemSecurityRole.SeManager, this.bu2Ident)); + await this.AuthManager.For(TestEmployeeLogin).SetRoleAsync(new SampleSystemTestPermission(SampleSystemSecurityRole.SeManager, this.bu2Ident), ct); this.TestEmp1 = this.DataHelper.SaveEmployee(coreBusinessUnit: this.bu1Ident); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs index c1d657359..263530352 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs @@ -11,6 +11,8 @@ using Anch.SecuritySystem; using Anch.SecuritySystem.Validation; +using Framework.AutomationCore.RootServiceProviderContainer; + namespace SampleSystem.IntegrationTests; public class PrincipalWithInitTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) @@ -19,7 +21,7 @@ public class PrincipalWithInitTests(IServiceProvider rootServiceProvider) : Test private Period testPeriod; - public PrincipalWithInitTests() + protected override async ValueTask InitializeAsync(CancellationToken ct) { this.testPeriod = this.TimeProvider.GetCurrentMonth(); @@ -42,10 +44,11 @@ public PrincipalWithInitTests() type: buTypeId, parent: luxoftBuId); - this.AuthManager.For(TestPrincipalName).SetRole( + await this.AuthManager.For(TestPrincipalName).SetRoleAsync( new SampleSystemTestPermission( SampleSystemSecurityRole.TestPerformance, - new BusinessUnitIdentityDTO(DefaultConstants.BUSINESS_UNIT_PARENT_PC_ID)) { Period = new PermissionPeriod(this.testPeriod.StartDate, this.testPeriod.EndDate) }); + new BusinessUnitIdentityDTO(DefaultConstants.BUSINESS_UNIT_PARENT_PC_ID)) { Period = new PermissionPeriod(this.testPeriod.StartDate, this.testPeriod.EndDate) }, + ct); } [Fact] diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs index 3f5d07693..5f1208435 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs @@ -26,7 +26,7 @@ public class SecurityContextRestrictionFilterTests(IServiceProvider rootServiceP private BusinessUnitIdentityDTO buWithAllowedFilter; - public SecurityContextRestrictionFilterTests() + protected override async ValueTask InitializeAsync(CancellationToken ct) { this.employee = this.DataHelper.SaveEmployee(login: this.employeeLogin); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs index 6b0ca0a57..07f161c56 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs @@ -11,7 +11,10 @@ namespace SampleSystem.IntegrationTests.Subscriptions_Metadata; public sealed class MetadataSubscriptionSystemServiceTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { - public MetadataSubscriptionSystemServiceTests() => this.GetNotifications().Clear(); + protected override async ValueTask InitializeAsync(CancellationToken ct) + { + this.GetNotifications().Clear(); + } [Fact] public void SubscriptionFromMetadataShouldBeSent() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs index 29c67aa3d..106542b16 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs @@ -13,7 +13,7 @@ public class VirtualPermissionTests(IServiceProvider rootServiceProvider) : Test private (string UserLogin, Guid BuId, Guid EmployeeId)[] Datas; - public VirtualPermissionTests() => + protected override async ValueTask InitializeAsync(CancellationToken ct) => this.Datas = new[] { "testEmployeeLogin", "otherTestEmployeeLogin" } .Select( userLogin => diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs index c9b1cf198..35444158a 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs @@ -18,7 +18,8 @@ public class WrongSecurityMessageTests(IServiceProvider rootServiceProvider) : T private static readonly Guid TestPrincipalId = Guid.NewGuid(); - public WrongSecurityMessageTests() => this.DataHelper.SaveEmployee(login: TestPrincipalName, id: TestPrincipalId); + protected override async ValueTask InitializeAsync(CancellationToken ct) => + this.DataHelper.SaveEmployee(login: TestPrincipalName, id: TestPrincipalId); [Fact] public void UseWrongSecurityMode_ErrorMessageCorrected() => this.UseSecurityRule_WithoutSecurity_ErrorMessageCorrected(SecurityRule.Edit); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Smo.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Smo.cs index 4d4ca2656..aba44b74b 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Smo.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Smo.cs @@ -1,4 +1,6 @@ -using Microsoft.SqlServer.Management.Smo; +using Framework.AutomationCore.RootServiceProviderContainer; + +using Microsoft.SqlServer.Management.Smo; namespace SampleSystem.IntegrationTests.__Support.TestData.Helpers; From 3f19045f13558e77d33e8f47e363cb309140d16b Mon Sep 17 00:00:00 2001 From: iatsuta Date: Mon, 27 Apr 2026 19:02:06 +0200 Subject: [PATCH 03/13] compile sln --- .../IntegrationTestBase.cs | 162 +++++++++--------- .../AutomationCoreFrameworkInitializer.cs | 116 ++++++------- .../DependencyInjection.cs | 26 +-- .../BUProjectionTests.cs | 2 +- .../ExpandPathTests.cs | 17 +- .../__Support/TestData/TestBase.cs | 11 +- 6 files changed, 168 insertions(+), 166 deletions(-) diff --git a/src/AutomationCore/Framework.AutomationCore.Legacy/IntegrationTestBase.cs b/src/AutomationCore/Framework.AutomationCore.Legacy/IntegrationTestBase.cs index db393affa..825b8b09f 100644 --- a/src/AutomationCore/Framework.AutomationCore.Legacy/IntegrationTestBase.cs +++ b/src/AutomationCore/Framework.AutomationCore.Legacy/IntegrationTestBase.cs @@ -17,85 +17,83 @@ namespace Framework.AutomationCore; -//public abstract class IntegrationTestBase(IServiceProvider rootServiceProvider) : IRootServiceProviderContainer -// where TBLLContext : IServiceProviderContainer -//{ -// public IServiceProvider RootServiceProvider { get; } = rootServiceProvider; - -// public Task EvaluateAsync( -// DBSessionMode sessionMode, -// UserCredential? customUserCredential, -// Func> getResult) => -// rootServiceProvider.GetRequiredService>().EvaluateAsync(sessionMode, customUserCredential, getResult); - - -// protected IConfigurationBLLContext GetConfigurationBLLContext(TBLLContext context) => context.ServiceProvider.GetRequiredService(); - -// /// -// /// Отчистка списка нотифицаций -// /// -// public virtual void ClearNotifications() => -// this.EvaluateWrite(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectNotification.Pipe(bll => bll.GetFullList().ForEach(bll.Remove))); - -// /// -// /// Получение списка модификаций -// /// -// /// -// protected virtual List> GetModifications() => -// this.EvaluateRead(context => - -// this.GetConfigurationBLLContext(context).Logics.DomainObjectModification.GetFullList() -// .ToList(mod => new ObjectModificationInfoDTO -// { -// Identity = mod.DomainObjectId, -// ModificationType = mod.Type, -// Revision = mod.Revision, -// TypeInfoDescription = new TypeInfoDescriptionDTO { Name = mod.DomainType.Name, Namespace = mod.DomainType.Namespace } -// })); - -// /// -// /// Отчистка списка модификаций -// /// -// protected virtual void ClearModifications() => -// this.EvaluateWrite(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectModification.Pipe(bll => bll.GetFullList().ForEach(bll.Remove))); - -// /// -// /// Отчистка интеграционных евентов -// /// -// public virtual void ClearIntegrationEvents() -// { -// this.ClearModifications(); - -// this.EvaluateWrite(context => -// { -// var bll = this.GetConfigurationBLLContext(context).Logics.Default.Create(); - -// bll.GetFullList().ForEach(bll.Remove); -// }); -// } - -// protected int GetIntegrationEventCount() => -// this.EvaluateRead(ctx => ctx.ServiceProvider.GetRequiredService>().Create().GetQueryable().Count()); - - -// /// -// /// Получение интегационных евентов -// /// -// /// -// protected virtual List GetIntegrationEvents(string queueTag = "default") -// { -// var serializeType = typeof(T).FullName; - -// return this.EvaluateRead(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectEvent -// .GetListBy(v => v.SerializeType == serializeType && v.QueueTag == queueTag) -// .ToList(obj => DataContractSerializerHelper.Deserialize(obj.SerializeData))); -// } - -// /// -// /// Получение списка нотификаций -// /// -// /// -// protected virtual List GetNotifications() => -// this.EvaluateRead(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectNotification.GetFullList() -// .ToList(obj => DataContractSerializerHelper.Deserialize(obj.SerializeData))); -//} +public abstract class IntegrationTestBase(IServiceProvider rootServiceProvider) : RootServiceProviderContainer(rootServiceProvider) + where TBLLContext : IServiceProviderContainer +{ + public Task EvaluateAsync( + DBSessionMode sessionMode, + UserCredential? customUserCredential, + Func> getResult) => + rootServiceProvider.GetRequiredService>().EvaluateAsync(sessionMode, customUserCredential, getResult); + + + protected IConfigurationBLLContext GetConfigurationBLLContext(TBLLContext context) => context.ServiceProvider.GetRequiredService(); + + /// + /// Отчистка списка нотифицаций + /// + public virtual void ClearNotifications() => + this.EvaluateWrite(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectNotification.Pipe(bll => bll.GetFullList().ForEach(bll.Remove))); + + /// + /// Получение списка модификаций + /// + /// + protected virtual List> GetModifications() => + this.EvaluateRead(context => + + this.GetConfigurationBLLContext(context).Logics.DomainObjectModification.GetFullList() + .ToList(mod => new ObjectModificationInfoDTO + { + Identity = mod.DomainObjectId, + ModificationType = mod.Type, + Revision = mod.Revision, + TypeInfoDescription = new TypeInfoDescriptionDTO { Name = mod.DomainType.Name, Namespace = mod.DomainType.Namespace } + })); + + /// + /// Отчистка списка модификаций + /// + protected virtual void ClearModifications() => + this.EvaluateWrite(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectModification.Pipe(bll => bll.GetFullList().ForEach(bll.Remove))); + + /// + /// Отчистка интеграционных евентов + /// + public virtual void ClearIntegrationEvents() + { + this.ClearModifications(); + + this.EvaluateWrite(context => + { + var bll = this.GetConfigurationBLLContext(context).Logics.Default.Create(); + + bll.GetFullList().ForEach(bll.Remove); + }); + } + + protected int GetIntegrationEventCount() => + this.EvaluateRead(ctx => ctx.ServiceProvider.GetRequiredService>().Create().GetQueryable().Count()); + + + /// + /// Получение интегационных евентов + /// + /// + protected virtual List GetIntegrationEvents(string queueTag = "default") + { + var serializeType = typeof(T).FullName; + + return this.EvaluateRead(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectEvent + .GetListBy(v => v.SerializeType == serializeType && v.QueueTag == queueTag) + .ToList(obj => DataContractSerializerHelper.Deserialize(obj.SerializeData))); + } + + /// + /// Получение списка нотификаций + /// + /// + protected virtual List GetNotifications() => + this.EvaluateRead(context => this.GetConfigurationBLLContext(context).Logics.DomainObjectNotification.GetFullList() + .ToList(obj => DataContractSerializerHelper.Deserialize(obj.SerializeData))); +} diff --git a/src/AutomationCore/Framework.AutomationCore.Xunit/AutomationCoreFrameworkInitializer.cs b/src/AutomationCore/Framework.AutomationCore.Xunit/AutomationCoreFrameworkInitializer.cs index f0dad9dc1..28d2e226f 100644 --- a/src/AutomationCore/Framework.AutomationCore.Xunit/AutomationCoreFrameworkInitializer.cs +++ b/src/AutomationCore/Framework.AutomationCore.Xunit/AutomationCoreFrameworkInitializer.cs @@ -1,73 +1,73 @@ -using Bss.Testing.Xunit.Interfaces; +//using Bss.Testing.Xunit.Interfaces; -using Framework.AutomationCore.Extensions; -using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Utils.DatabaseUtils; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; -using Framework.AutomationCore.Xunit.ServiceProviderPool; +//using Framework.AutomationCore.Extensions; +//using Framework.AutomationCore.Settings; +//using Framework.AutomationCore.Utils.DatabaseUtils; +//using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; +//using Framework.AutomationCore.Xunit.ServiceProviderPool; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using Microsoft.Extensions.Options; +//using Microsoft.Extensions.Configuration; +//using Microsoft.Extensions.DependencyInjection; +//using Microsoft.Extensions.DependencyInjection.Extensions; +//using Microsoft.Extensions.Options; -namespace Framework.AutomationCore.Xunit; +//namespace Framework.AutomationCore.Xunit; -public abstract class AutomationCoreFrameworkInitializer : IFrameworkInitializer -{ - public abstract IServiceCollection ConfigureFramework(IServiceCollection services); +//public abstract class AutomationCoreFrameworkInitializer : IFrameworkInitializer +//{ +// public abstract IServiceCollection ConfigureFramework(IServiceCollection services); - public abstract IServiceProvider ConfigureTestEnvironment(IServiceCollection services, IConfiguration configuration); +// public abstract IServiceProvider ConfigureTestEnvironment(IServiceCollection services, IConfiguration configuration); - public IServiceProvider GetFrameworkServiceProvider() - { - var frameworkServices = new ServiceCollection(); - AddSettings(frameworkServices); - this.ConfigureFramework(frameworkServices); +// public IServiceProvider GetFrameworkServiceProvider() +// { +// var frameworkServices = new ServiceCollection(); +// AddSettings(frameworkServices); +// this.ConfigureFramework(frameworkServices); - frameworkServices.TryAddSingleton(); - frameworkServices.TryAddSingleton(); +// frameworkServices.TryAddSingleton(); +// frameworkServices.TryAddSingleton(); - frameworkServices.AddSingleton( - sp => new ServiceProviderPoolFunc(this.GetPoolServiceProviderFunc(sp))); +// frameworkServices.AddSingleton( +// sp => new ServiceProviderPoolFunc(this.GetPoolServiceProviderFunc(sp))); - return frameworkServices.BuildServiceProvider( - new ServiceProviderOptions - { - ValidateScopes = true, - ValidateOnBuild = true - }); - } +// return frameworkServices.BuildServiceProvider( +// new ServiceProviderOptions +// { +// ValidateScopes = true, +// ValidateOnBuild = true +// }); +// } - private Func GetPoolServiceProviderFunc(IServiceProvider frameworkSp) - { - var rootConfiguration = frameworkSp.GetRequiredService(); - var automationFrameworkSettings = frameworkSp.GetRequiredService>(); +// private Func GetPoolServiceProviderFunc(IServiceProvider frameworkSp) +// { +// var rootConfiguration = frameworkSp.GetRequiredService(); +// var automationFrameworkSettings = frameworkSp.GetRequiredService>(); - return () => - { - var databaseContext = new DatabaseContext(rootConfiguration, automationFrameworkSettings); - var configuration = rootConfiguration.BuildFromRootWithConnectionStrings(databaseContext); +// return () => +// { +// var databaseContext = new DatabaseContext(rootConfiguration, automationFrameworkSettings); +// var configuration = rootConfiguration.BuildFromRootWithConnectionStrings(databaseContext); - var environmentServices = new ServiceCollection() - .AddSingleton(databaseContext) - .AddSingleton(configuration) - .AddSingleton(automationFrameworkSettings); +// var environmentServices = new ServiceCollection() +// .AddSingleton(databaseContext) +// .AddSingleton(configuration) +// .AddSingleton(automationFrameworkSettings); - return this.ConfigureTestEnvironment(environmentServices, configuration); - }; - } +// return this.ConfigureTestEnvironment(environmentServices, configuration); +// }; +// } - private static void AddSettings(IServiceCollection services) - { - services.AddOptions(); - services.AddSingleton>( - s => - { - return new ConfigureOptions( - opt => s.GetRequiredService() - .Bind(nameof(AutomationFrameworkSettings), opt)); - }); - } -} +// private static void AddSettings(IServiceCollection services) +// { +// services.AddOptions(); +// services.AddSingleton>( +// s => +// { +// return new ConfigureOptions( +// opt => s.GetRequiredService() +// .Bind(nameof(AutomationFrameworkSettings), opt)); +// }); +// } +//} diff --git a/src/AutomationCore/Framework.AutomationCore.Xunit/DependencyInjection.cs b/src/AutomationCore/Framework.AutomationCore.Xunit/DependencyInjection.cs index 30a09ccfb..fd1f43432 100644 --- a/src/AutomationCore/Framework.AutomationCore.Xunit/DependencyInjection.cs +++ b/src/AutomationCore/Framework.AutomationCore.Xunit/DependencyInjection.cs @@ -1,17 +1,17 @@ -using Bss.Testing.Xunit.Interfaces; +//using Bss.Testing.Xunit.Interfaces; -using Framework.AutomationCore.ServiceEnvironment; -using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Xunit.ServiceEnvironment; +//using Framework.AutomationCore.ServiceEnvironment; +//using Framework.AutomationCore.Settings; +//using Framework.AutomationCore.Xunit.ServiceEnvironment; -using Microsoft.Extensions.DependencyInjection; +//using Microsoft.Extensions.DependencyInjection; -namespace Framework.AutomationCore.Xunit; +//namespace Framework.AutomationCore.Xunit; -public static class DependencyInjection -{ - public static IServiceCollection AddXunitIntegrationTests(this IServiceCollection services, Action? setup = null) => - services - .AddSingleton() - .AddIntegrationTests(setup); -} +//public static class DependencyInjection +//{ +// public static IServiceCollection AddXunitIntegrationTests(this IServiceCollection services, Action? setup = null) => +// services +// .AddSingleton() +// .AddIntegrationTests(setup); +//} diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs index befad639f..b75bd90bd 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs @@ -14,7 +14,7 @@ public class BUProjectionTests(IServiceProvider rootServiceProvider) : TestBase( private const string TestEmployee1Login = "Test Employee 1"; private const string TestEmployee2Login = "Test Employee 2"; - public BUProjectionTests() + protected override async ValueTask InitializeAsync(CancellationToken ct) { var buTypeId = this.DataHelper.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_ID); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs index e2f878062..bfa29e159 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs @@ -52,11 +52,12 @@ public void LiftToNullablePeriodIntersect_ShouldNotThrowException() // Act var action = new Action(() => { + var currentMonth = this.TimeProvider.GetCurrentMonth(); + var res = this.Evaluate( DBSessionMode.Read, context => context.Logics.Employee.GetListBy( - employee => employee.CoreBusinessUnitPeriod.IsIntersected( - this.TimeProvider.GetCurrentMonth()))); + employee => employee.CoreBusinessUnitPeriod.IsIntersected(currentMonth))); return; }); @@ -73,11 +74,15 @@ public void LiftToNullablePeriodContains_ShouldNotThrowException() // Act var action = new Action(() => - { - var res = this.Evaluate(DBSessionMode.Read, context => context.Logics.Employee.GetListBy(employee => employee.CoreBusinessUnitPeriod.Contains(this.TimeProvider.GetToday()))); + { + var today = this.TimeProvider.GetToday(); - return; - }); + var res = this.Evaluate( + DBSessionMode.Read, + context => context.Logics.Employee.GetListBy(employee => employee.CoreBusinessUnitPeriod.Contains(today))); + + return; + }); // Assert action(); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/TestBase.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/TestBase.cs index 3e3408a48..50dc58ca1 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/TestBase.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/TestBase.cs @@ -1,4 +1,7 @@ -using Framework.AutomationCore.ServiceEnvironment; +using Anch.SecuritySystem.Testing; + +using Framework.AutomationCore; +using Framework.AutomationCore.ServiceEnvironment; using Microsoft.Extensions.DependencyInjection; @@ -7,13 +10,9 @@ using SampleSystem.IntegrationTests.__Support.WebApi; using SampleSystem.WebApiCore.Controllers.Main; -using Anch.SecuritySystem.Testing; - -using Framework.AutomationCore.RootServiceProviderContainer; - namespace SampleSystem.IntegrationTests.__Support.TestData; -public class TestBase(IServiceProvider rootServiceProvider) : RootServiceProviderContainer(rootServiceProvider), IAsyncLifetime +public class TestBase(IServiceProvider rootServiceProvider) : IntegrationTestBase(rootServiceProvider), IAsyncLifetime { public MainWebApi MainWebApi => new(this.RootServiceProvider); From 2ef5a8ecda67e9d077d9e0dfc9c73154f4176384 Mon Sep 17 00:00:00 2001 From: iatsuta Date: Tue, 28 Apr 2026 13:50:48 +0200 Subject: [PATCH 04/13] upd --- src/Directory.Packages.props | 3 +- .../AsyncControllerTests.cs | 2 +- .../AuditTests.cs | 2 +- .../Auth/PrincipalTests.cs | 3 +- .../AuthPerfomanceTest.cs | 3 +- .../AuthPerformanceTests.cs | 3 +- .../BUProjectionTests.cs | 2 +- .../BusinessUnitTests.cs | 2 +- .../CurrentUserManyRelativePathTests.cs | 2 +- .../CurrentUserSingleRelativePathTests.cs | 2 +- .../CurrentUserSourceTests.cs | 2 +- .../ChangeIndexesStrategyTests.cs | 2 +- .../DBGeneration/GenerateDBTests.cs | 24 +++--- .../DBGeneration/SchemeUpdateTests.cs | 6 +- ...UniqueGroupDatabaseScriptGeneratorTests.cs | 2 +- .../DependencySecurityTests.cs | 2 +- .../EmployeeProjectionTests.cs | 2 +- .../EmployeeTests.cs | 2 +- .../EnversBug1676.cs | 2 +- .../EventDALListenerTests.cs | 2 +- .../ExpandPathTests.cs | 2 +- .../ExtraQueryableSecurityPathTests.cs | 2 +- .../FixedPropertyValidatorTests.cs | 2 +- ...ionPrincipalsByHierarchicalContextTests.cs | 3 +- .../ImpersonateTests.cs | 2 +- .../InformationTest.cs | 2 +- .../IntegrationVersionTest.cs | 2 +- .../JobTests.cs | 2 +- .../JsonConverterTests.cs | 2 +- .../LegalEntityProjectionTests.cs | 2 +- .../ManagmentUnitFluentMappingTests.cs | 2 +- .../ManualAndLegacyProjectionSecurityTests.cs | 2 +- .../NH/FullTextSearchTests.cs | 2 +- .../NHibFetchTests.cs | 2 +- .../NhibArrayContainsTest.cs | 2 +- .../NhibDateTimeTests.cs | 2 +- .../NotificationCountryTests.cs | 2 +- .../OneToOneTests.cs | 2 +- .../PerfomanceTests.cs | 2 +- .../PrincipalTests.cs | 4 +- .../PrincipalWithInitTests.cs | 3 +- .../RepositoryControllerTests.cs | 2 +- .../RepositoryWithoutSecurityTests.cs | 2 +- .../RestrictionRoleTests.cs | 3 +- ...eSystem.IntegrationTests.NHibernate.csproj | 5 +- .../SecurityContextRestrictionFilterTests.cs | 3 +- .../SecurityPathTests.cs | 2 +- .../SecurityRuleTests.cs | 3 +- .../SequenceBllTests.cs | 2 +- .../SqlParserTests.cs | 2 +- ...bscriptionCustomNotPersistentModelTests.cs | 2 +- .../MetadataSubscriptionSystemServiceTests.cs | 2 +- .../TransactionFlushBeforeCommit.cs | 2 +- .../UniqueGroupTests.cs | 2 +- .../UpdateTests.cs | 2 +- .../ValidationTests.cs | 2 +- .../VirtualPermissionTests.cs | 2 +- .../WebApi/EmployeeTests.cs | 2 +- .../WrongSecurityMessageTests.cs | 3 +- .../_Environment/EmptySchemaInitializer.cs | 22 +++++ .../InitNumberInDomainObjectEventMigration.cs | 2 +- .../_Environment/NHibTestEnvironment.cs | 80 +++++++++++++++++++ .../Scripts/CheckConstraint.sql | 0 .../Scripts/Configuration/Configuration.sql | 0 .../Scripts/NoCheckConstraint.sql | 0 .../SampleSystem/Create AncestorChildView.sql | 0 .../Scripts/SampleSystem/Sample.sql | 0 .../TestData/DefaultConstants.cs | 2 +- .../TestData/Helpers/DataHelper.Employee.cs | 9 +-- .../TestData/Helpers/DataHelper.Init.cs | 2 +- .../TestData/Helpers/DataHelper.Smo.cs | 2 +- .../Helpers/DataHelper.Subscriptions.cs | 2 +- .../TestData/Helpers/DataHelper.cs | 2 +- .../TestData/SampleSystemTestPermission.cs | 7 +- .../TestData/TestBase.cs | 6 +- .../TestData/TestDataInitializer.cs | 23 +++--- .../SampleSystemTestDatabaseGenerator.cs | 0 .../Utils/TestIntegrationEventPublisher.cs | 2 +- .../WebApi/IntegrationWebApi.cs | 4 +- .../WebApi/MainAuditWebApi.cs | 2 +- .../WebApi/MainWebApi.cs | 2 +- .../__Support/InitializeAndCleanup.cs | 55 ------------- ...{appsettings.json => testAppSettings.json} | 0 .../ExtractConstTests.cs | 10 +-- 84 files changed, 222 insertions(+), 171 deletions(-) create mode 100644 src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/EmptySchemaInitializer.cs rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/FluentMigration/InitNumberInDomainObjectEventMigration.cs (88%) create mode 100644 src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/Scripts/CheckConstraint.sql (100%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/Scripts/Configuration/Configuration.sql (100%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/Scripts/NoCheckConstraint.sql (100%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/Scripts/SampleSystem/Create AncestorChildView.sql (100%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/Scripts/SampleSystem/Sample.sql (100%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/TestData/DefaultConstants.cs (98%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/TestData/Helpers/DataHelper.Employee.cs (98%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/TestData/Helpers/DataHelper.Init.cs (85%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/TestData/Helpers/DataHelper.Smo.cs (90%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/TestData/Helpers/DataHelper.Subscriptions.cs (89%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/TestData/Helpers/DataHelper.cs (99%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/TestData/SampleSystemTestPermission.cs (97%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/TestData/TestBase.cs (88%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/TestData/TestDataInitializer.cs (95%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/Utils/SampleSystemTestDatabaseGenerator.cs (100%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/Utils/TestIntegrationEventPublisher.cs (79%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/WebApi/IntegrationWebApi.cs (67%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/WebApi/MainAuditWebApi.cs (88%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{__Support => _Environment}/WebApi/MainWebApi.cs (90%) delete mode 100644 src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/InitializeAndCleanup.cs rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/{appsettings.json => testAppSettings.json} (100%) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 17be547d1..5829c55a3 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -8,6 +8,7 @@ + @@ -74,4 +75,4 @@ - + \ No newline at end of file diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AsyncControllerTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AsyncControllerTests.cs index fcf24902e..440097ad1 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AsyncControllerTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AsyncControllerTests.cs @@ -1,5 +1,5 @@ using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.WebApiCore.Controllers.Main; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuditTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuditTests.cs index 4eaf33474..46c9dc9eb 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuditTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuditTests.cs @@ -6,7 +6,7 @@ using SampleSystem.Domain.Employee; using SampleSystem.Domain.Inline; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.WebApiCore.Controllers.Audit; using SampleSystem.WebApiCore.Controllers.Main; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs index ffb6192fe..fe3f7b22f 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs @@ -1,12 +1,13 @@ using Framework.Authorization.Generated.DTO; using Framework.BLL.Exceptions; -using SampleSystem.IntegrationTests.__Support.TestData; using SampleSystem.Security; using SampleSystem.WebApiCore.Controllers.Main; using Anch.SecuritySystem; +using SampleSystem.IntegrationTests._Environment.TestData; + using DelegateToItemModelStrictDTO = Framework.Authorization.Generated.DTO.DelegateToItemModelStrictDTO; namespace SampleSystem.IntegrationTests.Auth; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs index 97cfeae90..cab01105a 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs @@ -10,11 +10,12 @@ using SampleSystem.Domain.Employee; using SampleSystem.Domain.MU; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; using SampleSystem.Security; using Anch.SecuritySystem; +using SampleSystem.IntegrationTests._Environment.TestData; + namespace SampleSystem.IntegrationTests; public class AuthPerformanceTest(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs index 3addc1dc3..2189c1f8e 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs @@ -4,12 +4,13 @@ using SampleSystem.Domain; using SampleSystem.Domain.TestDeserializedAuth; -using SampleSystem.IntegrationTests.__Support.TestData; using SampleSystem.Security; using SampleSystem.WebApiCore.Controllers.Main; using Anch.SecuritySystem; +using SampleSystem.IntegrationTests._Environment.TestData; + namespace SampleSystem.IntegrationTests; public class AuthPerformanceTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs index b75bd90bd..ddeee0768 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs @@ -3,7 +3,7 @@ using SampleSystem.Domain.BU; using SampleSystem.Domain.Inline; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.WebApiCore.Controllers.MainQuery; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs index 5432ed23e..17bd7630e 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs @@ -11,7 +11,7 @@ using SampleSystem.Domain.BU; using SampleSystem.Domain.Enums; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.Security; using SampleSystem.WebApiCore.Controllers.MainQuery; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs index f6a245956..7a2649e41 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs @@ -5,7 +5,7 @@ using Anch.SecuritySystem; using SampleSystem.Domain; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSingleRelativePathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSingleRelativePathTests.cs index b1ca668bd..b3f0d833f 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSingleRelativePathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSingleRelativePathTests.cs @@ -9,7 +9,7 @@ using SampleSystem.Domain; using SampleSystem.Domain.Employee; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs index 8b5441415..b5a40009d 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs @@ -5,7 +5,7 @@ using Anch.SecuritySystem.UserSource; using SampleSystem.Domain.Employee; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs index 44e7dc9d2..9433e9a3f 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs @@ -4,7 +4,7 @@ using Microsoft.SqlServer.Management.Smo; using SampleSystem.DbGenerate.NHibernate; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using Index = Microsoft.SqlServer.Management.Smo.Index; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/GenerateDBTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/GenerateDBTests.cs index 4e7c43167..3dd2cccc9 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/GenerateDBTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/GenerateDBTests.cs @@ -1,28 +1,24 @@ -using Framework.AutomationCore.RootServiceProviderContainer; -using Framework.Database.NHibernate.DBGenerator; +using Anch.Testing.Xunit; -using SampleSystem.DbGenerate.NHibernate; -using SampleSystem.IntegrationTests.__Support.TestData; +using Microsoft.Extensions.DependencyInjection; + +using SampleSystem.IntegrationTests._Environment; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests.DBGeneration; public class GenerateDBTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { - [Fact] - public void GenerateDB_SecondTime_ShouldNotFail() + [AnchFact] + public async Task GenerateDB_SecondTime_ShouldNotFail(CancellationToken ct) { // Arrange - var generator = new DbGeneratorTest(); + var initializer = rootServiceProvider.GetRequiredService(); // Act - var action = new Action(() => generator.GenerateAllDB( - this.DatabaseContext.Main.DataSource, - this.DatabaseContext.Main.DatabaseName, - credential: DbUserCredential.Create( - this.DatabaseContext.Main.UserId, - this.DatabaseContext.Main.Password))); + var ex = await Record.ExceptionAsync(() => initializer.Initialize(ct)); // Assert - Assert.Null(Record.Exception(action)); + Assert.Null(ex); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/SchemeUpdateTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/SchemeUpdateTests.cs index 3a7ea7957..0f737b93e 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/SchemeUpdateTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/SchemeUpdateTests.cs @@ -1,7 +1,7 @@ using Framework.AutomationCore.RootServiceProviderContainer; using SampleSystem.DbGenerate.NHibernate; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests.DBGeneration; @@ -11,13 +11,11 @@ public class SchemeUpdateTests(IServiceProvider rootServiceProvider) : TestBase( public void SchemeUpdate_ExistsDatabase_ShouldNotFail() { // Arrange - var generator = new UseSchemeUpdateTest(); // Act - var action = new Action(() => UseSchemeUpdateTest.UseSchemeUpdate(this.DatabaseContext.Main.ConnectionString)); + var ex = Record.Exception(() => UseSchemeUpdateTest.UseSchemeUpdate(this.DatabaseContext.Main.ConnectionString)); // Assert - var ex = Record.Exception(action); Assert.Null(ex); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs index cd2d2ba46..8a722b9a3 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs @@ -4,7 +4,7 @@ using Microsoft.SqlServer.Management.Smo; using SampleSystem.DbGenerate.NHibernate; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using Index = Microsoft.SqlServer.Management.Smo.Index; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs index 25a8f43a2..4fa5064e6 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs @@ -2,7 +2,7 @@ using SampleSystem.Domain.TestDependency; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.Security; using SampleSystem.WebApiCore.Controllers.Main; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs index 04a52c70a..47ca3db92 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs @@ -3,7 +3,7 @@ using Framework.Core; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.Security; using SampleSystem.WebApiCore.Controllers.MainQuery; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs index e6a71792a..63d89db78 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs @@ -19,7 +19,7 @@ using SampleSystem.Domain.Employee; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EnversBug1676.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EnversBug1676.cs index 2e35db7f2..bd412362b 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EnversBug1676.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EnversBug1676.cs @@ -1,7 +1,7 @@ using Framework.AutomationCore.RootServiceProviderContainer; using SampleSystem.Domain.EnversBug1676; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EventDALListenerTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EventDALListenerTests.cs index 2bac5e8b7..da2b29394 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EventDALListenerTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EventDALListenerTests.cs @@ -2,7 +2,7 @@ using Framework.Database; using SampleSystem.EventMetadata; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs index bfa29e159..2ffcce079 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs @@ -3,7 +3,7 @@ using Framework.Core; using Framework.Database; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs index 1e50101f5..0a4c160d4 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs @@ -11,7 +11,7 @@ using SampleSystem.BLL; using SampleSystem.Domain.Employee; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.Security; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs index 5117c64a4..bd56756f6 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs @@ -1,6 +1,6 @@ using SampleSystem.Domain; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.WebApiCore.Controllers.Main; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs index a97d28240..9eb3a2e0b 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs @@ -7,12 +7,13 @@ using SampleSystem.Domain.Employee; using SampleSystem.Domain.MU; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; using SampleSystem.Security; using Anch.SecuritySystem.Notification; using Anch.SecuritySystem.Notification.Domain; +using SampleSystem.IntegrationTests._Environment.TestData; + namespace SampleSystem.IntegrationTests; public class GetNotificationPrincipalsByHierarchicalContextTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ImpersonateTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ImpersonateTests.cs index a72fed5e1..941ddc255 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ImpersonateTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ImpersonateTests.cs @@ -1,4 +1,4 @@ -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.WebApiCore.Controllers.Main; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/InformationTest.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/InformationTest.cs index 57954fcac..bbde0a266 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/InformationTest.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/InformationTest.cs @@ -3,7 +3,7 @@ using SampleSystem.Domain.Employee; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/IntegrationVersionTest.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/IntegrationVersionTest.cs index 5a091e08f..f7dcf9483 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/IntegrationVersionTest.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/IntegrationVersionTest.cs @@ -4,7 +4,7 @@ using SampleSystem.Domain.IntegrationVersions; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.WebApiCore.Controllers.Integration; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JobTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JobTests.cs index d090cda83..5a70802ec 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JobTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JobTests.cs @@ -3,7 +3,7 @@ using Framework.Database; using SampleSystem.Domain; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.ServiceEnvironment.Jobs; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JsonConverterTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JsonConverterTests.cs index 72e39f532..112054c04 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JsonConverterTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/JsonConverterTests.cs @@ -4,7 +4,7 @@ using Framework.Core; using Framework.Infrastructure.JsonConverter; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/LegalEntityProjectionTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/LegalEntityProjectionTests.cs index 49edf61a1..50e0542ea 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/LegalEntityProjectionTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/LegalEntityProjectionTests.cs @@ -6,7 +6,7 @@ using SampleSystem.Domain.Directories; using SampleSystem.Domain.Projections; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManagmentUnitFluentMappingTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManagmentUnitFluentMappingTests.cs index e4ed080ee..0baa48e23 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManagmentUnitFluentMappingTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManagmentUnitFluentMappingTests.cs @@ -3,7 +3,7 @@ using Framework.Database; using SampleSystem.Domain.NhFluentMapping; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs index dfb580b2d..a9c436880 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs @@ -1,7 +1,7 @@ using SampleSystem.Domain.Projections; using SampleSystem.Generated.DTO; using SampleSystem.Domain.ManualProjections; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.Security; using SampleSystem.WebApiCore.Controllers.MainQuery; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NH/FullTextSearchTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NH/FullTextSearchTests.cs index 6cf8eaf7a..1beb4b9bf 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NH/FullTextSearchTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NH/FullTextSearchTests.cs @@ -1,6 +1,6 @@ using Framework.AutomationCore.RootServiceProviderContainer; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests.NH; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NHibFetchTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NHibFetchTests.cs index 42010ef18..b36fa4edd 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NHibFetchTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NHibFetchTests.cs @@ -3,7 +3,7 @@ using Anch.GenericQueryable; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibArrayContainsTest.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibArrayContainsTest.cs index 98f32c25c..173067b42 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibArrayContainsTest.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibArrayContainsTest.cs @@ -8,7 +8,7 @@ using SampleSystem.Domain.BU; using SampleSystem.Domain.Enums; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibDateTimeTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibDateTimeTests.cs index 4800fdaab..4afeedf10 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibDateTimeTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibDateTimeTests.cs @@ -1,7 +1,7 @@ using Framework.AutomationCore.RootServiceProviderContainer; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.WebApiCore.Controllers.Main; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs index 6721afe6f..e06be6df3 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs @@ -4,7 +4,7 @@ using SampleSystem.Domain.Directories; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/OneToOneTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/OneToOneTests.cs index 3b5057a23..079b4bef8 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/OneToOneTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/OneToOneTests.cs @@ -2,7 +2,7 @@ using Framework.Database; using SampleSystem.Domain.Employee; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.WebApiCore.Controllers.MainQuery; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PerfomanceTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PerfomanceTests.cs index 6405686f0..ca13c8bc5 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PerfomanceTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PerfomanceTests.cs @@ -6,7 +6,7 @@ using Framework.Database; using SampleSystem.Domain.Employee; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalTests.cs index 59febcc58..4ff731284 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalTests.cs @@ -3,9 +3,9 @@ using Framework.Authorization.Generated.DTO; using Framework.Core; -using SampleSystem.IntegrationTests.__Support.TestData; - using Anch.SecuritySystem; + +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.WebApiCore.Controllers.Main; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs index 263530352..cd78a8c59 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs @@ -5,7 +5,6 @@ using Framework.Database; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; using SampleSystem.Security; using Anch.SecuritySystem; @@ -13,6 +12,8 @@ using Framework.AutomationCore.RootServiceProviderContainer; +using SampleSystem.IntegrationTests._Environment.TestData; + namespace SampleSystem.IntegrationTests; public class PrincipalWithInitTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryControllerTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryControllerTests.cs index 916d04057..5421184d2 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryControllerTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryControllerTests.cs @@ -1,4 +1,4 @@ -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.WebApiCore.Controllers.Main; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryWithoutSecurityTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryWithoutSecurityTests.cs index 652f3c74e..baac3105e 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryWithoutSecurityTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryWithoutSecurityTests.cs @@ -1,4 +1,4 @@ -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.WebApiCore.Controllers.Main; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs index 1fc5466a9..23a7a8173 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs @@ -6,12 +6,13 @@ using SampleSystem.Domain.Directories; using SampleSystem.Domain.Employee; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; using SampleSystem.Security; using SampleSystem.WebApiCore.Controllers.Main; using Anch.SecuritySystem; using Anch.SecuritySystem.Validation; +using SampleSystem.IntegrationTests._Environment.TestData; + namespace SampleSystem.IntegrationTests; public class RestrictionRoleTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SampleSystem.IntegrationTests.NHibernate.csproj b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SampleSystem.IntegrationTests.NHibernate.csproj index 8b7cf703a..d39c757c8 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SampleSystem.IntegrationTests.NHibernate.csproj +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SampleSystem.IntegrationTests.NHibernate.csproj @@ -6,6 +6,7 @@ + @@ -17,7 +18,7 @@ - + PreserveNewest @@ -29,7 +30,7 @@ - + PreserveNewest diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs index 5f1208435..435549e26 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs @@ -3,12 +3,13 @@ using SampleSystem.Domain.BU; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; using SampleSystem.Security; using Anch.SecuritySystem; using Anch.SecuritySystem.Validation; +using SampleSystem.IntegrationTests._Environment.TestData; + namespace SampleSystem.IntegrationTests; public class SecurityContextRestrictionFilterTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityPathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityPathTests.cs index ef1c53484..87f55c4f9 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityPathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityPathTests.cs @@ -7,7 +7,7 @@ using SampleSystem.Domain.Employee; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.Security; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs index 4fdf8f109..dd4a13da6 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs @@ -8,10 +8,11 @@ using Microsoft.Extensions.DependencyInjection; using SampleSystem.Domain.Employee; -using SampleSystem.IntegrationTests.__Support.TestData; using Anch.SecuritySystem.AccessDenied; +using SampleSystem.IntegrationTests._Environment.TestData; + namespace SampleSystem.IntegrationTests; public class SecurityRuleTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SequenceBllTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SequenceBllTests.cs index 99c7aad9a..c3b6f92ea 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SequenceBllTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SequenceBllTests.cs @@ -2,7 +2,7 @@ using Framework.Configuration.BLL; using Framework.Database; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs index 25ec8bdcc..5763b9a22 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs @@ -4,7 +4,7 @@ using SampleSystem.Domain; using SampleSystem.Domain.Employee; using SampleSystem.Domain.HRDepartment; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.WebApiCore.Controllers.Main; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SubscriptionCustomNotPersistentModelTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SubscriptionCustomNotPersistentModelTests.cs index d28b61ff5..440efa0dc 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SubscriptionCustomNotPersistentModelTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SubscriptionCustomNotPersistentModelTests.cs @@ -2,7 +2,7 @@ using Framework.Database; using SampleSystem.Domain.Directories; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.Subscriptions.Metadata.DomainChangedByRecipients.NotPersistentCustomModel; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs index 07f161c56..caa43fa15 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs @@ -5,7 +5,7 @@ using SampleSystem.Domain.Employee; using SampleSystem.Domain.Models.Custom; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests.Subscriptions_Metadata; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/TransactionFlushBeforeCommit.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/TransactionFlushBeforeCommit.cs index e5b92c7e6..40fe6c6ac 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/TransactionFlushBeforeCommit.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/TransactionFlushBeforeCommit.cs @@ -3,7 +3,7 @@ using SampleSystem.Domain.Employee; using SampleSystem.Domain.ForUpdate; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs index a4e08313b..cb3069a2c 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs @@ -1,6 +1,6 @@ using Framework.Database.DALExceptions; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UpdateTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UpdateTests.cs index eba14f6a5..718d96859 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UpdateTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UpdateTests.cs @@ -4,7 +4,7 @@ using Framework.Core; using SampleSystem.Generated.DTO; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.WebApiCore.Controllers.Main; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs index ac4d44ff2..c31efb176 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs @@ -1,4 +1,4 @@ -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using ValidationException = Framework.Validation.ValidationException; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs index 106542b16..11b30fb8e 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs @@ -3,7 +3,7 @@ using SampleSystem.Domain.BU; using SampleSystem.Domain.Enums; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; using SampleSystem.Security; namespace SampleSystem.IntegrationTests; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WebApi/EmployeeTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WebApi/EmployeeTests.cs index 40d3d6560..4575417af 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WebApi/EmployeeTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WebApi/EmployeeTests.cs @@ -1,4 +1,4 @@ -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; namespace SampleSystem.IntegrationTests.WebApi; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs index 35444158a..c18347708 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs @@ -5,11 +5,12 @@ using Anch.SecuritySystem; using SampleSystem.Domain.Employee; -using SampleSystem.IntegrationTests.__Support.TestData; using SampleSystem.Security; using Anch.SecuritySystem.AccessDenied; +using SampleSystem.IntegrationTests._Environment.TestData; + namespace SampleSystem.IntegrationTests; public class WrongSecurityMessageTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/EmptySchemaInitializer.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/EmptySchemaInitializer.cs new file mode 100644 index 000000000..4f89bf51b --- /dev/null +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/EmptySchemaInitializer.cs @@ -0,0 +1,22 @@ +using Anch.Core; + +using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; +using Framework.Database.NHibernate.DBGenerator; + +using SampleSystem.DbGenerate.NHibernate; + +namespace SampleSystem.IntegrationTests._Environment; + +public class EmptySchemaInitializer(IDatabaseContext databaseContext) : IInitializer +{ + public async Task Initialize(CancellationToken cancellationToken) + { + var generator = new DbGeneratorTest(); + + // Act + generator.GenerateAllDB( + databaseContext.Main.DataSource, + databaseContext.Main.DatabaseName, + credential: DbUserCredential.Create(databaseContext.Main.UserId, databaseContext.Main.Password)); + } +} diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/FluentMigration/InitNumberInDomainObjectEventMigration.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/FluentMigration/InitNumberInDomainObjectEventMigration.cs similarity index 88% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/FluentMigration/InitNumberInDomainObjectEventMigration.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/FluentMigration/InitNumberInDomainObjectEventMigration.cs index b8f724e7f..edb9c6a0a 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/FluentMigration/InitNumberInDomainObjectEventMigration.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/FluentMigration/InitNumberInDomainObjectEventMigration.cs @@ -3,7 +3,7 @@ using Framework.Configuration.Domain; -namespace SampleSystem.IntegrationTests.__Support.FluentMigration; +namespace SampleSystem.IntegrationTests._Environment.FluentMigration; [Migration(2022_11_18_16_09_00)] public class InitNumberInDomainObjectEventMigration : Migration diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs new file mode 100644 index 000000000..c8e60d8dd --- /dev/null +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs @@ -0,0 +1,80 @@ +using Anch.DependencyInjection; +using Anch.Testing; +using Anch.Testing.Database; +using Anch.Testing.Database.DependencyInjection; +using Anch.Testing.Database.Mssql; +using Anch.Testing.Xunit; + +using Bss.Platform.Events.Abstractions; + +using Framework.Application.Jobs; +using Framework.AutomationCore.ServiceEnvironment; +using Framework.Database; +using Framework.Database.ConnectionStringSource; + +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting.Internal; + +using SampleSystem.IntegrationTests._Environment; +using SampleSystem.IntegrationTests._Environment.TestData; +using SampleSystem.IntegrationTests._Environment.TestData.Helpers; +using SampleSystem.IntegrationTests._Environment.Utils; +using SampleSystem.ServiceEnvironment; +using SampleSystem.ServiceEnvironment.DependencyInjection; +using SampleSystem.ServiceEnvironment.Jobs; +using SampleSystem.WebApiCore.Controllers.Main; + +[assembly: AnchTestFramework] + +namespace SampleSystem.IntegrationTests._Environment; + +public class NHibTestEnvironment : ITestEnvironment +{ + public IServiceProvider BuildServiceProvider(IServiceCollection services) + { + var configuration = new ConfigurationBuilder().AddJsonFile("testAppSettings.json", false, true).Build(); + + + var defaultConnectionString = configuration.GetConnectionString("DefaultConnection") + ?? throw new InvalidOperationException("DefaultConnection string is not configured."); + + + + return services.AddGeneralDependencyInjection(configuration, new HostingEnvironment(), s => s.AddExtensions(new SampleSystemNHibernateExtension())) + + .AddSingleton() + + .AddIntegrationTests() + + .AddScoped() + + .AddSingleton(new JobImpersonateData("sampleSystemTestJob")) + .AddJobs([typeof(SampleJob).Assembly]) + + .AddTestControllers([typeof(EmployeeController).Assembly]) + + .AddSingleton() + + .AddSingleton() + .AddSingleton() + + .AddDatabaseTesting(dts => dts + .SetProvider() + .SetEmptySchemaInitializer() + .SetSharedTestDataInitializer() + .SetSettings(new TestDatabaseSettings + { + InitMode = DatabaseInitModeHelper.DatabaseInitMode, + DefaultConnectionString = new(defaultConnectionString) + }) + .RebindActualConnection(connectionString => new ManualDefaultConnectionStringSource(connectionString.Value))) + + + .AddDatabaseTesting(dts => dts.SetProvider() + ) + + .AddValidator() + .BuildServiceProvider(new ServiceProviderOptions { ValidateScopes = true, ValidateOnBuild = true }); + } +} diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Scripts/CheckConstraint.sql b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/Scripts/CheckConstraint.sql similarity index 100% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Scripts/CheckConstraint.sql rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/Scripts/CheckConstraint.sql diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Scripts/Configuration/Configuration.sql b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/Scripts/Configuration/Configuration.sql similarity index 100% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Scripts/Configuration/Configuration.sql rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/Scripts/Configuration/Configuration.sql diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Scripts/NoCheckConstraint.sql b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/Scripts/NoCheckConstraint.sql similarity index 100% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Scripts/NoCheckConstraint.sql rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/Scripts/NoCheckConstraint.sql diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Scripts/SampleSystem/Create AncestorChildView.sql b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/Scripts/SampleSystem/Create AncestorChildView.sql similarity index 100% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Scripts/SampleSystem/Create AncestorChildView.sql rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/Scripts/SampleSystem/Create AncestorChildView.sql diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Scripts/SampleSystem/Sample.sql b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/Scripts/SampleSystem/Sample.sql similarity index 100% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Scripts/SampleSystem/Sample.sql rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/Scripts/SampleSystem/Sample.sql diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/DefaultConstants.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/DefaultConstants.cs similarity index 98% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/DefaultConstants.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/DefaultConstants.cs index c2f6f5daf..3fb360309 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/DefaultConstants.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/DefaultConstants.cs @@ -1,4 +1,4 @@ -namespace SampleSystem.IntegrationTests.__Support.TestData; +namespace SampleSystem.IntegrationTests._Environment.TestData; public static class DefaultConstants { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Employee.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Employee.cs similarity index 98% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Employee.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Employee.cs index ee2ba26ae..e7e11bbcb 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Employee.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Employee.cs @@ -1,17 +1,16 @@ -using Framework.AutomationCore.RootServiceProviderContainer; +using Anch.SecuritySystem.UserSource; + +using Framework.AutomationCore.RootServiceProviderContainer; using Framework.AutomationCore.Utils; using Framework.Core; - using Microsoft.Extensions.DependencyInjection; using SampleSystem.Domain.Employee; using SampleSystem.Domain.Inline; using SampleSystem.Generated.DTO; -using Anch.SecuritySystem.UserSource; - -namespace SampleSystem.IntegrationTests.__Support.TestData.Helpers; +namespace SampleSystem.IntegrationTests._Environment.TestData.Helpers; public partial class DataHelper { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Init.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Init.cs similarity index 85% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Init.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Init.cs index 9880dc3c6..c695649db 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Init.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Init.cs @@ -2,7 +2,7 @@ using SampleSystem.BLL; -namespace SampleSystem.IntegrationTests.__Support.TestData.Helpers; +namespace SampleSystem.IntegrationTests._Environment.TestData.Helpers; public partial class DataHelper(IServiceProvider rootServiceProvider) : IRootServiceProviderContainer { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Smo.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Smo.cs similarity index 90% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Smo.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Smo.cs index aba44b74b..c80bc235a 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Smo.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Smo.cs @@ -2,7 +2,7 @@ using Microsoft.SqlServer.Management.Smo; -namespace SampleSystem.IntegrationTests.__Support.TestData.Helpers; +namespace SampleSystem.IntegrationTests._Environment.TestData.Helpers; public partial class DataHelper { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Subscriptions.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Subscriptions.cs similarity index 89% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Subscriptions.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Subscriptions.cs index b12ac7be5..6d0ffcc94 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.Subscriptions.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Subscriptions.cs @@ -5,7 +5,7 @@ using Microsoft.Extensions.DependencyInjection; -namespace SampleSystem.IntegrationTests.__Support.TestData.Helpers; +namespace SampleSystem.IntegrationTests._Environment.TestData.Helpers; public partial class DataHelper { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.cs similarity index 99% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.cs index 8263e0f5a..0972644de 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/Helpers/DataHelper.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.cs @@ -14,7 +14,7 @@ using SampleSystem.Generated.DTO; using SampleSystem.WebApiCore.Controllers.Main; -namespace SampleSystem.IntegrationTests.__Support.TestData.Helpers; +namespace SampleSystem.IntegrationTests._Environment.TestData.Helpers; public partial class DataHelper { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/SampleSystemTestPermission.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/SampleSystemTestPermission.cs similarity index 97% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/SampleSystemTestPermission.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/SampleSystemTestPermission.cs index dadb604ce..6a5750ccb 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/SampleSystemTestPermission.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/SampleSystemTestPermission.cs @@ -1,4 +1,6 @@ using Anch.Core; +using Anch.SecuritySystem; +using Anch.SecuritySystem.Testing; using SampleSystem.Domain.BU; using SampleSystem.Domain.Directories; @@ -6,10 +8,7 @@ using SampleSystem.Domain.MU; using SampleSystem.Generated.DTO; -using Anch.SecuritySystem; -using Anch.SecuritySystem.Testing; - -namespace SampleSystem.IntegrationTests.__Support.TestData; +namespace SampleSystem.IntegrationTests._Environment.TestData; public class SampleSystemTestPermission : TestPermission { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/TestBase.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/TestBase.cs similarity index 88% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/TestBase.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/TestBase.cs index 50dc58ca1..6a8c694a8 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/TestBase.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/TestBase.cs @@ -6,11 +6,11 @@ using Microsoft.Extensions.DependencyInjection; using SampleSystem.BLL; -using SampleSystem.IntegrationTests.__Support.TestData.Helpers; -using SampleSystem.IntegrationTests.__Support.WebApi; +using SampleSystem.IntegrationTests._Environment.TestData.Helpers; +using SampleSystem.IntegrationTests._Environment.WebApi; using SampleSystem.WebApiCore.Controllers.Main; -namespace SampleSystem.IntegrationTests.__Support.TestData; +namespace SampleSystem.IntegrationTests._Environment.TestData; public class TestBase(IServiceProvider rootServiceProvider) : IntegrationTestBase(rootServiceProvider), IAsyncLifetime { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/TestDataInitializer.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/TestDataInitializer.cs similarity index 95% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/TestDataInitializer.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/TestDataInitializer.cs index 6c95e61b5..640924f0b 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/TestData/TestDataInitializer.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/TestDataInitializer.cs @@ -1,30 +1,31 @@ -using Framework.AutomationCore.Settings; +using Anch.Core; +using Anch.SecuritySystem; +using Anch.SecuritySystem.Services; +using Anch.SecuritySystem.Testing; + +using Framework.AutomationCore.Settings; using Microsoft.Extensions.Options; using SampleSystem.Domain.Enums; using SampleSystem.Domain.Inline; -using SampleSystem.IntegrationTests.__Support.TestData.Helpers; +using SampleSystem.IntegrationTests._Environment.TestData.Helpers; using SampleSystem.ServiceEnvironment; -using Anch.SecuritySystem; -using Anch.SecuritySystem.Services; -using Anch.SecuritySystem.Testing; - -namespace SampleSystem.IntegrationTests.__Support.TestData; +namespace SampleSystem.IntegrationTests._Environment.TestData; public class TestDataInitializer( SampleSystemInitializer mainInitializer, RootAuthManager authManager, DataHelper dataHelper, IOptions settings, - IRootImpersonateService rootImpersonateService) + IRootImpersonateService rootImpersonateService) : IInitializer { - public async Task InitializeAsync(CancellationToken cancellationToken) => + public async Task Initialize(CancellationToken cancellationToken) => await rootImpersonateService - .WithImpersonateAsync(nameof(TestDataInitializer), async () => await this.InitializeAsyncInternal(cancellationToken)); + .WithImpersonateAsync(nameof(TestDataInitializer), async () => await this.InitializeInternal(cancellationToken)); - public async Task InitializeAsyncInternal(CancellationToken cancellationToken) + public async Task InitializeInternal(CancellationToken cancellationToken) { await mainInitializer.InitializeAsync(cancellationToken); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Utils/SampleSystemTestDatabaseGenerator.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/Utils/SampleSystemTestDatabaseGenerator.cs similarity index 100% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Utils/SampleSystemTestDatabaseGenerator.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/Utils/SampleSystemTestDatabaseGenerator.cs diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Utils/TestIntegrationEventPublisher.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/Utils/TestIntegrationEventPublisher.cs similarity index 79% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Utils/TestIntegrationEventPublisher.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/Utils/TestIntegrationEventPublisher.cs index 45fe0ec04..d3ac44659 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/Utils/TestIntegrationEventPublisher.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/Utils/TestIntegrationEventPublisher.cs @@ -1,6 +1,6 @@ using Bss.Platform.Events.Abstractions; -namespace SampleSystem.IntegrationTests.__Support.Utils; +namespace SampleSystem.IntegrationTests._Environment.Utils; public class TestIntegrationEventPublisher : IIntegrationEventPublisher { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/WebApi/IntegrationWebApi.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/WebApi/IntegrationWebApi.cs similarity index 67% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/WebApi/IntegrationWebApi.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/WebApi/IntegrationWebApi.cs index fe3f904d4..6f1cf7549 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/WebApi/IntegrationWebApi.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/WebApi/IntegrationWebApi.cs @@ -1,8 +1,8 @@ using Framework.AutomationCore.WebApi; -using SampleSystem.IntegrationTests.__Support.TestData; +using SampleSystem.IntegrationTests._Environment.TestData; -namespace SampleSystem.IntegrationTests.__Support.WebApi; +namespace SampleSystem.IntegrationTests._Environment.WebApi; public class IntegrationWebApi(IServiceProvider serviceProvider) : IntegrationWebApiBase(serviceProvider) { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/WebApi/MainAuditWebApi.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/WebApi/MainAuditWebApi.cs similarity index 88% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/WebApi/MainAuditWebApi.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/WebApi/MainAuditWebApi.cs index 5f9e01d28..55b8b021c 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/WebApi/MainAuditWebApi.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/WebApi/MainAuditWebApi.cs @@ -3,7 +3,7 @@ using SampleSystem.WebApiCore.Controllers.Audit; -namespace SampleSystem.IntegrationTests.__Support.WebApi; +namespace SampleSystem.IntegrationTests._Environment.WebApi; public class MainAuditWebApi(IServiceProvider serviceProvider) : WebApiBase(serviceProvider) { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/WebApi/MainWebApi.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/WebApi/MainWebApi.cs similarity index 90% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/WebApi/MainWebApi.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/WebApi/MainWebApi.cs index c7f1fbf62..eca7e4f39 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/WebApi/MainWebApi.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/WebApi/MainWebApi.cs @@ -3,7 +3,7 @@ using SampleSystem.WebApiCore.Controllers.Main; -namespace SampleSystem.IntegrationTests.__Support.WebApi; +namespace SampleSystem.IntegrationTests._Environment.WebApi; public class MainWebApi(IServiceProvider serviceProvider) : WebApiBase(serviceProvider) { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/InitializeAndCleanup.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/InitializeAndCleanup.cs deleted file mode 100644 index 8e05e4e6b..000000000 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/__Support/InitializeAndCleanup.cs +++ /dev/null @@ -1,55 +0,0 @@ -//using Bss.Platform.Events.Abstractions; - -//using Framework.Application.Jobs; -//using Framework.AutomationCore.Environment; -//using Framework.AutomationCore.ServiceEnvironment; - -//using Microsoft.Extensions.Configuration; -//using Microsoft.Extensions.DependencyInjection; -//using Microsoft.Extensions.Hosting.Internal; - -//using SampleSystem.IntegrationTests.__Support.TestData; -//using SampleSystem.IntegrationTests.__Support.TestData.Helpers; -//using SampleSystem.IntegrationTests.__Support.Utils; -//using SampleSystem.ServiceEnvironment; -//using SampleSystem.ServiceEnvironment.DependencyInjection; -//using SampleSystem.ServiceEnvironment.Jobs; -//using SampleSystem.WebApiCore.Controllers.Main; - -//namespace SampleSystem.IntegrationTests.__Support; - -//public class AssemblyFixture : IAsyncLifetime -//{ -// public static readonly TestEnvironment TestEnvironment = new TestEnvironmentBuilder() -// .WithDefaultConfiguration($"{nameof(SampleSystem)}_") -// .WithDatabaseGenerator() -// .WithServiceProviderBuildFunc(GetServices) -// .Build(); - -// private static IServiceCollection GetServices(IConfiguration configuration, IServiceCollection services) => -// services -// .AddGeneralDependencyInjection(configuration, new HostingEnvironment(), s => s.AddExtensions(new SampleSystemNHibernateExtension())) - -// .AddSingleton() - -// .AddIntegrationTests() - -// .AddScoped() - -// .AddSingleton(new JobImpersonateData("sampleSystemTestJob")) -// .AddJobs([typeof(SampleJob).Assembly]) - -// .AddTestControllers([typeof(EmployeeController).Assembly]) - -// .AddSingleton() - -// .AddSingleton(); - -// public Task InitializeAsync() => TestEnvironment.AssemblyInitializeAndCleanup.EnvironmentInitializeAsync(); - -// public async Task DisposeAsync() -// { -// await TestEnvironment.AssemblyInitializeAndCleanup.EnvironmentCleanupAsync(); -// GC.SuppressFinalize(this); -// } -//} diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/appsettings.json b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/testAppSettings.json similarity index 100% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/appsettings.json rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/testAppSettings.json diff --git a/src/_SampleSystem/_Tests/SampleSystem.UnitTests/ExtractConstTests.cs b/src/_SampleSystem/_Tests/SampleSystem.UnitTests/ExtractConstTests.cs index 551b959cd..420f2e9ea 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.UnitTests/ExtractConstTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.UnitTests/ExtractConstTests.cs @@ -13,13 +13,13 @@ public class ExtractConstTests public void NullValueChainExpression_GetDeepMemberConstValue_NotThrowException() { // Arrange - Parameters p = null; - Expression> testExpr = obj => p.Period.StartDate > obj.Period.StartDate; + Parameters? p = null; + Expression> testExpr = obj => p!.Period.StartDate > obj.Period.StartDate; - Action action = () => testExpr.UpdateBase(OverrideHashSetVisitor.Value); - - var exception = Record.Exception(action); + // Act + var exception = Record.Exception(() => testExpr.UpdateBase(OverrideHashSetVisitor.Value)); + // Assert Assert.Null(exception); } From b5a3fd7cfae90041ef5bb0bd587ea1706ac6e5bb Mon Sep 17 00:00:00 2001 From: iatsuta Date: Tue, 28 Apr 2026 14:03:25 +0200 Subject: [PATCH 05/13] upd --- .../ServiceProviderExtensions.cs | 2 -- .../_Environment/NHibTestEnvironment.cs | 22 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ServiceProviderExtensions.cs b/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ServiceProviderExtensions.cs index 50744997a..130a4a0db 100644 --- a/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ServiceProviderExtensions.cs +++ b/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ServiceProviderExtensions.cs @@ -81,8 +81,6 @@ public IServiceCollection AddIntegrationTests(Action)) - .Replace(ServiceDescriptor.KeyedSingleton(ICurrentUser.DefaultKey)) - .AddSecuritySystemTesting(b => b.SetEvaluator(typeof(BssTestingEvaluator<>)) .SetTestRootUserInfo(sp => sp.GetRequiredService>() .Pipe(options => new TestRootUserInfo(options.Value.IntegrationTestUserName)))); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs index c8e60d8dd..c8cffdf1f 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs @@ -9,6 +9,7 @@ using Framework.Application.Jobs; using Framework.AutomationCore.ServiceEnvironment; +using Framework.AutomationCore.Settings; using Framework.Database; using Framework.Database.ConnectionStringSource; @@ -35,12 +36,13 @@ public IServiceProvider BuildServiceProvider(IServiceCollection services) { var configuration = new ConfigurationBuilder().AddJsonFile("testAppSettings.json", false, true).Build(); + var automationFrameworkSettings = new AutomationFrameworkSettings(); + configuration.Bind(nameof(AutomationFrameworkSettings), automationFrameworkSettings); var defaultConnectionString = configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("DefaultConnection string is not configured."); - return services.AddGeneralDependencyInjection(configuration, new HostingEnvironment(), s => s.AddExtensions(new SampleSystemNHibernateExtension())) .AddSingleton() @@ -63,16 +65,14 @@ public IServiceProvider BuildServiceProvider(IServiceCollection services) .SetProvider() .SetEmptySchemaInitializer() .SetSharedTestDataInitializer() - .SetSettings(new TestDatabaseSettings - { - InitMode = DatabaseInitModeHelper.DatabaseInitMode, - DefaultConnectionString = new(defaultConnectionString) - }) - .RebindActualConnection(connectionString => new ManualDefaultConnectionStringSource(connectionString.Value))) - - - .AddDatabaseTesting(dts => dts.SetProvider() - ) + .SetSettings( + new TestDatabaseSettings + { + InitMode = automationFrameworkSettings.DatabaseInitMode, + DefaultConnectionString = new(defaultConnectionString) + }) + .RebindActualConnection(connectionString => + new ManualDefaultConnectionStringSource(connectionString.Value))) .AddValidator() .BuildServiceProvider(new ServiceProviderOptions { ValidateScopes = true, ValidateOnBuild = true }); From d4fe5a502dd08a2f95729f679863be50ba0eb7d7 Mon Sep 17 00:00:00 2001 From: iatsuta Date: Tue, 28 Apr 2026 14:26:47 +0200 Subject: [PATCH 06/13] upd --- .../ServiceProviderExtensions.cs | 10 ++++- .../Settings/AutomationFrameworkSettings.cs | 2 - .../DatabaseUtils/CoreDatabaseUtil.Helper.cs | 4 +- .../Utils/DatabaseUtils/DatabaseContext.cs | 37 ++++++++----------- .../_Environment/NHibTestEnvironment.cs | 5 ++- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ServiceProviderExtensions.cs b/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ServiceProviderExtensions.cs index 130a4a0db..119530a32 100644 --- a/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ServiceProviderExtensions.cs +++ b/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ServiceProviderExtensions.cs @@ -19,6 +19,11 @@ using Anch.SecuritySystem.Testing; using Anch.SecuritySystem.Testing.DependencyInjection; +using Framework.AutomationCore.Utils.DatabaseUtils; +using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; + +using Microsoft.Extensions.Configuration; + namespace Framework.AutomationCore.ServiceEnvironment; public static class ServiceProviderExtensions @@ -72,7 +77,10 @@ public IServiceCollection AddIntegrationTests(Action() + return services.AddSingleton() + + + .AddSingleton() .ReplaceSingletonFrom() .AddScoped() diff --git a/src/AutomationCore/Framework.AutomationCore/Settings/AutomationFrameworkSettings.cs b/src/AutomationCore/Framework.AutomationCore/Settings/AutomationFrameworkSettings.cs index 24bcdf838..c923962ba 100644 --- a/src/AutomationCore/Framework.AutomationCore/Settings/AutomationFrameworkSettings.cs +++ b/src/AutomationCore/Framework.AutomationCore/Settings/AutomationFrameworkSettings.cs @@ -20,8 +20,6 @@ public class AutomationFrameworkSettings public string TempFolder => Path.Combine(this.TestRunServerRootFolder, "temp"); - public string ConnectionStringName { get; set; } = "DefaultConnection"; - public string[] SecondaryDatabases { get; set; } = []; public string[] LocalAdmins { get; set; } = []; diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.Helper.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.Helper.cs index 13e2e0df3..ba172d929 100644 --- a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.Helper.cs +++ b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.Helper.cs @@ -14,7 +14,7 @@ public static string CutInitialCatalog(string inputConnectionString) => private static string GetInitialCatalog(string connectionString) => InitialCatalogRegex.Matches(connectionString).First().Value; - private static Table GetTable(this Server server, string databaseName, string tableName) + private static Table? GetTable(this Server server, string databaseName, string tableName) { var database = server.GetDatabase(databaseName); @@ -43,5 +43,5 @@ private static void SetModeRestrictedUser(this Server server, string databaseNam private static void SetModeMultiUser(this Server server, Microsoft.SqlServer.Management.Smo.Database database) => ExecuteSql(server.ConnectionContext.SqlConnectionObject, $"ALTER DATABASE [{database.Name}] SET MULTI_USER"); - private static Microsoft.SqlServer.Management.Smo.Database GetDatabase(this Server server, string name) => server.Databases.Contains(name) ? server.Databases[name] : null; + private static Microsoft.SqlServer.Management.Smo.Database? GetDatabase(this Server server, string name) => server.Databases.Contains(name) ? server.Databases[name] : null; } diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs index aefdfb771..6ac823da1 100644 --- a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs +++ b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs @@ -2,9 +2,9 @@ using Framework.AutomationCore.Settings; using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; +using Framework.Database; using Microsoft.Data.SqlClient; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Options; using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Smo; @@ -20,31 +20,26 @@ static DatabaseContext() => public DatabaseItem Main { get; } - private readonly Server server; - public Dictionary Secondary { get; } public DatabaseContext( - IConfiguration configuration, + IDefaultConnectionStringSource defaultConnectionStringSource, IOptions settings) - : this(configuration, settings.Value) + : this(defaultConnectionStringSource, settings.Value) { } - private DatabaseContext( - IConfiguration configuration, - AutomationFrameworkSettings settings) + private DatabaseContext(IDefaultConnectionStringSource defaultConnectionStringSource, AutomationFrameworkSettings settings) { - var connectionString = this.GetConnectionString(configuration, settings); + var actualConnectionString = GetConnectionString(defaultConnectionStringSource, settings); this.Main = new DatabaseItem( - connectionString, + actualConnectionString, settings.DatabaseCollation, settings.DbDataDirectory, null, settings.TestsParallelize); - if (settings.SecondaryDatabases != null) { this.Secondary = new Dictionary(); foreach (var database in settings.SecondaryDatabases) @@ -52,7 +47,7 @@ private DatabaseContext( this.Secondary.Add( database, new DatabaseItem( - connectionString, + actualConnectionString, settings.DatabaseCollation, settings.DbDataDirectory, database, @@ -60,7 +55,7 @@ private DatabaseContext( } } - this.server = new Server(new ServerConnection(new SqlConnection( + this.Server = new Server(new ServerConnection(new SqlConnection( CoreDatabaseUtil.CutInitialCatalog(this.Main.ConnectionString)))); } @@ -68,26 +63,24 @@ public Server Server { get { - this.server.Refresh(); - return this.server; + field.Refresh(); + return field; } } - private string GetConnectionString( - IConfiguration configuration, + private static string GetConnectionString( + IDefaultConnectionStringSource defaultConnectionStringSource, AutomationFrameworkSettings settings) { - var connectionString = configuration.GetConnectionString(settings.ConnectionStringName); - if (settings.UseLocalDb) { - connectionString = this.GetLocalDbConnectionString(connectionString, LocalDbInstanceName); + return GetLocalDbConnectionString(defaultConnectionStringSource.ConnectionString, LocalDbInstanceName); } - return connectionString; + return defaultConnectionStringSource.ConnectionString; } - private string GetLocalDbConnectionString(string connectionString, string instanceName) + private static string GetLocalDbConnectionString(string connectionString, string instanceName) => DataSourceRegex.Replace(connectionString, $"Data Source=(localdb)\\{instanceName}"); private static readonly Regex DataSourceRegex = new("Data Source=([^;]*)", RegexOptions.Compiled | RegexOptions.NonBacktracking); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs index c8cffdf1f..9c015f9eb 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs @@ -10,6 +10,8 @@ using Framework.Application.Jobs; using Framework.AutomationCore.ServiceEnvironment; using Framework.AutomationCore.Settings; +using Framework.AutomationCore.Utils.DatabaseUtils; +using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; using Framework.Database; using Framework.Database.ConnectionStringSource; @@ -42,8 +44,9 @@ public IServiceProvider BuildServiceProvider(IServiceCollection services) var defaultConnectionString = configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("DefaultConnection string is not configured."); + return services.AddSingleton(configuration) - return services.AddGeneralDependencyInjection(configuration, new HostingEnvironment(), s => s.AddExtensions(new SampleSystemNHibernateExtension())) + .AddGeneralDependencyInjection(configuration, new HostingEnvironment(), s => s.AddExtensions(new SampleSystemNHibernateExtension())) .AddSingleton() From 5fabb7e809d9a581c75b3e93f604a5f5525cd247 Mon Sep 17 00:00:00 2001 From: iatsuta Date: Tue, 28 Apr 2026 19:39:29 +0200 Subject: [PATCH 07/13] upd --- .../ServiceProviderExtensions.cs | 4 ---- src/Directory.Packages.props | 22 +++++++++---------- .../_Environment/NHibTestEnvironment.cs | 4 +--- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ServiceProviderExtensions.cs b/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ServiceProviderExtensions.cs index 119530a32..e19f039cb 100644 --- a/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ServiceProviderExtensions.cs +++ b/src/AutomationCore/Framework.AutomationCore/ServiceEnvironment/ServiceProviderExtensions.cs @@ -1,7 +1,6 @@ using System.Reflection; using Anch.Core; -using Anch.Core.Auth; using Anch.DependencyInjection; using Framework.Application.Jobs; @@ -12,7 +11,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; using Anch.SecuritySystem; @@ -22,8 +20,6 @@ using Framework.AutomationCore.Utils.DatabaseUtils; using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; -using Microsoft.Extensions.Configuration; - namespace Framework.AutomationCore.ServiceEnvironment; public static class ServiceProviderExtensions diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 5829c55a3..4a479a90d 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -2,17 +2,13 @@ true false - 3.4.1.0 + 3.4.2.0 [1.6.2] - - - - - - - + + + @@ -32,13 +28,17 @@ - + + + + + @@ -64,7 +64,7 @@ - + @@ -75,4 +75,4 @@ - \ No newline at end of file + diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs index 9c015f9eb..aa7c214e5 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs @@ -10,8 +10,6 @@ using Framework.Application.Jobs; using Framework.AutomationCore.ServiceEnvironment; using Framework.AutomationCore.Settings; -using Framework.AutomationCore.Utils.DatabaseUtils; -using Framework.AutomationCore.Utils.DatabaseUtils.Interfaces; using Framework.Database; using Framework.Database.ConnectionStringSource; @@ -67,7 +65,7 @@ public IServiceProvider BuildServiceProvider(IServiceCollection services) .AddDatabaseTesting(dts => dts .SetProvider() .SetEmptySchemaInitializer() - .SetSharedTestDataInitializer() + .SetTestDataInitializer() .SetSettings( new TestDatabaseSettings { From 36f00012d34f7043111db7089e4d3de32e31ee33 Mon Sep 17 00:00:00 2001 From: iatsuta Date: Tue, 28 Apr 2026 19:40:49 +0200 Subject: [PATCH 08/13] upd --- .../PeriodTests.cs | 8 ++-- .../ExpressionParserTests.cs | 5 +-- .../AsyncControllerTests.cs | 5 ++- .../Auth/PrincipalTests.cs | 15 +++++--- .../CurrentUserSourceTests.cs | 10 ++--- .../EmployeeTests.cs | 5 ++- .../ExpandPathTests.cs | 33 ++++++++-------- .../ExtraQueryableSecurityPathTests.cs | 29 +++++++------- .../FixedPropertyValidatorTests.cs | 37 +++++++++--------- .../NotificationCountryTests.cs | 5 ++- .../PrincipalWithInitTests.cs | 4 +- .../RepositoryWithoutSecurityTests.cs | 4 +- .../RestrictionRoleTests.cs | 20 +++++----- .../SecurityContextRestrictionFilterTests.cs | 13 ++++--- .../SecurityRuleTests.cs | 17 +++++---- .../SqlParserTests.cs | 38 ++++++++++--------- .../UniqueGroupTests.cs | 5 ++- .../ValidationTests.cs | 24 +++++++----- .../WrongSecurityMessageTests.cs | 11 +++--- 19 files changed, 155 insertions(+), 133 deletions(-) diff --git a/src/Application/Framework.Application.Tests/PeriodTests.cs b/src/Application/Framework.Application.Tests/PeriodTests.cs index 87c5cff45..be6feb93e 100644 --- a/src/Application/Framework.Application.Tests/PeriodTests.cs +++ b/src/Application/Framework.Application.Tests/PeriodTests.cs @@ -41,10 +41,10 @@ public void GetFinancialYear_MonthOutOfRange_ThrowArgumentOutOfRangeException(in var service = new FinancialYearCalculator(new FinancialYearServiceSettings()); // Act - Action action = () => service.GetFinancialYear(2017, month); + var ex = Record.Exception(() => service.GetFinancialYear(2017, month)); // Assert - Assert.Throws(action); + Assert.IsType(ex); } /// @@ -61,9 +61,9 @@ public void GetFinancialYear_YearOutOfRange_ThrowArgumentOutOfRangeException(int var service = new FinancialYearCalculator(new FinancialYearServiceSettings()); // Act - Action action = () => service.GetFinancialYear(year, month); + var ex = Record.Exception(() => service.GetFinancialYear(year, month)); // Assert - Assert.Throws(action); + Assert.IsType(ex); } } diff --git a/src/Framework.ExpressionParsers.Tests/ExpressionParserTests.cs b/src/Framework.ExpressionParsers.Tests/ExpressionParserTests.cs index 5bb7b2df2..2367fd2b4 100644 --- a/src/Framework.ExpressionParsers.Tests/ExpressionParserTests.cs +++ b/src/Framework.ExpressionParsers.Tests/ExpressionParserTests.cs @@ -10,12 +10,11 @@ public sealed class ExpressionParserTests public void Validate_InvalidExpressionAndErrorsUnWrapped_CorrectException() { // Arrange - var call = () => this.parser.Validate("n => blah"); - // Act - var exception = Assert.Throws(call); + var ex = Record.Exception(() => this.parser.Validate("n => blah")); // Assert + var exception = Assert.IsType(ex); Assert.Equal("Can't parse value: \"n => blah\". Expected format: \"Func\"", exception.Message); var innerException = Assert.IsType(exception.InnerException); Assert.Contains("The name 'blah' does not exist in the current context", innerException.Message); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AsyncControllerTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AsyncControllerTests.cs index 440097ad1..195e27915 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AsyncControllerTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AsyncControllerTests.cs @@ -34,8 +34,9 @@ public async Task TestSaveLocationWithWriteException_ExceptionRaised() var saveDto = new LocationStrictDTO { Name = Guid.NewGuid().ToString(), CloseDate = 30, Code = 12345 }; // Act - Func saveTask = () => asyncControllerEvaluator.EvaluateAsync(c => c.AsyncSaveLocationWithWriteException(saveDto, default)); + var ex = await Record.ExceptionAsync(() => asyncControllerEvaluator.EvaluateAsync(c => c.AsyncSaveLocationWithWriteException(saveDto, default))); - await Assert.ThrowsAsync(saveTask); + // Assert + Assert.IsType(ex); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs index fe3f7b22f..e394d557b 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs @@ -151,10 +151,11 @@ public void RemovePermission_CheckRemoval() // Act this.GetAuthControllerEvaluator().Evaluate(c => c.RemovePermission(permissionIdentity)); - Action call = () => this.GetAuthControllerEvaluator().Evaluate(c => c.GetSimplePermission(permissionIdentity)); + var ex = Record.Exception(() => this.GetAuthControllerEvaluator().Evaluate(c => c.GetSimplePermission(permissionIdentity))); // Assert - Assert.Matches("^Permission with id = \".*\" not found$", Assert.Throws>(call).Message); + var notFoundException = Assert.IsType>(ex); + Assert.Matches("^Permission with id = \".*\" not found$", notFoundException.Message); } [Fact] @@ -164,10 +165,11 @@ public void RemovePrincipalWithRole_CheckException() var principalIdentity = this.GetAuthControllerEvaluator().Evaluate(c => c.GetCurrentPrincipal()).Identity; // Act - var call = () => this.GetAuthControllerEvaluator().Evaluate(c => c.RemovePrincipal(principalIdentity)); + var ex = Record.Exception(() => this.GetAuthControllerEvaluator().Evaluate(c => c.RemovePrincipal(principalIdentity))); // Assert - Assert.Matches("^Removing principal \".*\" must be empty$", Assert.Throws(call).Message); + var securityException = Assert.IsType(ex); + Assert.Matches("^Removing principal \".*\" must be empty$", securityException.Message); } [Fact] @@ -180,9 +182,10 @@ public void RemovePrincipal_CheckRemoval() // Act this.GetAuthControllerEvaluator().Evaluate(c => c.RemovePrincipal(principalIdentity)); - var call = () => this.GetAuthControllerEvaluator().Evaluate(c => c.GetSimplePrincipal(principalIdentity)); + var ex = Record.Exception(() => this.GetAuthControllerEvaluator().Evaluate(c => c.GetSimplePrincipal(principalIdentity))); // Assert - Assert.Matches("^Principal with id = \".*\" not found$", Assert.Throws>(call).Message); + var notFoundException = Assert.IsType>(ex); + Assert.Matches("^Principal with id = \".*\" not found$", notFoundException.Message); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs index b5a40009d..7444c1e98 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs @@ -40,16 +40,14 @@ public void TryGetCurrentUserWithoutEmployee_ExceptionRaised() var randomName = TextRandomizer.RandomString(10); // Act - var action = () => - { + var ex = Record.Exception(() => this.Evaluate( DBSessionMode.Read, randomName, - ctx => ctx.CurrentEmployeeSource.CurrentUser.Id); - }; + ctx => ctx.CurrentEmployeeSource.CurrentUser.Id)); // Assert - var exception = Assert.Throws(action); - Assert.Equal($"{nameof(Employee)} \"{randomName}\" not found", exception.Message); + var userSourceException = Assert.IsType(ex); + Assert.Equal($"{nameof(Employee)} \"{randomName}\" not found", userSourceException.Message); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs index 63d89db78..8185eede2 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs @@ -332,12 +332,13 @@ public void ChangeEmployeeWithoutVersionInfo_RaisedStateException() var employeeIdentity = this.DataHelper.SaveEmployee(Guid.NewGuid()); // Act - var call = new Action( + var ex = Record.Exception( () => employeeController.Evaluate( c => c.UpdateEmployee(new EmployeeUpdateDTO { Id = employeeIdentity.Id, Interphone = Maybe.Return("1234") }))); // Assert - Assert.Equal($"Object '{nameof(Employee)}' was updated or deleted by another transaction", Assert.Throws(call).Message); + var staleDomainObjectStateException = Assert.IsType(ex); + Assert.Equal($"Object '{nameof(Employee)}' was updated or deleted by another transaction", staleDomainObjectStateException.Message); } [Fact] diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs index 2ffcce079..158436543 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExpandPathTests.cs @@ -17,11 +17,13 @@ public void LiftToNullableContainsExt_ShouldNotThrowException() // Act var action = new Action(() => - { - var res = this.Evaluate(DBSessionMode.Read, context => context.Logics.Employee.GetListBy(employee => employee.CoreBusinessUnit.Period.ContainsExt(period.EndDate ?? period.StartDate))); + { + var res = this.Evaluate( + DBSessionMode.Read, + context => context.Logics.Employee.GetListBy(employee => employee.CoreBusinessUnit.Period.ContainsExt(period.EndDate ?? period.StartDate))); - return; - }); + return; + }); // Assert action(); @@ -34,11 +36,11 @@ public void LiftToNullableBinaryExpression_ShouldNotThrowException() // Act var action = new Action(() => - { - var res = this.Evaluate(DBSessionMode.Read, context => context.Logics.Employee.GetListBy(employee => employee.LocationCode == null)); + { + var res = this.Evaluate(DBSessionMode.Read, context => context.Logics.Employee.GetListBy(employee => employee.LocationCode == null)); - return; - }); + return; + }); // Assert action(); @@ -51,16 +53,15 @@ public void LiftToNullablePeriodIntersect_ShouldNotThrowException() // Act var action = new Action(() => - { - var currentMonth = this.TimeProvider.GetCurrentMonth(); + { + var currentMonth = this.TimeProvider.GetCurrentMonth(); - var res = this.Evaluate( - DBSessionMode.Read, - context => context.Logics.Employee.GetListBy( - employee => employee.CoreBusinessUnitPeriod.IsIntersected(currentMonth))); + var res = this.Evaluate( + DBSessionMode.Read, + context => context.Logics.Employee.GetListBy(employee => employee.CoreBusinessUnitPeriod.IsIntersected(currentMonth))); - return; - }); + return; + }); // Assert action(); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs index 0a4c160d4..d91c5f197 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs @@ -64,21 +64,20 @@ await this.AuthManager.For(this.TestEmployee.Id).SetRoleAsync( public void TestExtraQueryableSecurityPath_LoadedWithExtraQueryableFilter() { // Arrange - var createProviderFunc = FuncHelper.Create( - (ISampleSystemBLLContext context) => - { - var extraQueryableSecurity = context.Logics.Location.GetUnsecureQueryable(); - - var extraSecurityPath = SecurityPath.Create(e => e.CoreBusinessUnit, true) - .And(e => e.Location, true) - .And( - e => extraQueryableSecurity.Where( - l => l == e.Location && e.Location.Id == this.loc1Ident.Id), true); - - return context.ServiceProvider.GetRequiredService>().Create( - SampleSystemSecurityOperation.EmployeeView, - extraSecurityPath); - }); + var createProviderFunc = FuncHelper.Create((ISampleSystemBLLContext context) => + { + var extraQueryableSecurity = context.Logics.Location.GetUnsecureQueryable(); + + var extraSecurityPath = SecurityPath.Create(e => e.CoreBusinessUnit, true) + .And(e => e.Location, true) + .And( + e => extraQueryableSecurity.Where(l => l == e.Location && e.Location.Id == this.loc1Ident.Id), + true); + + return context.ServiceProvider.GetRequiredService>().Create( + SampleSystemSecurityOperation.EmployeeView, + extraSecurityPath); + }); // Act var items = this.Evaluate( diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs index bd56756f6..f442da96e 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs @@ -16,17 +16,18 @@ public void PrimitiveImmutablePropertyChanged_RaisedValidationError() new TestImmutableObjStrictDTO { TestImmutablePrimitiveProperty = "AAA" })); // Act - var changePropertyAction = () => - { - var dto = testImmutableObjController.Evaluate(c => c.GetRichTestImmutableObj(identity)); - dto.TestImmutablePrimitiveProperty = "BBB"; - testImmutableObjController.Evaluate(c => c.SaveTestImmutableObj(dto.ToStrict())); - }; + var ex = Record.Exception(() => + { + var dto = testImmutableObjController.Evaluate(c => c.GetRichTestImmutableObj(identity)); + dto.TestImmutablePrimitiveProperty = "BBB"; + testImmutableObjController.Evaluate(c => c.SaveTestImmutableObj(dto.ToStrict())); + }); // Assert + var validationException = Assert.IsType(ex); Assert.Equal( $"{nameof(TestImmutableObj.TestImmutablePrimitiveProperty)} field in {nameof(TestImmutableObj)} can't be changed", - Assert.Throws(changePropertyAction).Message); + validationException.Message); } [Fact] @@ -38,17 +39,18 @@ public void ReferenceImmutablePropertyChanged_RaisedValidationError() var identity = testImmutableObjController.Evaluate(c => c.SaveTestImmutableObj(new TestImmutableObjStrictDTO { })); // Act - var changePropertyAction = () => - { - var dto = testImmutableObjController.Evaluate(c => c.GetRichTestImmutableObj(identity)); - dto.TestImmutableRefProperty = this.DataHelper.GetCurrentEmployee(); - testImmutableObjController.Evaluate(c => c.SaveTestImmutableObj(dto.ToStrict())); - }; + var ex = Record.Exception(() => + { + var dto = testImmutableObjController.Evaluate(c => c.GetRichTestImmutableObj(identity)); + dto.TestImmutableRefProperty = this.DataHelper.GetCurrentEmployee(); + testImmutableObjController.Evaluate(c => c.SaveTestImmutableObj(dto.ToStrict())); + }); // Assert - Assert.Equal( + var validationException = Assert.IsType(ex); + Assert.Equal( $"{nameof(TestImmutableObj.TestImmutableRefProperty)} field in {nameof(TestImmutableObj)} can't be changed", - Assert.Throws(changePropertyAction).Message); + validationException.Message); } [Fact] @@ -73,12 +75,13 @@ public void ImmutablePropertyChangedByIntegration_RaisedValidationError() var identity = integrationTestImmutableObjController.Evaluate(c => c.SaveTestImmutableObj(new TestImmutableObjIntegrationRichDTO { TestImmutablePrimitiveProperty = "AAA", Id = Guid.NewGuid() })); // Act - Action changePropertyAction = () => integrationTestImmutableObjController.Evaluate(c => c.SaveTestImmutableObj(new TestImmutableObjIntegrationRichDTO { TestImmutablePrimitiveProperty = "BBB", Id = identity.Id })); + var ex = Record.Exception(() => integrationTestImmutableObjController.Evaluate(c => c.SaveTestImmutableObj(new TestImmutableObjIntegrationRichDTO { TestImmutablePrimitiveProperty = "BBB", Id = identity.Id }))); // Assert + var validationException = Assert.IsType(ex); Assert.Equal( $"{nameof(TestImmutableObj.TestImmutablePrimitiveProperty)} field in {nameof(TestImmutableObj)} can't be changed", - Assert.Throws(changePropertyAction).Message); + validationException.Message); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs index e06be6df3..17c03c7d3 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs @@ -129,9 +129,10 @@ public void EmulateFailureCountryModification_RaisedException() var configController = this.GetConfigurationControllerEvaluator(DefaultConstants.NOTIFICATION_ADMIN); // Act - var call = new Action(() => configController.Evaluate(c => c.ProcessModifications(1000))); + var ex = Record.Exception(() => configController.Evaluate(c => c.ProcessModifications(1000))); // Assert - Assert.Equal("Both arguments (previous and current) can't be null", Assert.Throws(call).Message); + var argumentException = Assert.IsType(ex); + Assert.Equal("Both arguments (previous and current) can't be null", argumentException.Message); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs index cd78a8c59..c68cbc873 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs @@ -102,6 +102,8 @@ public void CreateDuplicatePermission_ValidationError() }; // Assert - Assert.Contains(expectedErrorMessage, Assert.Throws(call).Message); + var ex = Record.Exception(() => call()); + var validationException = Assert.IsType(ex); + Assert.Contains(expectedErrorMessage, validationException.Message); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryWithoutSecurityTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryWithoutSecurityTests.cs index baac3105e..f0591366d 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryWithoutSecurityTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RepositoryWithoutSecurityTests.cs @@ -27,9 +27,9 @@ public async Task GetDataFromUnsecurityRepository_TryLoadWithSecurity_DataLoadFa var controllerEvaluator = this.GetControllerEvaluator(); // Act - Func saveAction = () => controllerEvaluator.EvaluateAsync(c => c.TestFaultSave(default)); + var ex = await Record.ExceptionAsync(() => controllerEvaluator.EvaluateAsync(c => c.TestFaultSave(default))); // Assert - await Assert.ThrowsAsync(saveAction); + Assert.IsType(ex); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs index 23a7a8173..b03ebc7ae 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs @@ -84,14 +84,15 @@ public void TryCreatePermissionWithInvalidSecurityContext_ExceptionRaised() var location = this.DataHelper.SaveLocation(); // Act - var action = () => - this.AuthManager.For().SetRole( - new SampleSystemTestPermission( - SampleSystemSecurityRole.RestrictionRole, - location: location)); + var ex = Record.Exception(() => + this.AuthManager.For().SetRole( + new SampleSystemTestPermission( + SampleSystemSecurityRole.RestrictionRole, + location: location))); // Assert - Assert.Contains($"Invalid SecurityContextType: {nameof(Location)}", Assert.Throws(action).Message); + var validationException = Assert.IsType(ex); + Assert.Contains($"Invalid SecurityContextType: {nameof(Location)}", validationException.Message); } [Fact] @@ -169,12 +170,13 @@ public void TryCreatePermissionWithoutRequiredSecurityContext_ExceptionRaised() var location = this.DataHelper.SaveLocation(); // Act - var action = () => this.AuthManager.For().SetRole( - new SampleSystemTestPermission(SampleSystemSecurityRole.RequiredRestrictionRole, location: location)); + var ex = Record.Exception(() => this.AuthManager.For().SetRole( + new SampleSystemTestPermission(SampleSystemSecurityRole.RequiredRestrictionRole, location: location))); // Assert + var validationException = Assert.IsType(ex); Assert.Contains( $"{nameof(Framework.Authorization.Domain.Permission)} must contain the required contexts: {nameof(BusinessUnit)}", - Assert.Throws(action).Message); + validationException.Message); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs index 435549e26..754459e70 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs @@ -42,14 +42,15 @@ public void CreatePermissionWithRestrictionFilter_ApplyInvalidBusinessUnit_Excep // Arrange // Act - var action = () => this.AuthManager.For(this.employee.Id).SetRole( - new SampleSystemTestPermission(SampleSystemSecurityRole.WithRestrictionFilterRole) - { - BusinessUnit = this.defaultBu - }); + var ex = Record.Exception(() => this.AuthManager.For(this.employee.Id).SetRole( + new SampleSystemTestPermission(SampleSystemSecurityRole.WithRestrictionFilterRole) + { + BusinessUnit = this.defaultBu + })); // Assert - Assert.Contains($"SecurityContext: '{this.defaultBu.Id}' denied by filter", Assert.Throws(action).Message); + var validationException = Assert.IsType(ex); + Assert.Contains($"SecurityContext: '{this.defaultBu.Id}' denied by filter", validationException.Message); } [Fact] diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs index dd4a13da6..7d2fb2d99 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs @@ -64,16 +64,17 @@ public void ApplyOverrideFaultMessageRule_FaultMessageChanged() var testSecurityRule = DomainSecurityRule.AccessDenied.WithOverrideAccessDeniedMessage(faultMessage); // Act - var action = () => this.Evaluate( - DBSessionMode.Read, - ctx => - { - var bll = ctx.Logics.EmployeeFactory.Create(testSecurityRule); + var ex = Record.Exception(() => this.Evaluate( + DBSessionMode.Read, + ctx => + { + var bll = ctx.Logics.EmployeeFactory.Create(testSecurityRule); - bll.CheckAccess(ctx.CurrentEmployeeSource.CurrentUser); - }); + bll.CheckAccess(ctx.CurrentEmployeeSource.CurrentUser); + })); // Assert - Assert.Equal(faultMessage, Assert.Throws(action).Message); + var accessDeniedException = Assert.IsType(ex); + Assert.Equal(faultMessage, accessDeniedException.Message); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs index 5763b9a22..c0e7bace1 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs @@ -18,10 +18,11 @@ public void SaveNullIntoNotNullProperty_RequiredConstraintDALException() var testObject = new SqlParserTestObj(); // Act - var action = () => this.EvaluateWrite(context => { context.Logics.SqlParserTestObj.Save(testObject); }); + var ex = Record.Exception(() => this.EvaluateWrite(context => { context.Logics.SqlParserTestObj.Save(testObject); })); // Assert - Assert.Contains("The field \'notNullColumn\' of type SqlParserTestObj must be initialized", Assert.Throws(action).Message); + var requiredConstraintException = Assert.IsType(ex); + Assert.Contains("The field \'notNullColumn\' of type SqlParserTestObj must be initialized", requiredConstraintException.Message); } [Fact] @@ -32,15 +33,16 @@ public void SaveNotUniqueProperty_UniqueViolationConstraintDALException() var testObject2 = new SqlParserTestObj { UniqueColumn = "1", NotNullColumn = "2" }; // Act - var action = () => this.EvaluateWrite( - context => - { - context.Logics.SqlParserTestObj.Save(testObject1); - context.Logics.SqlParserTestObj.Save(testObject2); - }); + var ex = Record.Exception(() => this.EvaluateWrite( + context => + { + context.Logics.SqlParserTestObj.Save(testObject1); + context.Logics.SqlParserTestObj.Save(testObject2); + })); // Assert - Assert.Contains("SqlParserTestObj with same:\'UniqueColumn\' already exists", Assert.Throws(action).Message); + var uniqueViolationException = Assert.IsType(ex); + Assert.Contains("SqlParserTestObj with same:\'UniqueColumn\' already exists", uniqueViolationException.Message); } [Fact] @@ -58,14 +60,15 @@ public void RemoveLinkedObject_RemoveLinkedObjectsDALException() }); // Act - var action = () => this.EvaluateWrite( - context => - { - context.Logics.SqlParserTestObj.Remove(testObject); - }); + var ex = Record.Exception(() => this.EvaluateWrite( + context => + { + context.Logics.SqlParserTestObj.Remove(testObject); + })); // Assert - Assert.Contains($"{nameof(SqlParserTestObj)} cannot be removed because it is used in {nameof(SqlParserTestObjContainer)}", Assert.Throws(action).Message); + var removeLinkedObjectsException = Assert.IsType(ex); + Assert.Contains($"{nameof(SqlParserTestObj)} cannot be removed because it is used in {nameof(SqlParserTestObjContainer)}", removeLinkedObjectsException.Message); } [Fact] @@ -95,9 +98,10 @@ public void RemoveHRDepartment_HasEmployeeWithHRDepartment_CorrectExceptionMessa var fullEmployee = employeeController.Evaluate(c => c.GetFullEmployee(employeeIdentity)); // Act - var action = () => hRDepartmentController.Evaluate(c => c.RemoveHRDepartment(fullEmployee.HRDepartment.Identity)); + var ex = Record.Exception(() => hRDepartmentController.Evaluate(c => c.RemoveHRDepartment(fullEmployee.HRDepartment.Identity))); // Assert - Assert.Equal($"{nameof(HRDepartment)} cannot be removed because it is used in {nameof(Employee)}", Assert.Throws(action).Message); + var removeLinkedObjectsException = Assert.IsType(ex); + Assert.Equal($"{nameof(HRDepartment)} cannot be removed because it is used in {nameof(Employee)}", removeLinkedObjectsException.Message); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs index cb3069a2c..7cd5dc7b8 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs @@ -16,9 +16,10 @@ public void UniqueGroup_NonUniqueEntityCreated_ErrorUsesCustomName() this.DataHelper.SaveRoleRoleDegreeLink(role, roleDegree); // Act - var action = new Action(() => this.DataHelper.SaveRoleRoleDegreeLink(role, roleDegree)); + var ex = Record.Exception(() => this.DataHelper.SaveRoleRoleDegreeLink(role, roleDegree)); // Assert - Assert.Equal("Role-Seniority link with same:'Role,Seniority' already exists", Assert.Throws(action).Message); + var uniqueViolationException = Assert.IsType(ex); + Assert.Equal("Role-Seniority link with same:'Role,Seniority' already exists", uniqueViolationException.Message); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs index c31efb176..251212f05 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs @@ -13,10 +13,10 @@ public void ValidateByDB_ValidationException() this.DataHelper.SaveEmployee("John Doe", "JD"); // Act - Action call = () => this.DataHelper.SaveEmployee("John Doe", "JD"); + var ex = Record.Exception(() => this.DataHelper.SaveEmployee("John Doe", "JD")); // Assert - Assert.Throws(call); + Assert.IsType(ex); } [Fact] @@ -25,10 +25,11 @@ public void ValidateByClassAttribute_ValidationException() // Arrange // Act - Action call = () => this.DataHelper.SaveEmployee(pin: 1234); + var ex = Record.Exception(() => this.DataHelper.SaveEmployee(pin: 1234)); // Assert - Assert.Equal("Employee Pin could not be set as '1234'", Assert.Throws(call).Message); + var validationException = Assert.IsType(ex); + Assert.Equal("Employee Pin could not be set as '1234'", validationException.Message); } [Fact] @@ -39,10 +40,11 @@ public void ValidateByConcreteValidator_ValidationException() this.DataHelper.SaveEmployee(externalId: externalId); // Act - Action call = () => this.DataHelper.SaveEmployee(externalId: externalId); + var ex = Record.Exception(() => this.DataHelper.SaveEmployee(externalId: externalId)); // Assert - Assert.Equal($"Employee with ExternalId '{externalId}' already exists.", Assert.Throws(call).Message); + var validationException = Assert.IsType(ex); + Assert.Equal($"Employee with ExternalId '{externalId}' already exists.", validationException.Message); } [Fact] @@ -53,10 +55,11 @@ public void ValidateByGlobalValidator_ValidationException() this.DataHelper.SaveEmployee(pin: pin); // Act - Action call = () => this.DataHelper.SaveEmployee(pin: pin); + var ex = Record.Exception(() => this.DataHelper.SaveEmployee(pin: pin)); // Assert - Assert.Equal($"Employee with Pin '{pin}' already exists.", Assert.Throws(call).Message); + var validationException = Assert.IsType(ex); + Assert.Equal($"Employee with Pin '{pin}' already exists.", validationException.Message); } [Fact] @@ -81,9 +84,10 @@ public void Validate_HasInvalidVirtualPropertyMarkedWithAttribute_ShouldThrow() var invalidDate = DateTime.MinValue; // Act - Action call = () => this.DataHelper.SaveEmployee(externalId: externalId, validateVirtualProp: invalidDate); + var ex = Record.Exception(() => this.DataHelper.SaveEmployee(externalId: externalId, validateVirtualProp: invalidDate)); // Assert - Assert.Equal("Employee has ValidateVirtualProp value was too overflow for a DateTime", Assert.Throws(call).Message); + var validationException = Assert.IsType(ex); + Assert.Equal("Employee has ValidateVirtualProp value was too overflow for a DateTime", validationException.Message); } } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs index c18347708..a03108b86 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs @@ -36,14 +36,15 @@ private void UseSecurityRule_WithoutSecurity_ErrorMessageCorrected(SecurityRule //Arrange // Act - var action = () => this.Evaluate( - DBSessionMode.Read, - TestPrincipalName, - ctx => ctx.Logics.EmployeeFactory.Create(securityRule).CheckAccess(ctx.CurrentEmployeeSource.CurrentUser)); + var ex = Record.Exception(() => this.Evaluate( + DBSessionMode.Read, + TestPrincipalName, + ctx => ctx.Logics.EmployeeFactory.Create(securityRule).CheckAccess(ctx.CurrentEmployeeSource.CurrentUser))); // Assert + var accessDeniedException = Assert.IsType(ex); Assert.Equal( $"You have no permissions to access object with type = '{nameof(Employee)}' (id = '{TestPrincipalId}', securityRule = '{securityRule}')", - Assert.Throws(action).Message); + accessDeniedException.Message); } } From e0acdd9ee9b848fa7bafe7940a3fbe4ae4102fa9 Mon Sep 17 00:00:00 2001 From: iatsuta Date: Wed, 29 Apr 2026 20:13:47 +0200 Subject: [PATCH 09/13] upd --- src/Directory.Packages.props | 2 +- .../_Environment/NHibTestEnvironment.cs | 43 +++++++++++++------ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 4a479a90d..035130514 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -2,7 +2,7 @@ true false - 3.4.2.0 + 3.4.3.0 [1.6.2] diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs index aa7c214e5..5b94f225d 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs @@ -32,19 +32,39 @@ namespace SampleSystem.IntegrationTests._Environment; public class NHibTestEnvironment : ITestEnvironment { - public IServiceProvider BuildServiceProvider(IServiceCollection services) + private readonly IConfiguration configuration; + + private readonly AutomationFrameworkSettings settings = new(); + + private readonly TestDatabaseSettings databaseSettings; + + public NHibTestEnvironment() { - var configuration = new ConfigurationBuilder().AddJsonFile("testAppSettings.json", false, true).Build(); + var settingsFileName = "testAppSettings.json"; + + this.configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile(settingsFileName, false, true) + .AddJsonFile($"{Environment.MachineName}.{settingsFileName}", true) + .AddEnvironmentVariables(nameof(SampleSystem)).Build(); - var automationFrameworkSettings = new AutomationFrameworkSettings(); - configuration.Bind(nameof(AutomationFrameworkSettings), automationFrameworkSettings); + this.configuration.Bind(this.settings); - var defaultConnectionString = configuration.GetConnectionString("DefaultConnection") + var defaultConnectionString = this.configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("DefaultConnection string is not configured."); - return services.AddSingleton(configuration) + this.databaseSettings = new TestDatabaseSettings { InitMode = this.settings.DatabaseInitMode, DefaultConnectionString = new(defaultConnectionString) }; + } + + public bool AllowParallelization => this.settings.TestsParallelize; + + public IServiceProvider BuildServiceProvider(IServiceCollection services) + { + services.AddOptions(); + + return services.AddSingleton(this.configuration) - .AddGeneralDependencyInjection(configuration, new HostingEnvironment(), s => s.AddExtensions(new SampleSystemNHibernateExtension())) + .AddGeneralDependencyInjection(this.configuration, new HostingEnvironment(), s => s.AddExtensions(new SampleSystemNHibernateExtension())) .AddSingleton() @@ -66,14 +86,9 @@ public IServiceProvider BuildServiceProvider(IServiceCollection services) .SetProvider() .SetEmptySchemaInitializer() .SetTestDataInitializer() - .SetSettings( - new TestDatabaseSettings - { - InitMode = automationFrameworkSettings.DatabaseInitMode, - DefaultConnectionString = new(defaultConnectionString) - }) + .SetSettings(this.databaseSettings) .RebindActualConnection(connectionString => - new ManualDefaultConnectionStringSource(connectionString.Value))) + new ManualDefaultConnectionStringSource(connectionString.Value))) .AddValidator() .BuildServiceProvider(new ServiceProviderOptions { ValidateScopes = true, ValidateOnBuild = true }); From 033507d798a840be8ff0b5b0905c52d593a809c7 Mon Sep 17 00:00:00 2001 From: iatsuta Date: Wed, 29 Apr 2026 21:07:43 +0200 Subject: [PATCH 10/13] up --- .../AuditTests.cs | 2 +- .../Auth/PrincipalTests.cs | 8 +-- .../AuthPerfomanceTest.cs | 8 +-- .../AuthPerformanceTests.cs | 8 +-- .../BUProjectionTests.cs | 14 ++--- .../BusinessUnitTests.cs | 16 +++--- .../CurrentUserManyRelativePathTests.cs | 2 +- .../CurrentUserSourceTests.cs | 2 +- .../ChangeIndexesStrategyTests.cs | 10 ++-- ...UniqueGroupDatabaseScriptGeneratorTests.cs | 4 +- .../DependencySecurityTests.cs | 6 +-- .../EmployeeProjectionTests.cs | 20 +++---- .../EmployeeTests.cs | 22 ++++---- .../ExtraQueryableSecurityPathTests.cs | 16 +++--- .../FixedPropertyValidatorTests.cs | 2 +- ...ionPrincipalsByHierarchicalContextTests.cs | 26 +++++----- .../ManagmentUnitFluentMappingTests.cs | 2 +- .../ManualAndLegacyProjectionSecurityTests.cs | 10 ++-- .../NhibArrayContainsTest.cs | 2 +- .../PrincipalWithInitTests.cs | 8 +-- .../RestrictionRoleTests.cs | 6 +-- .../SecurityContextRestrictionFilterTests.cs | 6 +-- .../SecurityPathTests.cs | 2 +- .../SecurityRuleTests.cs | 4 +- .../SqlParserTests.cs | 10 ++-- .../MetadataSubscriptionSystemServiceTests.cs | 18 +++---- .../UniqueGroupTests.cs | 8 +-- .../ValidationTests.cs | 18 +++---- .../VirtualPermissionTests.cs | 4 +- .../WebApi/EmployeeTests.cs | 2 +- .../WrongSecurityMessageTests.cs | 2 +- .../_Environment/NHibTestEnvironment.cs | 2 +- ...er.Employee.cs => DataManager.Employee.cs} | 2 +- ...DataHelper.Init.cs => DataManager.Init.cs} | 2 +- .../{DataHelper.Smo.cs => DataManager.Smo.cs} | 2 +- ...ptions.cs => DataManager.Subscriptions.cs} | 2 +- .../Helpers/{DataHelper.cs => DataManager.cs} | 2 +- .../_Environment/TestData/TestBase.cs | 2 +- .../TestData/TestDataInitializer.cs | 52 +++++++++---------- 39 files changed, 167 insertions(+), 167 deletions(-) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/{DataHelper.Employee.cs => DataManager.Employee.cs} (99%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/{DataHelper.Init.cs => DataManager.Init.cs} (73%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/{DataHelper.Smo.cs => DataManager.Smo.cs} (95%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/{DataHelper.Subscriptions.cs => DataManager.Subscriptions.cs} (95%) rename src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/{DataHelper.cs => DataManager.cs} (99%) diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuditTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuditTests.cs index 46c9dc9eb..a6588bb9c 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuditTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuditTests.cs @@ -268,7 +268,7 @@ public void CrateNewBu_AuditBuLoadedFromCustomMapping() this.AuthManager.For(testUser).LoginAs(); // Act - var newBu = this.DataHelper.SaveBusinessUnit(); + var newBu = this.DataManager.SaveBusinessUnit(); // Assert diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs index e394d557b..cd837f2e0 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Auth/PrincipalTests.cs @@ -22,7 +22,7 @@ public void AddPermission_CheckAddition() { // Arrange var authorizationController = this.GetAuthControllerEvaluator(); - var currentUser = this.DataHelper.GetCurrentEmployee(); + var currentUser = this.DataManager.GetCurrentEmployee(); var businessRoleIdentity = authorizationController.Evaluate(c => c.GetSimpleBusinessRoleByName(SampleSystemSecurityRole.SecretariatNotification.Name)).Identity; @@ -45,7 +45,7 @@ public void SavePrincipal_CheckCreateon() { // Arrange var authorizationController = this.GetAuthControllerEvaluator(); - var currentUser = this.DataHelper.GetCurrentEmployee(); + var currentUser = this.DataManager.GetCurrentEmployee(); var businessRoleIdentity = authorizationController.Evaluate(c => c.GetSimpleBusinessRoleByName(SampleSystemSecurityRole.SecretariatNotification.Name)).Identity; @@ -71,7 +71,7 @@ public void SavePrincipal_CheckCreateon() public void SavePrincipal_CheckPrincipalChanges() { // Arrange - var currentUser = this.DataHelper.GetCurrentEmployee(); + var currentUser = this.DataManager.GetCurrentEmployee(); var principalStrict = new PrincipalStrictDTO { Name = Name }; this.GetAuthControllerEvaluator().Evaluate(c => c.SavePrincipal(principalStrict)); @@ -94,7 +94,7 @@ public void SavePrincipal_CheckPrincipalChanges() public void PermissionDelegate_CheckChanges() { // Arrange - var currentUser = this.DataHelper.GetCurrentEmployee(); + var currentUser = this.DataManager.GetCurrentEmployee(); var businessRoleIdentity = this.GetAuthControllerEvaluator().Evaluate(c => c.GetSimpleBusinessRoleByName(SampleSystemSecurityRole.SecretariatNotification.Name)).Identity; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs index cab01105a..d7b7247bf 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerfomanceTest.cs @@ -34,13 +34,13 @@ public class AuthPerformanceTest(IServiceProvider rootServiceProvider) : TestBas protected override async ValueTask InitializeAsync(CancellationToken ct) { - this.fbuSource = [null, .. Enumerable.Range(0, Size - 1).Select(_ => (BusinessUnitIdentityDTO?)this.DataHelper.SaveBusinessUnit())]; + this.fbuSource = [null, .. Enumerable.Range(0, Size - 1).Select(_ => (BusinessUnitIdentityDTO?)this.DataManager.SaveBusinessUnit())]; - this.mbuSource = [null, .. Enumerable.Range(0, Size - 1).Select(_ => (ManagementUnitIdentityDTO?)this.DataHelper.SaveManagementUnit())]; + this.mbuSource = [null, .. Enumerable.Range(0, Size - 1).Select(_ => (ManagementUnitIdentityDTO?)this.DataManager.SaveManagementUnit())]; - this.locationSource = [null, .. Enumerable.Range(0, Size - 1).Select(_ => (LocationIdentityDTO?)this.DataHelper.SaveLocation())]; + this.locationSource = [null, .. Enumerable.Range(0, Size - 1).Select(_ => (LocationIdentityDTO?)this.DataManager.SaveLocation())]; - this.employeeSource = [null, this.DataHelper.SaveEmployee()]; + this.employeeSource = [null, this.DataManager.SaveEmployee()]; await this.AuthManager.For(PrincipalName).CreatePrincipalAsync(ct); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs index 2189c1f8e..0b26fd8b7 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/AuthPerformanceTests.cs @@ -23,13 +23,13 @@ public class AuthPerformanceTests(IServiceProvider rootServiceProvider) : TestBa protected override async ValueTask InitializeAsync(CancellationToken ct) { - var genLoc = Enumerable.Range(0, Limit).ToList(i => this.DataHelper.SaveLocation()); + var genLoc = Enumerable.Range(0, Limit).ToList(i => this.DataManager.SaveLocation()); - var genEmployee = Enumerable.Range(0, Limit).ToList(i => this.DataHelper.SaveEmployee()); + var genEmployee = Enumerable.Range(0, Limit).ToList(i => this.DataManager.SaveEmployee()); - var genBu = Enumerable.Range(0, Limit).ToList(i => this.DataHelper.SaveBusinessUnit()); + var genBu = Enumerable.Range(0, Limit).ToList(i => this.DataManager.SaveBusinessUnit()); - var genMbu = Enumerable.Range(0, Limit).ToList(i => this.DataHelper.SaveManagementUnit()); + var genMbu = Enumerable.Range(0, Limit).ToList(i => this.DataManager.SaveManagementUnit()); var genObjects = this.EvaluateWrite(ctx => { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs index ddeee0768..7f3b9940c 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BUProjectionTests.cs @@ -16,28 +16,28 @@ public class BUProjectionTests(IServiceProvider rootServiceProvider) : TestBase( protected override async ValueTask InitializeAsync(CancellationToken ct) { - var buTypeId = this.DataHelper.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_ID); + var buTypeId = this.DataManager.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_ID); - var luxoftBuId = this.DataHelper.SaveBusinessUnit( + var luxoftBuId = this.DataManager.SaveBusinessUnit( id: DefaultConstants.BUSINESS_UNIT_PARENT_COMPANY_ID, name: DefaultConstants.BUSINESS_UNIT_PARENT_COMPANY_NAME, type: buTypeId); - var costBuId = this.DataHelper.SaveBusinessUnit( + var costBuId = this.DataManager.SaveBusinessUnit( id: DefaultConstants.BUSINESS_UNIT_PARENT_CC_ID, name: DefaultConstants.BUSINESS_UNIT_PARENT_CC_NAME, type: buTypeId, parent: luxoftBuId); - var profitBuId = this.DataHelper.SaveBusinessUnit( + var profitBuId = this.DataManager.SaveBusinessUnit( id: DefaultConstants.BUSINESS_UNIT_PARENT_PC_ID, name: DefaultConstants.BUSINESS_UNIT_PARENT_PC_NAME, type: buTypeId, parent: luxoftBuId); - var empId1 = this.DataHelper.SaveEmployee(login: TestEmployee0Login, coreBusinessUnit: costBuId, nameEng: new Fio { FirstName = "AA" }); - var empId2 = this.DataHelper.SaveEmployee(login: TestEmployee1Login, coreBusinessUnit: costBuId, nameEng: new Fio { FirstName = "BB" }); - var empId3 = this.DataHelper.SaveEmployee(login: TestEmployee2Login, coreBusinessUnit: profitBuId, nameEng: new Fio { FirstName = "CC" }); + var empId1 = this.DataManager.SaveEmployee(login: TestEmployee0Login, coreBusinessUnit: costBuId, nameEng: new Fio { FirstName = "AA" }); + var empId2 = this.DataManager.SaveEmployee(login: TestEmployee1Login, coreBusinessUnit: costBuId, nameEng: new Fio { FirstName = "BB" }); + var empId3 = this.DataManager.SaveEmployee(login: TestEmployee2Login, coreBusinessUnit: profitBuId, nameEng: new Fio { FirstName = "CC" }); this.Evaluate( DBSessionMode.Write, diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs index 17bd7630e..d6fb07a6f 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/BusinessUnitTests.cs @@ -29,20 +29,20 @@ public class BusinessUnitTests(IServiceProvider rootServiceProvider) : TestBase( protected override async ValueTask InitializeAsync(CancellationToken ct) { - var buTypeId = this.DataHelper.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_ID); + var buTypeId = this.DataManager.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_ID); - var luxoftBuId = this.DataHelper.SaveBusinessUnit( + var luxoftBuId = this.DataManager.SaveBusinessUnit( id: DefaultConstants.BUSINESS_UNIT_PARENT_COMPANY_ID, name: DefaultConstants.BUSINESS_UNIT_PARENT_COMPANY_NAME, type: buTypeId); - this.DataHelper.SaveBusinessUnit( + this.DataManager.SaveBusinessUnit( id: DefaultConstants.BUSINESS_UNIT_PARENT_CC_ID, name: DefaultConstants.BUSINESS_UNIT_PARENT_CC_NAME, type: buTypeId, parent: luxoftBuId); - this.DataHelper.SaveBusinessUnit( + this.DataManager.SaveBusinessUnit( id: DefaultConstants.BUSINESS_UNIT_PARENT_PC_ID, name: DefaultConstants.BUSINESS_UNIT_PARENT_PC_NAME, type: buTypeId, @@ -114,8 +114,8 @@ public void GetFullBusinessUnitsTreeTwoTestInOne() public void LoadTreeWithMiddlePermission_RootParentLoadedWithViewMode() { // Arrange - var parentBu = this.DataHelper.SaveBusinessUnit(parentIsNeeded: false); - var childBu = this.DataHelper.SaveBusinessUnit(parent: parentBu); + var parentBu = this.DataManager.SaveBusinessUnit(parentIsNeeded: false); + var childBu = this.DataManager.SaveBusinessUnit(parent: parentBu); this.ClearIntegrationEvents(); @@ -162,9 +162,9 @@ private void TestGetFullBusinessUnitsTree() private void CreateBigBuTree() { - var buAccountId = this.DataHelper.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_ACCOUNT_ID); + var buAccountId = this.DataManager.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_ACCOUNT_ID); - this.DataHelper + this.DataManager .EvaluateWrite(context => { var period = new Period( diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs index 7a2649e41..1b473cccc 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserManyRelativePathTests.cs @@ -19,7 +19,7 @@ protected override async ValueTask InitializeAsync(CancellationToken ct) { this.testEmployeeIdents = - Enumerable.Range(0, 3).Select(_ => this.DataHelper.SaveEmployee().Id).ToArray(); + Enumerable.Range(0, 3).Select(_ => this.DataManager.SaveEmployee().Id).ToArray(); this.testObj = this.EvaluateWrite( ctx => diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs index 7444c1e98..5ddd711ac 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/CurrentUserSourceTests.cs @@ -16,7 +16,7 @@ public void TryGetCurrentUserWithEmployee_CurrentUserResolved() { // Arrange var randomName = TextRandomizer.RandomString(10); - var employeeId = this.DataHelper.SaveEmployee(login: randomName).Id; + var employeeId = this.DataManager.SaveEmployee(login: randomName).Id; // Act var result = this.Evaluate( diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs index 9433e9a3f..83fbd33bf 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/ChangeIndexesStrategyTests.cs @@ -19,7 +19,7 @@ public void GenerateLocal_ColumnHasIndexWithIncludedColumns_PreventsDefaultIndex var generator = new DbGeneratorTest(); var tableName = "Employee"; - var table = this.DataHelper.GetTable(this.DatabaseContext.Main.DatabaseName, tableName); + var table = this.DataManager.GetTable(this.DatabaseContext.Main.DatabaseName, tableName); var baseIndexName = "IX_Employee_coreBusinessUnitId"; var newIndexName = "IX_Employee_coreBusinessUnitId_inc"; @@ -47,7 +47,7 @@ public void GenerateLocal_ColumnHasIndexWithIncludedColumns_PreventsDefaultIndex this.DatabaseContext.Main.Password), skipFrameworkDatabases: true); - var changedTable = this.DataHelper.GetTable(this.DatabaseContext.Main.DatabaseName, tableName); + var changedTable = this.DataManager.GetTable(this.DatabaseContext.Main.DatabaseName, tableName); // Assert var indexes = changedTable.Indexes.ToList(); @@ -62,7 +62,7 @@ public void GenerateLocal_IgnoredIndex_NotCreated() var generator = new DbGeneratorTest(); var tableName = "Employee"; - var table = this.DataHelper.GetTable(this.DatabaseContext.Main.DatabaseName, tableName); + var table = this.DataManager.GetTable(this.DatabaseContext.Main.DatabaseName, tableName); var ignoredIndexName = "IX_Employee_hRDepartmentId"; @@ -78,7 +78,7 @@ public void GenerateLocal_IgnoredIndex_NotCreated() this.DatabaseContext.Main.Password), ignoredIndexes: [ignoredIndexName], skipFrameworkDatabases: true); - var changedTable = this.DataHelper.GetTable(this.DatabaseContext.Main.DatabaseName, tableName); + var changedTable = this.DataManager.GetTable(this.DatabaseContext.Main.DatabaseName, tableName); // Assert Assert.DoesNotContain(changedTable.Indexes, x => x.Name == ignoredIndexName); @@ -99,7 +99,7 @@ public void GenerateLocal_UniqueFieldForFK_NoDuplicates() this.DatabaseContext.Main.Password), skipFrameworkDatabases: true); - var changedTable = this.DataHelper.GetTable(this.DatabaseContext.Main.DatabaseName, "Employee"); + var changedTable = this.DataManager.GetTable(this.DatabaseContext.Main.DatabaseName, "Employee"); // Assert Assert.DoesNotContain(changedTable.Indexes, x => x.Name == "IX_ChildEntity_parentId"); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs index 8a722b9a3..cac84ee6e 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DBGeneration/UniqueGroupDatabaseScriptGeneratorTests.cs @@ -20,7 +20,7 @@ public void GenerateLocal_UniqueIndexExistsWithLessColumns_RecreatesColumns() var tableName = "RoleRoleDegreeLink"; - var table = this.DataHelper.GetTable(this.DatabaseContext.Main.DatabaseName, tableName); + var table = this.DataManager.GetTable(this.DatabaseContext.Main.DatabaseName, tableName); var indexName = "unilink_RoleRoleDegreeLink"; @@ -42,7 +42,7 @@ public void GenerateLocal_UniqueIndexExistsWithLessColumns_RecreatesColumns() this.DatabaseContext.Main.Password), skipFrameworkDatabases: true); - var changedTable = this.DataHelper.GetTable(this.DatabaseContext.Main.DatabaseName, tableName); + var changedTable = this.DataManager.GetTable(this.DatabaseContext.Main.DatabaseName, tableName); // changedTable.Indexes.Refresh(); var indexes = changedTable.Indexes.ToList(); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs index 4fa5064e6..7d7989062 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/DependencySecurityTests.cs @@ -32,11 +32,11 @@ public class DependencySecurityTests(IServiceProvider rootServiceProvider) : Tes protected override async ValueTask InitializeAsync(CancellationToken ct) { - this.bu1Ident = this.DataHelper.SaveBusinessUnit(); + this.bu1Ident = this.DataManager.SaveBusinessUnit(); - this.bu2Ident = this.DataHelper.SaveBusinessUnit(); + this.bu2Ident = this.DataManager.SaveBusinessUnit(); - this.DataHelper.SaveEmployee(login: TestEmployeeLogin); + this.DataManager.SaveEmployee(login: TestEmployeeLogin); await this.AuthManager.For(TestEmployeeLogin).SetRoleAsync(new SampleSystemTestPermission(SampleSystemSecurityRole.SeManager, this.bu2Ident), ct); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs index 47ca3db92..f71a84587 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeProjectionTests.cs @@ -18,29 +18,29 @@ public class EmployeeProjectionTests(IServiceProvider rootServiceProvider) : Tes protected override async ValueTask InitializeAsync(CancellationToken ct) { - var buTypeId = this.DataHelper.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_ID); + var buTypeId = this.DataManager.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_ID); - var luxoftBuId = this.DataHelper.SaveBusinessUnit( + var luxoftBuId = this.DataManager.SaveBusinessUnit( id: DefaultConstants.BUSINESS_UNIT_PARENT_COMPANY_ID, name: DefaultConstants.BUSINESS_UNIT_PARENT_COMPANY_NAME, type: buTypeId); - var costBuId = this.DataHelper.SaveBusinessUnit( + var costBuId = this.DataManager.SaveBusinessUnit( id: DefaultConstants.BUSINESS_UNIT_PARENT_CC_ID, name: DefaultConstants.BUSINESS_UNIT_PARENT_CC_NAME, type: buTypeId, parent: luxoftBuId); - var profitBuId = this.DataHelper.SaveBusinessUnit( + var profitBuId = this.DataManager.SaveBusinessUnit( id: DefaultConstants.BUSINESS_UNIT_PARENT_PC_ID, name: DefaultConstants.BUSINESS_UNIT_PARENT_PC_NAME, type: buTypeId, parent: luxoftBuId); - this.DataHelper.SaveEmployee(login: ProjectionPrincipalName, coreBusinessUnit: costBuId); - this.DataHelper.SaveEmployee(login: TestEmployee1Login, coreBusinessUnit: costBuId); - this.DataHelper.SaveEmployee(login: TestEmployee2Login, coreBusinessUnit: profitBuId); - this.DataHelper.SaveEmployee(login: TestEmployee3Login, coreBusinessUnit: costBuId); + this.DataManager.SaveEmployee(login: ProjectionPrincipalName, coreBusinessUnit: costBuId); + this.DataManager.SaveEmployee(login: TestEmployee1Login, coreBusinessUnit: costBuId); + this.DataManager.SaveEmployee(login: TestEmployee2Login, coreBusinessUnit: profitBuId); + this.DataManager.SaveEmployee(login: TestEmployee3Login, coreBusinessUnit: costBuId); await this.AuthManager.For(ProjectionPrincipalName).SetRoleAsync( new SampleSystemTestPermission( @@ -56,7 +56,7 @@ await this.AuthManager.For(ProjectionPrincipalName).SetRoleAsync( public void EmployeeProjectionTest() { // Arrange - var identity = this.DataHelper.SaveEmployee(Guid.NewGuid()); + var identity = this.DataManager.SaveEmployee(Guid.NewGuid()); var controller = this.GetControllerEvaluator(); // Act @@ -122,7 +122,7 @@ public void EmployeeProjectionSortingTest() foreach (var login in logins) { - this.DataHelper.SaveEmployee(login: login); + this.DataManager.SaveEmployee(login: login); } var expected = logins.Reverse().ToArray(Maybe.Return); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs index 8185eede2..fdc9dcc24 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/EmployeeTests.cs @@ -34,7 +34,7 @@ public void GetEmployeeFromDB_FilterByAge_ReturnNotNulRecords() */ // Arrange - this.DataHelper.SaveEmployee(Guid.NewGuid(), age: 10); + this.DataManager.SaveEmployee(Guid.NewGuid(), age: 10); CoreDatabaseUtil.ExecuteSql( this.DatabaseContext.Main.ConnectionString, "INSERT INTO [app].[Employee] ([id], age) VALUES (NewId(), null)"); @@ -54,7 +54,7 @@ public void AddNewEmployee_CheckEmployeeSaved() { // Arrange var employeeController = this.MainWebApi.Employee; - var employeeIdentity = this.DataHelper.SaveEmployee(Guid.NewGuid()); + var employeeIdentity = this.DataManager.SaveEmployee(Guid.NewGuid()); // Act var employees = employeeController.Evaluate(c => c.GetSimpleEmployees()); @@ -72,7 +72,7 @@ public void GetEmployeeByOData_ContainsForNumberProperty_OnlyRequestedDataInTheR foreach (var pin in new[] { 123, 456 }) { - var employeeIdentity = this.DataHelper.SaveEmployee(Guid.NewGuid()); + var employeeIdentity = this.DataManager.SaveEmployee(Guid.NewGuid()); var employee = employeeController.Evaluate(c => c.GetSimpleEmployee(employeeIdentity)); employee.Pin = pin; employeeController.Evaluate(c => c.SaveEmployee(employee.ToStrict())); @@ -107,7 +107,7 @@ public void GetEmployeeByOData_TakeTestWithoutSorting_OnlyRequestedDataInTheResu foreach (var item in idToPinMap) { - var employeeIdentity = this.DataHelper.SaveEmployee(item.Key); + var employeeIdentity = this.DataManager.SaveEmployee(item.Key); var employee = employeeController.Evaluate(c => c.GetSimpleEmployee(employeeIdentity)); employee.Pin = item.Value; employeeController.Evaluate(c => c.SaveEmployee(employee.ToStrict())); @@ -148,7 +148,7 @@ public void GetEmployeeByOData_TakeAndSkipTestWithoutSorting_OnlyRequestedDataIn foreach (var item in idToPinMap) { - var employeeIdentity = this.DataHelper.SaveEmployee(item.Key); + var employeeIdentity = this.DataManager.SaveEmployee(item.Key); var employee = employeeController.Evaluate(c => c.GetSimpleEmployee(employeeIdentity)); employee.Pin = item.Value; employeeController.Evaluate(c => c.SaveEmployee(employee.ToStrict())); @@ -179,7 +179,7 @@ public void GetEmployeeByOData_TakeAndSkipTestWithSorting_OnlyRequestedDataInThe foreach (var pin in new[] { 123, 456 }) { - var employeeIdentity = this.DataHelper.SaveEmployee(Guid.NewGuid()); + var employeeIdentity = this.DataManager.SaveEmployee(Guid.NewGuid()); var employee = employeeController.Evaluate(c => c.GetSimpleEmployee(employeeIdentity)); employee.Pin = pin; employeeController.Evaluate(c => c.SaveEmployee(employee.ToStrict())); @@ -199,7 +199,7 @@ public void GetEmployeeByOData_TakeAndSkipTestWithSorting_OnlyRequestedDataInThe public void ForceDomainTypeEvent_ForceEmployeeSaveEvent_ContainsEventEmployee() { // Arrange - var employeeIdentity = this.DataHelper.SaveEmployee(Guid.NewGuid()); + var employeeIdentity = this.DataManager.SaveEmployee(Guid.NewGuid()); var configFacade = this.GetConfigurationControllerEvaluator(); @@ -228,7 +228,7 @@ public void ChangeEmployee_ProcessModifications_ContainsNotification() // Arrange var employeeController = this.MainWebApi.Employee; - var employeeIdentity = this.DataHelper.SaveEmployee(Guid.NewGuid()); + var employeeIdentity = this.DataManager.SaveEmployee(Guid.NewGuid()); var employeeVersion = employeeController.Evaluate(c => c.GetSimpleEmployee(employeeIdentity)).Version; this.ClearNotifications(); @@ -264,7 +264,7 @@ public void ChangeEmployee_ProcessModifications_ChangedUnprocessedCount() { // Arrange var employeeController = this.MainWebApi.Employee; - var employeeIdentity = this.DataHelper.SaveEmployee(Guid.NewGuid()); + var employeeIdentity = this.DataManager.SaveEmployee(Guid.NewGuid()); var employeeVersion = employeeController.Evaluate(c => c.GetSimpleEmployee(employeeIdentity)).Version; this.ClearNotifications(); @@ -298,7 +298,7 @@ public void ChangeEmployee_ContainsAribaEvent() { // Arrange var employeeController = this.MainWebApi.Employee; - var employeeIdentity = this.DataHelper.SaveEmployee(Guid.NewGuid()); + var employeeIdentity = this.DataManager.SaveEmployee(Guid.NewGuid()); var employeeVersion = employeeController.Evaluate(c => c.GetSimpleEmployee(employeeIdentity)).Version; this.ClearIntegrationEvents(); @@ -329,7 +329,7 @@ public void ChangeEmployeeWithoutVersionInfo_RaisedStateException() { // Arrange var employeeController = this.MainWebApi.Employee; - var employeeIdentity = this.DataHelper.SaveEmployee(Guid.NewGuid()); + var employeeIdentity = this.DataManager.SaveEmployee(Guid.NewGuid()); // Act var ex = Record.Exception( diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs index d91c5f197..6cef89e13 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ExtraQueryableSecurityPathTests.cs @@ -36,15 +36,15 @@ public class ExtraQueryableSecurityPathTests(IServiceProvider rootServiceProvide protected override async ValueTask InitializeAsync(CancellationToken ct) { - this.bu1Ident = this.DataHelper.SaveBusinessUnit(); + this.bu1Ident = this.DataManager.SaveBusinessUnit(); - this.bu2Ident = this.DataHelper.SaveBusinessUnit(); + this.bu2Ident = this.DataManager.SaveBusinessUnit(); - this.loc1Ident = this.DataHelper.SaveLocation(name: "Loc 1 (ExtraQueryableSecurityPathTests)"); + this.loc1Ident = this.DataManager.SaveLocation(name: "Loc 1 (ExtraQueryableSecurityPathTests)"); - this.loc2Ident = this.DataHelper.SaveLocation(name: "Loc 2 (ExtraQueryableSecurityPathTests)"); + this.loc2Ident = this.DataManager.SaveLocation(name: "Loc 2 (ExtraQueryableSecurityPathTests)"); - this.TestEmployee = this.DataHelper.SaveEmployee(login: "EQSP SecurityTester"); + this.TestEmployee = this.DataManager.SaveEmployee(login: "EQSP SecurityTester"); await this.AuthManager.For(this.TestEmployee.Id).SetRoleAsync( [ @@ -53,11 +53,11 @@ await this.AuthManager.For(this.TestEmployee.Id).SetRoleAsync( ], ct); - this.TestEmp1 = this.DataHelper.SaveEmployee(coreBusinessUnit: this.bu1Ident, location: this.loc1Ident); + this.TestEmp1 = this.DataManager.SaveEmployee(coreBusinessUnit: this.bu1Ident, location: this.loc1Ident); - this.TestEmp2 = this.DataHelper.SaveEmployee(coreBusinessUnit: this.bu2Ident, location: this.loc1Ident); + this.TestEmp2 = this.DataManager.SaveEmployee(coreBusinessUnit: this.bu2Ident, location: this.loc1Ident); - this.TestEmp3 = this.DataHelper.SaveEmployee(coreBusinessUnit: this.bu2Ident, location: this.loc2Ident); + this.TestEmp3 = this.DataManager.SaveEmployee(coreBusinessUnit: this.bu2Ident, location: this.loc2Ident); } [Fact] diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs index f442da96e..28738a85b 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/FixedPropertyValidatorTests.cs @@ -42,7 +42,7 @@ public void ReferenceImmutablePropertyChanged_RaisedValidationError() var ex = Record.Exception(() => { var dto = testImmutableObjController.Evaluate(c => c.GetRichTestImmutableObj(identity)); - dto.TestImmutableRefProperty = this.DataHelper.GetCurrentEmployee(); + dto.TestImmutableRefProperty = this.DataManager.GetCurrentEmployee(); testImmutableObjController.Evaluate(c => c.SaveTestImmutableObj(dto.ToStrict())); }); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs index 9eb3a2e0b..fab46f119 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs @@ -46,19 +46,19 @@ public class GetNotificationPrincipalsByHierarchicalContextTests(IServiceProvide protected override async ValueTask InitializeAsync(CancellationToken ct) { - this.rootBusinessUnit = this.DataHelper.SaveBusinessUnit(id: DefaultConstants.BUSINESS_UNIT_PARENT_CC_ID); - this.child_1_0_BusinessUnit = this.DataHelper.SaveBusinessUnit(parent: this.rootBusinessUnit); - this.child_1_1_BusinessUnit = this.DataHelper.SaveBusinessUnit(parent: this.child_1_0_BusinessUnit); - this.child_2_0_BusinessUnit = this.DataHelper.SaveBusinessUnit(parent: this.rootBusinessUnit); - this.child_2_1_BusinessUnit = this.DataHelper.SaveBusinessUnit(parent: this.child_2_0_BusinessUnit); - - this.rootManagementUnit = this.DataHelper.SaveManagementUnit(id: DefaultConstants.MANAGEMENT_UNIT_PARENT_COMPANY_ID); - this.child_1_0_ManagementUnit = this.DataHelper.SaveManagementUnit(parent: this.rootManagementUnit); - this.child_1_1_ManagementUnit = this.DataHelper.SaveManagementUnit(parent: this.child_1_0_ManagementUnit); - this.child_2_0_ManagementUnit = this.DataHelper.SaveManagementUnit(parent: this.rootManagementUnit); - this.child_2_1_ManagementUnit = this.DataHelper.SaveManagementUnit(parent: this.child_2_0_ManagementUnit); - - this.rootEmployee = this.DataHelper.SaveEmployee(); + this.rootBusinessUnit = this.DataManager.SaveBusinessUnit(id: DefaultConstants.BUSINESS_UNIT_PARENT_CC_ID); + this.child_1_0_BusinessUnit = this.DataManager.SaveBusinessUnit(parent: this.rootBusinessUnit); + this.child_1_1_BusinessUnit = this.DataManager.SaveBusinessUnit(parent: this.child_1_0_BusinessUnit); + this.child_2_0_BusinessUnit = this.DataManager.SaveBusinessUnit(parent: this.rootBusinessUnit); + this.child_2_1_BusinessUnit = this.DataManager.SaveBusinessUnit(parent: this.child_2_0_BusinessUnit); + + this.rootManagementUnit = this.DataManager.SaveManagementUnit(id: DefaultConstants.MANAGEMENT_UNIT_PARENT_COMPANY_ID); + this.child_1_0_ManagementUnit = this.DataManager.SaveManagementUnit(parent: this.rootManagementUnit); + this.child_1_1_ManagementUnit = this.DataManager.SaveManagementUnit(parent: this.child_1_0_ManagementUnit); + this.child_2_0_ManagementUnit = this.DataManager.SaveManagementUnit(parent: this.rootManagementUnit); + this.child_2_1_ManagementUnit = this.DataManager.SaveManagementUnit(parent: this.child_2_0_ManagementUnit); + + this.rootEmployee = this.DataManager.SaveEmployee(); } [Fact] diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManagmentUnitFluentMappingTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManagmentUnitFluentMappingTests.cs index 0baa48e23..6b27c0a05 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManagmentUnitFluentMappingTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManagmentUnitFluentMappingTests.cs @@ -13,7 +13,7 @@ public class ManagmentUnitFluentMappingTests(IServiceProvider rootServiceProvide public void CheckBusinessUnitSecondaryAccess_HasAccess() { // Arrange - var employeeId = this.DataHelper.SaveEmployee(); + var employeeId = this.DataManager.SaveEmployee(); this.Evaluate( DBSessionMode.Write, diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs index a9c436880..27803d50c 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ManualAndLegacyProjectionSecurityTests.cs @@ -22,17 +22,17 @@ public class ManualAndLegacyProjectionSecurityTests(IServiceProvider rootService protected override async ValueTask InitializeAsync(CancellationToken ct) { - this.bu1Ident = this.DataHelper.SaveBusinessUnit(); + this.bu1Ident = this.DataManager.SaveBusinessUnit(); - this.bu2Ident = this.DataHelper.SaveBusinessUnit(); + this.bu2Ident = this.DataManager.SaveBusinessUnit(); - this.DataHelper.SaveEmployee(login: TestEmployeeLogin); + this.DataManager.SaveEmployee(login: TestEmployeeLogin); await this.AuthManager.For(TestEmployeeLogin).SetRoleAsync(new SampleSystemTestPermission(SampleSystemSecurityRole.SeManager, this.bu2Ident), ct); - this.TestEmp1 = this.DataHelper.SaveEmployee(coreBusinessUnit: this.bu1Ident); + this.TestEmp1 = this.DataManager.SaveEmployee(coreBusinessUnit: this.bu1Ident); - this.TestEmp2 = this.DataHelper.SaveEmployee(coreBusinessUnit: this.bu2Ident); + this.TestEmp2 = this.DataManager.SaveEmployee(coreBusinessUnit: this.bu2Ident); } [Fact] diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibArrayContainsTest.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibArrayContainsTest.cs index 173067b42..073684484 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibArrayContainsTest.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NhibArrayContainsTest.cs @@ -19,7 +19,7 @@ public void LinqContainsOverArray_TranslatedAndExecutedCorrectly() { // Arrange var name = TextRandomizer.UniqueString("BusinessUnit"); - var bu = this.DataHelper.SaveBusinessUnit(name: name); + var bu = this.DataManager.SaveBusinessUnit(name: name); var arr1 = new[] { bu.Id }; var arr2 = new[] { BusinessUnitStatus.Current }; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs index c68cbc873..e4c6c29c1 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/PrincipalWithInitTests.cs @@ -26,20 +26,20 @@ protected override async ValueTask InitializeAsync(CancellationToken ct) { this.testPeriod = this.TimeProvider.GetCurrentMonth(); - var buTypeId = this.DataHelper.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_ID); + var buTypeId = this.DataManager.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_ID); - var luxoftBuId = this.DataHelper.SaveBusinessUnit( + var luxoftBuId = this.DataManager.SaveBusinessUnit( id: DefaultConstants.BUSINESS_UNIT_PARENT_COMPANY_ID, name: DefaultConstants.BUSINESS_UNIT_PARENT_COMPANY_NAME, type: buTypeId); - var costBuId = this.DataHelper.SaveBusinessUnit( + var costBuId = this.DataManager.SaveBusinessUnit( id: DefaultConstants.BUSINESS_UNIT_PARENT_CC_ID, name: DefaultConstants.BUSINESS_UNIT_PARENT_CC_NAME, type: buTypeId, parent: luxoftBuId); - var profitBuId = this.DataHelper.SaveBusinessUnit( + var profitBuId = this.DataManager.SaveBusinessUnit( id: DefaultConstants.BUSINESS_UNIT_PARENT_PC_ID, name: DefaultConstants.BUSINESS_UNIT_PARENT_PC_NAME, type: buTypeId, diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs index b03ebc7ae..07aa875e6 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/RestrictionRoleTests.cs @@ -64,7 +64,7 @@ public void TryCreateEmptyPermission_PermissionCreated() public void TryCreatePermissionWithCorrectSecurityContext_PermissionCreated() { // Arrange - var businessUnit = this.DataHelper.SaveBusinessUnit(); + var businessUnit = this.DataManager.SaveBusinessUnit(); // Act var action = () => @@ -81,7 +81,7 @@ public void TryCreatePermissionWithCorrectSecurityContext_PermissionCreated() public void TryCreatePermissionWithInvalidSecurityContext_ExceptionRaised() { // Arrange - var location = this.DataHelper.SaveLocation(); + var location = this.DataManager.SaveLocation(); // Act var ex = Record.Exception(() => @@ -167,7 +167,7 @@ public void GetRestrictionObjectsWithConditionRule_RestrictionApplied() public void TryCreatePermissionWithoutRequiredSecurityContext_ExceptionRaised() { // Arrange - var location = this.DataHelper.SaveLocation(); + var location = this.DataManager.SaveLocation(); // Act var ex = Record.Exception(() => this.AuthManager.For().SetRole( diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs index 754459e70..eff658d11 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityContextRestrictionFilterTests.cs @@ -29,11 +29,11 @@ public class SecurityContextRestrictionFilterTests(IServiceProvider rootServiceP protected override async ValueTask InitializeAsync(CancellationToken ct) { - this.employee = this.DataHelper.SaveEmployee(login: this.employeeLogin); + this.employee = this.DataManager.SaveEmployee(login: this.employeeLogin); - this.defaultBu = this.DataHelper.SaveBusinessUnit(); + this.defaultBu = this.DataManager.SaveBusinessUnit(); - this.buWithAllowedFilter = this.DataHelper.SaveBusinessUnit(allowedForFilterRole: true); + this.buWithAllowedFilter = this.DataManager.SaveBusinessUnit(allowedForFilterRole: true); } [Fact] diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityPathTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityPathTests.cs index 87f55c4f9..89e570512 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityPathTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityPathTests.cs @@ -18,7 +18,7 @@ public class SecurityPathTests(IServiceProvider rootServiceProvider) : TestBase( public void SecurityPathWithContext_EmployeeWithoutContextRestrictions_EmployeeShouldHaveAccess() { // Arrange - var employeeIdentity = this.DataHelper.SaveEmployee(Guid.NewGuid()); + var employeeIdentity = this.DataManager.SaveEmployee(Guid.NewGuid()); // Act var result = this.Evaluate( diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs index 7d2fb2d99..f62182a17 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SecurityRuleTests.cs @@ -23,9 +23,9 @@ public async Task ApplyExceptRule_CurrentUserExcepted() // Arrange var testSecurityRule = SecurityRole.Administrator.Except(DomainSecurityRule.CurrentUser); - var testOtherEmployeeId = this.DataHelper.SaveEmployee().Id; + var testOtherEmployeeId = this.DataManager.SaveEmployee().Id; - var currentEmployeeId = this.DataHelper.GetCurrentEmployee().Id; + var currentEmployeeId = this.DataManager.GetCurrentEmployee().Id; var testObjectIdents = await this.EvaluateAsync( DBSessionMode.Write, diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs index c0e7bace1..53c224889 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SqlParserTests.cs @@ -78,22 +78,22 @@ public void RemoveHRDepartment_HasEmployeeWithHRDepartment_CorrectExceptionMessa var employeeController = this.MainWebApi.Employee; var hRDepartmentController = this.GetControllerEvaluator(); - var buTypeId = this.DataHelper.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_ID); + var buTypeId = this.DataManager.SaveBusinessUnitType(DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_ID); - var luxoftBuId = this.DataHelper.SaveBusinessUnit( + var luxoftBuId = this.DataManager.SaveBusinessUnit( id: DefaultConstants.BUSINESS_UNIT_PARENT_COMPANY_ID, name: DefaultConstants.BUSINESS_UNIT_PARENT_COMPANY_NAME, type: buTypeId); - var costBuId = this.DataHelper.SaveBusinessUnit( + var costBuId = this.DataManager.SaveBusinessUnit( id: DefaultConstants.BUSINESS_UNIT_PARENT_CC_ID, name: DefaultConstants.BUSINESS_UNIT_PARENT_CC_NAME, type: buTypeId, parent: luxoftBuId); - var location = this.DataHelper.SaveLocation(name: "testLocation"); + var location = this.DataManager.SaveLocation(name: "testLocation"); - var employeeIdentity = this.DataHelper.SaveEmployee(login: "value", coreBusinessUnit: costBuId, location: location); + var employeeIdentity = this.DataManager.SaveEmployee(login: "value", coreBusinessUnit: costBuId, location: location); var fullEmployee = employeeController.Evaluate(c => c.GetFullEmployee(employeeIdentity)); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs index caa43fa15..9a3a0488d 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs @@ -23,7 +23,7 @@ public void SubscriptionFromMetadataShouldBeSent() var employee = this.CreateEmployee(); // Act - var results = this.DataHelper.ProcessSubscription(employee, employee); + var results = this.DataManager.ProcessSubscription(employee, employee); var errors = results.GetErrors().ToList(); var expectedNotifications = this.GetNotifications() @@ -39,11 +39,11 @@ public void SubscriptionFromMetadataShouldBeSent() public void RazorTemplateImpl_SubscriptionFromMetadataShouldBeSent() { // Arrange - var employee = this.DataHelper.SaveEmployee("Chuck Norris"); + var employee = this.DataManager.SaveEmployee("Chuck Norris"); var message = @"String.Concat it is good choice for Chuck Norris."; // Act - var results = this.DataHelper.ProcessSubscription(employee, employee); + var results = this.DataManager.ProcessSubscription(employee, employee); var errors = results.GetErrors().ToList(); var expectedNotifications = this.GetNotifications() @@ -67,7 +67,7 @@ public void LocalRazorTemplate_SubscriptionFromMetadataShouldBeSent() var message = $"

Hi there!!!

{Environment.NewLine}My test employee Name: John Doe {Environment.NewLine}Date: 21 Oct 2015"; // Act - var results = this.DataHelper.ProcessSubscription(employee, employee); + var results = this.DataManager.ProcessSubscription(employee, employee); var errors = results.GetErrors().ToList(); var expectedNotifications = this.GetNotifications() @@ -91,7 +91,7 @@ public void AttachTest() var content = Encoding.UTF8.GetBytes("Hello world!"); // Act - this.DataHelper.ProcessSubscription(employee, employee); + this.DataManager.ProcessSubscription(employee, employee); var expectedNotifications = this.GetNotifications() .Where(n => n.From == "Attachment@luxoft.com"); @@ -115,7 +115,7 @@ public void AttachTemplateEvaluatorTest() var content = "Hello world! John Doe "; // Act - this.DataHelper.ProcessSubscription(employee, employee); + this.DataManager.ProcessSubscription(employee, employee); var expectedNotifications = this.GetNotifications().Where(n => n.From == "AttachmentTemplateEvaluator@luxoft.com"); @@ -138,7 +138,7 @@ public void AttachInlinedTest() var messageTemplate = @" John Doe
"; // Act - this.DataHelper.ProcessSubscription(employee, employee); + this.DataManager.ProcessSubscription(employee, employee); var expectedNotifications = this.GetNotifications() .Where(n => n.From == "InlineAttach@luxoft.com"); @@ -156,7 +156,7 @@ public void DateModelCreateSubscriptionTest() // Arrange // Act - this.DataHelper.ProcessSubscription(null, new DateModel { Year = 2019 }); + this.DataManager.ProcessSubscription(null, new DateModel { Year = 2019 }); var expectedNotifications = this.GetNotifications() .Where(n => n.From == "DateModelCreateSampleSystem@luxoft.com"); @@ -167,7 +167,7 @@ public void DateModelCreateSubscriptionTest() private Employee CreateEmployee() { - var employee = this.DataHelper.SaveEmployee("John Doe"); + var employee = this.DataManager.SaveEmployee("John Doe"); return employee; } diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs index 7cd5dc7b8..d02da67b1 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/UniqueGroupTests.cs @@ -10,13 +10,13 @@ public class UniqueGroupTests(IServiceProvider rootServiceProvider) : TestBase(r public void UniqueGroup_NonUniqueEntityCreated_ErrorUsesCustomName() { // Arrange - var role = this.DataHelper.SaveEmployeeRole(); - var roleDegree = this.DataHelper.SaveEmployeeRoleDegree(); + var role = this.DataManager.SaveEmployeeRole(); + var roleDegree = this.DataManager.SaveEmployeeRoleDegree(); - this.DataHelper.SaveRoleRoleDegreeLink(role, roleDegree); + this.DataManager.SaveRoleRoleDegreeLink(role, roleDegree); // Act - var ex = Record.Exception(() => this.DataHelper.SaveRoleRoleDegreeLink(role, roleDegree)); + var ex = Record.Exception(() => this.DataManager.SaveRoleRoleDegreeLink(role, roleDegree)); // Assert var uniqueViolationException = Assert.IsType(ex); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs index 251212f05..496f3a8ab 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/ValidationTests.cs @@ -10,10 +10,10 @@ public class ValidationTests(IServiceProvider rootServiceProvider) : TestBase(ro public void ValidateByDB_ValidationException() { // Arrange - this.DataHelper.SaveEmployee("John Doe", "JD"); + this.DataManager.SaveEmployee("John Doe", "JD"); // Act - var ex = Record.Exception(() => this.DataHelper.SaveEmployee("John Doe", "JD")); + var ex = Record.Exception(() => this.DataManager.SaveEmployee("John Doe", "JD")); // Assert Assert.IsType(ex); @@ -25,7 +25,7 @@ public void ValidateByClassAttribute_ValidationException() // Arrange // Act - var ex = Record.Exception(() => this.DataHelper.SaveEmployee(pin: 1234)); + var ex = Record.Exception(() => this.DataManager.SaveEmployee(pin: 1234)); // Assert var validationException = Assert.IsType(ex); @@ -37,10 +37,10 @@ public void ValidateByConcreteValidator_ValidationException() { // Arrange var externalId = new Random().Next(); - this.DataHelper.SaveEmployee(externalId: externalId); + this.DataManager.SaveEmployee(externalId: externalId); // Act - var ex = Record.Exception(() => this.DataHelper.SaveEmployee(externalId: externalId)); + var ex = Record.Exception(() => this.DataManager.SaveEmployee(externalId: externalId)); // Assert var validationException = Assert.IsType(ex); @@ -52,10 +52,10 @@ public void ValidateByGlobalValidator_ValidationException() { // Arrange var pin = new Random().Next(); - this.DataHelper.SaveEmployee(pin: pin); + this.DataManager.SaveEmployee(pin: pin); // Act - var ex = Record.Exception(() => this.DataHelper.SaveEmployee(pin: pin)); + var ex = Record.Exception(() => this.DataManager.SaveEmployee(pin: pin)); // Assert var validationException = Assert.IsType(ex); @@ -70,7 +70,7 @@ public void Validate_HasInvalidVirtualProperty_ShouldNotThrow() var invalidDate = DateTime.MinValue; // Act - Action call = () => this.DataHelper.SaveEmployee(externalId: externalId, nonValidateVirtualProp: invalidDate); + Action call = () => this.DataManager.SaveEmployee(externalId: externalId, nonValidateVirtualProp: invalidDate); // Assert call(); @@ -84,7 +84,7 @@ public void Validate_HasInvalidVirtualPropertyMarkedWithAttribute_ShouldThrow() var invalidDate = DateTime.MinValue; // Act - var ex = Record.Exception(() => this.DataHelper.SaveEmployee(externalId: externalId, validateVirtualProp: invalidDate)); + var ex = Record.Exception(() => this.DataManager.SaveEmployee(externalId: externalId, validateVirtualProp: invalidDate)); // Assert var validationException = Assert.IsType(ex); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs index 11b30fb8e..da5d2ec91 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/VirtualPermissionTests.cs @@ -18,9 +18,9 @@ protected override async ValueTask InitializeAsync(CancellationToken ct) => .Select( userLogin => { - var buId = this.DataHelper.SaveBusinessUnit().Id; + var buId = this.DataManager.SaveBusinessUnit().Id; - var employeeId = this.DataHelper.SaveEmployee(login: userLogin).Id; + var employeeId = this.DataManager.SaveEmployee(login: userLogin).Id; this.Evaluate( DBSessionMode.Write, diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WebApi/EmployeeTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WebApi/EmployeeTests.cs index 4575417af..e270ed240 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WebApi/EmployeeTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WebApi/EmployeeTests.cs @@ -8,7 +8,7 @@ public class WebApiTests(IServiceProvider rootServiceProvider) : TestBase(rootSe public void WebApi_CallMethod() { // Arrange - var employeeIdentity = this.DataHelper.SaveEmployee(Guid.NewGuid()); + var employeeIdentity = this.DataManager.SaveEmployee(Guid.NewGuid()); var employeeController = this.MainWebApi.Employee; diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs index a03108b86..69f3567e8 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/WrongSecurityMessageTests.cs @@ -20,7 +20,7 @@ public class WrongSecurityMessageTests(IServiceProvider rootServiceProvider) : T private static readonly Guid TestPrincipalId = Guid.NewGuid(); protected override async ValueTask InitializeAsync(CancellationToken ct) => - this.DataHelper.SaveEmployee(login: TestPrincipalName, id: TestPrincipalId); + this.DataManager.SaveEmployee(login: TestPrincipalName, id: TestPrincipalId); [Fact] public void UseWrongSecurityMode_ErrorMessageCorrected() => this.UseSecurityRule_WithoutSecurity_ErrorMessageCorrected(SecurityRule.Edit); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs index 5b94f225d..125b5b937 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs @@ -77,7 +77,7 @@ public IServiceProvider BuildServiceProvider(IServiceCollection services) .AddTestControllers([typeof(EmployeeController).Assembly]) - .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton() diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Employee.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataManager.Employee.cs similarity index 99% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Employee.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataManager.Employee.cs index e7e11bbcb..c61fe32d0 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Employee.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataManager.Employee.cs @@ -12,7 +12,7 @@ namespace SampleSystem.IntegrationTests._Environment.TestData.Helpers; -public partial class DataHelper +public partial class DataManager { public EmployeeIdentityDTO SaveEmployee( Guid? id = null, diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Init.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataManager.Init.cs similarity index 73% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Init.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataManager.Init.cs index c695649db..81bb4f95b 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Init.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataManager.Init.cs @@ -4,7 +4,7 @@ namespace SampleSystem.IntegrationTests._Environment.TestData.Helpers; -public partial class DataHelper(IServiceProvider rootServiceProvider) : IRootServiceProviderContainer +public partial class DataManager(IServiceProvider rootServiceProvider) : IRootServiceProviderContainer { private Guid GetGuid(Guid? id) { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Smo.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataManager.Smo.cs similarity index 95% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Smo.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataManager.Smo.cs index c80bc235a..28369987b 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Smo.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataManager.Smo.cs @@ -4,7 +4,7 @@ namespace SampleSystem.IntegrationTests._Environment.TestData.Helpers; -public partial class DataHelper +public partial class DataManager { public Table GetTable(string databaseName, string tableName, string schema = "app") { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Subscriptions.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataManager.Subscriptions.cs similarity index 95% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Subscriptions.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataManager.Subscriptions.cs index 6d0ffcc94..0c5457944 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.Subscriptions.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataManager.Subscriptions.cs @@ -7,7 +7,7 @@ namespace SampleSystem.IntegrationTests._Environment.TestData.Helpers; -public partial class DataHelper +public partial class DataManager { public List> ProcessSubscription(T? prev, T? next) diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataManager.cs similarity index 99% rename from src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.cs rename to src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataManager.cs index 0972644de..944fdea1e 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataHelper.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/Helpers/DataManager.cs @@ -16,7 +16,7 @@ namespace SampleSystem.IntegrationTests._Environment.TestData.Helpers; -public partial class DataHelper +public partial class DataManager { public CountryIdentityDTO SaveCountry( Guid? id = null, diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/TestBase.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/TestBase.cs index 6a8c694a8..69ac10474 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/TestBase.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/TestBase.cs @@ -18,7 +18,7 @@ public class TestBase(IServiceProvider rootServiceProvider) : IntegrationTestBas public MainAuditWebApi MainAuditWebApi => new(this.RootServiceProvider); - protected DataHelper DataHelper => this.RootServiceProvider.GetRequiredService(); + protected DataManager DataManager => this.RootServiceProvider.GetRequiredService(); protected RootAuthManager AuthManager => this.RootServiceProvider.GetRequiredService(); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/TestDataInitializer.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/TestDataInitializer.cs index 640924f0b..7ac03bd9f 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/TestDataInitializer.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/TestDataInitializer.cs @@ -17,7 +17,7 @@ namespace SampleSystem.IntegrationTests._Environment.TestData; public class TestDataInitializer( SampleSystemInitializer mainInitializer, RootAuthManager authManager, - DataHelper dataHelper, + DataManager dataManager, IOptions settings, IRootImpersonateService rootImpersonateService) : IInitializer { @@ -37,7 +37,7 @@ public async Task InitializeInternal(CancellationToken cancellationToken) var integrationTestUserName = settings.Value.IntegrationTestUserName; - dataHelper.SaveEmployee( + dataManager.SaveEmployee( id: DefaultConstants.EMPLOYEE_MY_ID, nameEng: new Fio { FirstName = DefaultConstants.EMPLOYEE_MY_NAME, LastName = DefaultConstants.EMPLOYEE_MY_NAME }, login: integrationTestUserName); @@ -46,7 +46,7 @@ public async Task InitializeInternal(CancellationToken cancellationToken) foreach (var localAdmin in settings.Value.LocalAdmins) { - dataHelper.SaveEmployee(login: localAdmin); + dataManager.SaveEmployee(login: localAdmin); await authManager.For(localAdmin).SetRoleAsync(SecurityRole.Administrator, cancellationToken); } @@ -54,16 +54,16 @@ public async Task InitializeInternal(CancellationToken cancellationToken) private void FillMainData() { - dataHelper.SaveCountry( + dataManager.SaveCountry( id: DefaultConstants.COUNTRY_RUSSIA_ID, name: DefaultConstants.COUNTRY_RUSSIA_NAME, nativeName: DefaultConstants.COUNTRY_RUSSIA_NATIVE_NAME, code: DefaultConstants.COUNTRY_RUSSIA_CODE, culture: "ru-RU"); - dataHelper.SaveLocation(id: DefaultConstants.LOCATION_PARENT_ID, name: DefaultConstants.LOCATION_PARENT_NAME); + dataManager.SaveLocation(id: DefaultConstants.LOCATION_PARENT_ID, name: DefaultConstants.LOCATION_PARENT_NAME); - var company = dataHelper.SaveBusinessUnitType( + var company = dataManager.SaveBusinessUnitType( DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_ID, DefaultConstants.BUSINESS_UNIT_TYPE_COMPANY_NAME, isAdministrative: false, @@ -71,7 +71,7 @@ private void FillMainData() canBeLinkedToDepartment: false, canBeResourcePool: false, needVertical: false); - var lob = dataHelper.SaveBusinessUnitType( + var lob = dataManager.SaveBusinessUnitType( DefaultConstants.BUSINESS_UNIT_TYPE_LOB_ID, DefaultConstants.BUSINESS_UNIT_TYPE_LOB_NAME, projectStartAllowed: true, @@ -79,7 +79,7 @@ private void FillMainData() canBeResourcePool: true, needVertical: false); - var businessSegment = dataHelper.SaveBusinessUnitType( + var businessSegment = dataManager.SaveBusinessUnitType( DefaultConstants.BUSINESS_UNIT_TYPE_BUSINESS_SEGMENT_ID, DefaultConstants.BUSINESS_UNIT_TYPE_BUSINESS_SEGMENT_NAME, possibleStartDate: PossibleStartDate.FinYearStart, @@ -95,7 +95,7 @@ private void FillMainData() canBeNewBusiness: false, possibleParents: [company]); - var account = dataHelper.SaveBusinessUnitType( + var account = dataManager.SaveBusinessUnitType( DefaultConstants.BUSINESS_UNIT_TYPE_ACCOUNT_ID, DefaultConstants.BUSINESS_UNIT_TYPE_ACCOUNT_NAME, possibleStartDate: PossibleStartDate.AnyDay, @@ -117,21 +117,21 @@ private void FillMainData() possibleParents: [businessSegment, lob, company], transferTo: [businessSegment, lob, company]); - dataHelper.SaveBusinessUnitType( + dataManager.SaveBusinessUnitType( DefaultConstants.BUSINESS_UNIT_TYPE_ADMIN_COMMERCIAL_ID, DefaultConstants.BUSINESS_UNIT_TYPE_ADMIN_COMMERCIAL_NAME, projectStartAllowed: true, canBeLinkedToDepartment: true, canBeResourcePool: true, needVertical: false); - dataHelper.SaveBusinessUnitType( + dataManager.SaveBusinessUnitType( DefaultConstants.BUSINESS_UNIT_TYPE_ADMIN_SERVICES_ID, DefaultConstants.BUSINESS_UNIT_TYPE_ADMIN_SERVICES_NAME, projectStartAllowed: true, canBeLinkedToDepartment: true, canBeResourcePool: true, needVertical: false); - dataHelper.SaveBusinessUnitType( + dataManager.SaveBusinessUnitType( DefaultConstants.BUSINESS_UNIT_TYPE_DIVISION_ID, DefaultConstants.BUSINESS_UNIT_TYPE_DIVISION_NAME, projectStartAllowed: true, @@ -140,7 +140,7 @@ private void FillMainData() needVertical: false, possibleParents: [company, account]); - dataHelper.SaveBusinessUnitType( + dataManager.SaveBusinessUnitType( DefaultConstants.BUSINESS_UNIT_TYPE_NEW_BUSINESS_ID, DefaultConstants.BUSINESS_UNIT_TYPE_NEW_BUSINESS_NAME, projectStartAllowed: true, @@ -149,21 +149,21 @@ private void FillMainData() needVertical: true, possibleParents: [company, account, businessSegment]); - dataHelper.SaveBusinessUnitType( + dataManager.SaveBusinessUnitType( DefaultConstants.BUSINESS_UNIT_TYPE_SERVICE_ID, DefaultConstants.BUSINESS_UNIT_TYPE_SERVICE_NAME, projectStartAllowed: true, canBeLinkedToDepartment: true, canBeResourcePool: true, needVertical: false); - dataHelper.SaveBusinessUnitType( + dataManager.SaveBusinessUnitType( DefaultConstants.BUSINESS_UNIT_TYPE_SE_ADMINISTRATIVE_ID, DefaultConstants.BUSINESS_UNIT_TYPE_SE_ADMINISTRATIVE_NAME, projectStartAllowed: true, canBeLinkedToDepartment: true, canBeResourcePool: true, needVertical: false); - var seDivision = dataHelper.SaveBusinessUnitType( + var seDivision = dataManager.SaveBusinessUnitType( DefaultConstants.BUSINESS_UNIT_TYPE_SE_DIVISION_ID, DefaultConstants.BUSINESS_UNIT_TYPE_SE_DIVISION_NAME, possibleStartDate: PossibleStartDate.AnyDay, @@ -179,14 +179,14 @@ private void FillMainData() canBeNewBusiness: false, possibleParents: [account], transferTo: [account]); - dataHelper.SaveBusinessUnitType( + dataManager.SaveBusinessUnitType( DefaultConstants.BUSINESS_UNIT_TYPE_SE_SUB_DIVISION_ID, DefaultConstants.BUSINESS_UNIT_TYPE_SE_SE_SUB_DIVISION_NAME, projectStartAllowed: true, canBeLinkedToDepartment: true, canBeResourcePool: true, needVertical: false); - dataHelper.SaveBusinessUnitType( + dataManager.SaveBusinessUnitType( DefaultConstants.BUSINESS_UNIT_TYPE_PRACTICE_ID, DefaultConstants.BUSINESS_UNIT_TYPE_PRACTICE_NAME, projectStartAllowed: true, @@ -194,7 +194,7 @@ private void FillMainData() canBeResourcePool: true, needVertical: false); - dataHelper.SaveBusinessUnitType( + dataManager.SaveBusinessUnitType( DefaultConstants.BUSINESS_UNIT_TYPE_PROGRAM_ID, DefaultConstants.BUSINESS_UNIT_TYPE_PROGRAM_NAME, currentTypeInPossibleParents: true, @@ -218,29 +218,29 @@ private void FillMainData() ], transferTo: [account, seDivision]); - dataHelper.SaveEmployeePosition( + dataManager.SaveEmployeePosition( DefaultConstants.EMPLOYEE_POSITION_TESTER_ID, DefaultConstants.EMPLOYEE_POSITION_TESTER_NAME); - dataHelper.SaveEmployeeRegistrationType( + dataManager.SaveEmployeeRegistrationType( DefaultConstants.EMPLOYEE_REGISTRATION_TYPE_STAFF_ID, DefaultConstants.EMPLOYEE_REGISTRATION_TYPE_STAFF_NAME); - dataHelper.SaveEmployeeRole( + dataManager.SaveEmployeeRole( DefaultConstants.EMPLOYEE_ROLE_TESTER_ID, DefaultConstants.EMPLOYEE_ROLE_TESTER_NAME); - dataHelper.SaveEmployeeRoleDegree( + dataManager.SaveEmployeeRoleDegree( DefaultConstants.EMPLOYEE_ROLE_DEGREE_REGULAR_ID, DefaultConstants.EMPLOYEE_ROLE_DEGREE_REGULAR_NAME); - dataHelper.SaveCompanyLegalEntity( + dataManager.SaveCompanyLegalEntity( DefaultConstants.COMPANY_LEGAL_ENTITY_ID, DefaultConstants.COMPANY_LEGAL_ENTITY_NAME); - dataHelper.SaveEmployee(DefaultConstants.HRDepartment_DEFAULT_HEAD_EMPLOYEE_ID, login: "Default_HRDepartment_HEAD", isObjectRequired: false); + dataManager.SaveEmployee(DefaultConstants.HRDepartment_DEFAULT_HEAD_EMPLOYEE_ID, login: "Default_HRDepartment_HEAD", isObjectRequired: false); - dataHelper.SaveHRDepartment( + dataManager.SaveHRDepartment( DefaultConstants.HRDEPARTMENT_PARENT_ID, DefaultConstants.HRDEPARTMENT_PARENT_NAME); } From 4ce2a440efc70322a9dca1b18fa709069b2b05d2 Mon Sep 17 00:00:00 2001 From: "Atsuta, Ivan" Date: Mon, 11 May 2026 12:09:32 +0200 Subject: [PATCH 11/13] fix --- src/Directory.Packages.props | 1 + .../Framework.Infrastructure.Hangfire.csproj | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index cb406692d..c8a7bae0e 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -66,6 +66,7 @@ + diff --git a/src/Infrastructure/Framework.Infrastructure.Hangfire/Framework.Infrastructure.Hangfire.csproj b/src/Infrastructure/Framework.Infrastructure.Hangfire/Framework.Infrastructure.Hangfire.csproj index 1b7209e19..9efd93148 100644 --- a/src/Infrastructure/Framework.Infrastructure.Hangfire/Framework.Infrastructure.Hangfire.csproj +++ b/src/Infrastructure/Framework.Infrastructure.Hangfire/Framework.Infrastructure.Hangfire.csproj @@ -13,6 +13,7 @@ +
From 8981cd482a638e6d30b8ca24ede93b4f8d5651ab Mon Sep 17 00:00:00 2001 From: "Atsuta, Ivan" Date: Mon, 11 May 2026 12:13:07 +0200 Subject: [PATCH 12/13] clean --- .../MssqlDatabaseTestingProvider.cs | 6 ++---- .../Extensions/TypeExtensions.cs | 10 ++-------- .../Configuration/DefaultValidatorGenerator.cs | 5 +---- .../Lambda/ProjectionLambdaEnvironment.cs | 5 +---- .../ServerGenerators.cs | 5 +---- .../SampleSystem.CheckGenTests/CsprojPackageIdTests.cs | 10 ++-------- .../MetadataSubscriptionSystemServiceTests.cs | 5 +---- 7 files changed, 10 insertions(+), 36 deletions(-) diff --git a/src/Anch.Testing.Database.Mssql/MssqlDatabaseTestingProvider.cs b/src/Anch.Testing.Database.Mssql/MssqlDatabaseTestingProvider.cs index 8af67647f..ae04137a0 100644 --- a/src/Anch.Testing.Database.Mssql/MssqlDatabaseTestingProvider.cs +++ b/src/Anch.Testing.Database.Mssql/MssqlDatabaseTestingProvider.cs @@ -7,9 +7,7 @@ namespace Anch.Testing.Database.Mssql; public class MssqlDatabaseTestingProvider : IDatabaseTestingProvider { - public void AddServices(IServiceCollection services) - { + public void AddServices(IServiceCollection services) => services.AddSingleton() - .AddSingleton(); - } + .AddSingleton(); } diff --git a/src/BLL/Framework.BLL.Abstractions/Extensions/TypeExtensions.cs b/src/BLL/Framework.BLL.Abstractions/Extensions/TypeExtensions.cs index 70fc9851c..741e8fc88 100644 --- a/src/BLL/Framework.BLL.Abstractions/Extensions/TypeExtensions.cs +++ b/src/BLL/Framework.BLL.Abstractions/Extensions/TypeExtensions.cs @@ -2,13 +2,7 @@ public static class TypeExtensions { - internal static bool SafeEquals(this Type t1, Type t2) - { - return t1.IsGenericTypeDefinition == t2.IsGenericTypeDefinition && t1 == t2; - } + internal static bool SafeEquals(this Type t1, Type t2) => t1.IsGenericTypeDefinition == t2.IsGenericTypeDefinition && t1 == t2; - internal static bool SafeIsAssignableFrom(this Type t1, Type t2) - { - return t1.SafeEquals(t2) || t1.IsAssignableFrom(t2); - } + internal static bool SafeIsAssignableFrom(this Type t1, Type t2) => t1.SafeEquals(t2) || t1.IsAssignableFrom(t2); } diff --git a/src/CodeGeneration/Framework.CodeGeneration.BLLGenerator/Configuration/DefaultValidatorGenerator.cs b/src/CodeGeneration/Framework.CodeGeneration.BLLGenerator/Configuration/DefaultValidatorGenerator.cs index c1493bb23..7448b1d25 100644 --- a/src/CodeGeneration/Framework.CodeGeneration.BLLGenerator/Configuration/DefaultValidatorGenerator.cs +++ b/src/CodeGeneration/Framework.CodeGeneration.BLLGenerator/Configuration/DefaultValidatorGenerator.cs @@ -146,10 +146,7 @@ protected virtual IEnumerable GetPropertyValidators(PropertyI } } - protected virtual bool HasDeepValidation(PropertyInfo property) - { - return property.HasDeepValidation(); - } + protected virtual bool HasDeepValidation(PropertyInfo property) => property.HasDeepValidation(); protected virtual bool IsManyPropertyDynamicClassAttribute(ClassValidatorAttribute attribute) { diff --git a/src/Projection/Framework.Projection.Runtime/Lambda/ProjectionLambdaEnvironment.cs b/src/Projection/Framework.Projection.Runtime/Lambda/ProjectionLambdaEnvironment.cs index 41300a382..c94829a56 100644 --- a/src/Projection/Framework.Projection.Runtime/Lambda/ProjectionLambdaEnvironment.cs +++ b/src/Projection/Framework.Projection.Runtime/Lambda/ProjectionLambdaEnvironment.cs @@ -55,10 +55,7 @@ private ITypeResolver CreateProjectionTypeResolver(IProjectionSourc return TypeResolverHelper.Create(this.projections.ToDictionary(projection => projection, this.ProjectionTypeResolver.Resolve)); } - public Type GetSecurityProjectionType(Type sourceType) - { - return this.ProjectionTypeResolver.Resolve(this.projections.TryGetSecurityProjection(sourceType)!); - } + public Type GetSecurityProjectionType(Type sourceType) => this.ProjectionTypeResolver.Resolve(this.projections.TryGetSecurityProjection(sourceType)!); /// /// Получение типа свойства из ссылки на тип diff --git a/src/_Configuration/Framework.Configuration.TestGenerate/ServerGenerators.cs b/src/_Configuration/Framework.Configuration.TestGenerate/ServerGenerators.cs index 1d7d376a3..ec3159588 100644 --- a/src/_Configuration/Framework.Configuration.TestGenerate/ServerGenerators.cs +++ b/src/_Configuration/Framework.Configuration.TestGenerate/ServerGenerators.cs @@ -11,10 +11,7 @@ namespace Framework.Configuration.TestGenerate; public partial class ServerGenerators { [Fact] - public void GenerateMainTest() - { - this.GenerateMain().ToList(); - } + public void GenerateMainTest() => this.GenerateMain().ToList(); public IEnumerable GenerateMain() => this.GenerateBLLCore() diff --git a/src/_SampleSystem/_Tests/SampleSystem.CheckGenTests/CsprojPackageIdTests.cs b/src/_SampleSystem/_Tests/SampleSystem.CheckGenTests/CsprojPackageIdTests.cs index b692d2b18..c19cf4712 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.CheckGenTests/CsprojPackageIdTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.CheckGenTests/CsprojPackageIdTests.cs @@ -118,15 +118,9 @@ private static HashSet LoadSlnxProjects(string slnxPath) .ToHashSet(StringComparer.OrdinalIgnoreCase); } - private static string ToRelativePath(string root, string file) - { - return NormalizePath(Path.GetRelativePath(root, file)); - } + private static string ToRelativePath(string root, string file) => NormalizePath(Path.GetRelativePath(root, file)); - private static string NormalizePath(string path) - { - return path.Replace('\\', '/').TrimStart('/'); - } + private static string NormalizePath(string path) => path.Replace('\\', '/').TrimStart('/'); private static string FindSolutionRoot() { diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs index 9a3a0488d..2b04f6dca 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/Subscriptions_Metadata/MetadataSubscriptionSystemServiceTests.cs @@ -11,10 +11,7 @@ namespace SampleSystem.IntegrationTests.Subscriptions_Metadata; public sealed class MetadataSubscriptionSystemServiceTests(IServiceProvider rootServiceProvider) : TestBase(rootServiceProvider) { - protected override async ValueTask InitializeAsync(CancellationToken ct) - { - this.GetNotifications().Clear(); - } + protected override async ValueTask InitializeAsync(CancellationToken ct) => this.GetNotifications().Clear(); [Fact] public void SubscriptionFromMetadataShouldBeSent() From fadd2e6733560bd78cbfbf6ff3a5dc8327cbcc61 Mon Sep 17 00:00:00 2001 From: "Atsuta, Ivan" Date: Mon, 11 May 2026 14:10:34 +0200 Subject: [PATCH 13/13] add BssTestEnvironment --- .../Anch.Testing.Database.Mssql.csproj | 11 --- ...ssqlTestDatabaseConnectionStringBuilder.cs | 31 ------- .../BssDatabaseFilePathExtractor.cs | 69 ++++++++++++++++ .../Framework.AutomationCore.csproj | 3 +- .../BssDatabaseFilePathExtractor.cs} | 12 +-- .../BssDatabaseTestingProvider.cs} | 8 +- .../BssTestDatabaseConnectionStringBuilder.cs | 32 ++++++++ .../Utils/DatabaseUtils/CoreDatabaseUtil.cs | 24 +++--- .../Utils/DatabaseUtils/DatabaseContext.cs | 6 +- .../Utils/DatabaseUtils/DatabaseItem.cs | 6 +- src/BssFramework.slnx | 1 - .../_Environment/NHibTestEnvironment.cs | 81 +++++-------------- 12 files changed, 151 insertions(+), 133 deletions(-) delete mode 100644 src/Anch.Testing.Database.Mssql/Anch.Testing.Database.Mssql.csproj delete mode 100644 src/Anch.Testing.Database.Mssql/MssqlTestDatabaseConnectionStringBuilder.cs create mode 100644 src/AutomationCore/Framework.AutomationCore/BssDatabaseFilePathExtractor.cs rename src/{Anch.Testing.Database.Mssql/MssqlDatabaseFilePathExtractor.cs => AutomationCore/Framework.AutomationCore/TestingProvider/BssDatabaseFilePathExtractor.cs} (66%) rename src/{Anch.Testing.Database.Mssql/MssqlDatabaseTestingProvider.cs => AutomationCore/Framework.AutomationCore/TestingProvider/BssDatabaseTestingProvider.cs} (52%) create mode 100644 src/AutomationCore/Framework.AutomationCore/TestingProvider/BssTestDatabaseConnectionStringBuilder.cs diff --git a/src/Anch.Testing.Database.Mssql/Anch.Testing.Database.Mssql.csproj b/src/Anch.Testing.Database.Mssql/Anch.Testing.Database.Mssql.csproj deleted file mode 100644 index de4c36d99..000000000 --- a/src/Anch.Testing.Database.Mssql/Anch.Testing.Database.Mssql.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - Anch.Testing.Database.Mssql - - - - - - - diff --git a/src/Anch.Testing.Database.Mssql/MssqlTestDatabaseConnectionStringBuilder.cs b/src/Anch.Testing.Database.Mssql/MssqlTestDatabaseConnectionStringBuilder.cs deleted file mode 100644 index 4aca1c191..000000000 --- a/src/Anch.Testing.Database.Mssql/MssqlTestDatabaseConnectionStringBuilder.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Data.Common; - -using Anch.Testing.Database.ConnectionStringManagement; - -namespace Anch.Testing.Database.Mssql; - -public class MssqlTestDatabaseConnectionStringBuilder(TestDatabaseSettings databaseSettings) : ITestDatabaseConnectionStringBuilder -{ - public TestDatabaseConnectionString AddPostfix(string postfix) - { - var builder = new DbConnectionStringBuilder { ConnectionString = databaseSettings.DefaultConnectionString.Value }; - - var dataSource = builder["Data Source"]?.ToString(); - - if (string.IsNullOrWhiteSpace(dataSource)) - throw new InvalidOperationException("Data Source is missing in connection string."); - - var directory = Path.GetDirectoryName(dataSource); - var fileName = Path.GetFileNameWithoutExtension(dataSource); - var extension = Path.GetExtension(dataSource); - - var newFileName = $"{fileName}{postfix}{extension}"; - var newDataSource = directory is null - ? newFileName - : Path.Combine(directory, newFileName); - - builder["Data Source"] = newDataSource; - - return new TestDatabaseConnectionString(builder.ConnectionString); - } -} diff --git a/src/AutomationCore/Framework.AutomationCore/BssDatabaseFilePathExtractor.cs b/src/AutomationCore/Framework.AutomationCore/BssDatabaseFilePathExtractor.cs new file mode 100644 index 000000000..09e256e77 --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore/BssDatabaseFilePathExtractor.cs @@ -0,0 +1,69 @@ +using Anch.Core; +using Anch.DependencyInjection; +using Anch.Testing; +using Anch.Testing.Database; +using Anch.Testing.Database.DependencyInjection; + +using Framework.AutomationCore.ServiceEnvironment; +using Framework.AutomationCore.Settings; +using Framework.AutomationCore.TestingProvider; +using Framework.Core; +using Framework.Database; +using Framework.Database.ConnectionStringSource; + +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Framework.AutomationCore; + +public abstract class BssTestEnvironment : ITestEnvironment +{ + protected abstract IConfiguration Configuration { get; } + + private AutomationFrameworkSettings Settings => field ??= new AutomationFrameworkSettings().Self(this.Configuration.Bind); + + protected virtual string DefaultConnectionStringName => "DefaultConnection"; + + protected virtual string DefaultConnectionString => field ??= this.Configuration.GetConnectionString(this.DefaultConnectionStringName) + ?? throw new InvalidOperationException( + $"{this.DefaultConnectionStringName} connection string is not configured."); + + private TestDatabaseSettings TestDatabaseSettings => + field ??= new TestDatabaseSettings { InitMode = this.Settings.DatabaseInitMode, DefaultConnectionString = new(this.DefaultConnectionString) }; + + public bool AllowParallelization => this.Settings.TestsParallelize; + + protected virtual void InitServices(IServiceCollection services) + { + + } + + protected virtual void InitInitializers(IDatabaseTestingSetup setup) + { + + } + + public IServiceProvider BuildServiceProvider(IServiceCollection services) + { + services.AddOptions(); + + return services.AddSingleton(this.Configuration) + + .Self(this.InitServices) + + .AddIntegrationTests() + + .AddDatabaseTesting(dts => dts + .SetProvider() + .Self(this.InitInitializers) + .SetSettings(this.TestDatabaseSettings) + .RebindActualConnection(connectionString => + new ManualDefaultConnectionStringSource(connectionString.Value))) + + .Pipe(this.InternalBuildServiceProvider); + } + + protected virtual IServiceProvider InternalBuildServiceProvider(IServiceCollection services) => + services.AddValidator() + .BuildServiceProvider(new ServiceProviderOptions { ValidateScopes = true, ValidateOnBuild = true }); +} diff --git a/src/AutomationCore/Framework.AutomationCore/Framework.AutomationCore.csproj b/src/AutomationCore/Framework.AutomationCore/Framework.AutomationCore.csproj index fa36f90bf..ed91a75b5 100644 --- a/src/AutomationCore/Framework.AutomationCore/Framework.AutomationCore.csproj +++ b/src/AutomationCore/Framework.AutomationCore/Framework.AutomationCore.csproj @@ -10,14 +10,15 @@ + + - diff --git a/src/Anch.Testing.Database.Mssql/MssqlDatabaseFilePathExtractor.cs b/src/AutomationCore/Framework.AutomationCore/TestingProvider/BssDatabaseFilePathExtractor.cs similarity index 66% rename from src/Anch.Testing.Database.Mssql/MssqlDatabaseFilePathExtractor.cs rename to src/AutomationCore/Framework.AutomationCore/TestingProvider/BssDatabaseFilePathExtractor.cs index c5a18b593..65dd18f95 100644 --- a/src/Anch.Testing.Database.Mssql/MssqlDatabaseFilePathExtractor.cs +++ b/src/AutomationCore/Framework.AutomationCore/TestingProvider/BssDatabaseFilePathExtractor.cs @@ -2,16 +2,18 @@ using Anch.Testing.Database.ConnectionStringManagement; -namespace Anch.Testing.Database.Mssql; +namespace Framework.AutomationCore.TestingProvider; -public class MssqlDatabaseFilePathExtractor : IDatabaseFilePathExtractor +public class BssDatabaseFilePathExtractor : IDatabaseFilePathExtractor { public string Extract(TestDatabaseConnectionString connectionString) { + throw new NotImplementedException(); + var builder = new DbConnectionStringBuilder - { - ConnectionString = connectionString.Value - }; + { + ConnectionString = connectionString.Value + }; if (!builder.TryGetValue("Data Source", out var value)) throw new InvalidOperationException("Data Source is missing."); diff --git a/src/Anch.Testing.Database.Mssql/MssqlDatabaseTestingProvider.cs b/src/AutomationCore/Framework.AutomationCore/TestingProvider/BssDatabaseTestingProvider.cs similarity index 52% rename from src/Anch.Testing.Database.Mssql/MssqlDatabaseTestingProvider.cs rename to src/AutomationCore/Framework.AutomationCore/TestingProvider/BssDatabaseTestingProvider.cs index ae04137a0..70216cef4 100644 --- a/src/Anch.Testing.Database.Mssql/MssqlDatabaseTestingProvider.cs +++ b/src/AutomationCore/Framework.AutomationCore/TestingProvider/BssDatabaseTestingProvider.cs @@ -3,11 +3,11 @@ using Microsoft.Extensions.DependencyInjection; -namespace Anch.Testing.Database.Mssql; +namespace Framework.AutomationCore.TestingProvider; -public class MssqlDatabaseTestingProvider : IDatabaseTestingProvider +public class BssDatabaseTestingProvider : IDatabaseTestingProvider { public void AddServices(IServiceCollection services) => - services.AddSingleton() - .AddSingleton(); + services.AddSingleton() + .AddSingleton(); } diff --git a/src/AutomationCore/Framework.AutomationCore/TestingProvider/BssTestDatabaseConnectionStringBuilder.cs b/src/AutomationCore/Framework.AutomationCore/TestingProvider/BssTestDatabaseConnectionStringBuilder.cs new file mode 100644 index 000000000..13b26db56 --- /dev/null +++ b/src/AutomationCore/Framework.AutomationCore/TestingProvider/BssTestDatabaseConnectionStringBuilder.cs @@ -0,0 +1,32 @@ +using Anch.Testing.Database; +using Anch.Testing.Database.ConnectionStringManagement; + +namespace Framework.AutomationCore.TestingProvider; + +public class BssTestDatabaseConnectionStringBuilder(TestDatabaseSettings databaseSettings) : ITestDatabaseConnectionStringBuilder +{ + public TestDatabaseConnectionString AddPostfix(string postfix) + { + throw new NotImplementedException(); + + //var builder = new DbConnectionStringBuilder { ConnectionString = databaseSettings.DefaultConnectionString.Value }; + + //var dataSource = builder["Data Source"]?.ToString(); + + //if (string.IsNullOrWhiteSpace(dataSource)) + // throw new InvalidOperationException("Data Source is missing in connection string."); + + //var directory = Path.GetDirectoryName(dataSource); + //var fileName = Path.GetFileNameWithoutExtension(dataSource); + //var extension = Path.GetExtension(dataSource); + + //var newFileName = $"{fileName}{postfix}{extension}"; + //var newDataSource = directory is null + // ? newFileName + // : Path.Combine(directory, newFileName); + + //builder["Data Source"] = newDataSource; + + //return new TestDatabaseConnectionString(builder.ConnectionString); + } +} diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.cs index 47737d9df..a13de3ee0 100644 --- a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.cs +++ b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/CoreDatabaseUtil.cs @@ -201,24 +201,24 @@ private static void Create(Server server, IDatabaseItem database) var fileGroup = new FileGroup(db, "PRIMARY"); var dataFile = new DataFile( - fileGroup, - database.DatabaseName, - database.SourceDataPath) - { - Size = 5.5 * 1024.0, GrowthType = FileGrowthType.KB, Growth = 1.0 * 1024.0 - }; + fileGroup, + database.DatabaseName, + database.SourceDataPath) + { + Size = 5.5 * 1024.0, GrowthType = FileGrowthType.KB, Growth = 1.0 * 1024.0 + }; fileGroup.Files.Add(dataFile); db.FileGroups.Add(fileGroup); var logFile = new LogFile( - db, - database.DatabaseName + "_log", - database.SourceLogPath) - { - Size = 1.0 * 1024.0, GrowthType = FileGrowthType.Percent, Growth = 10.0 - }; + db, + database.DatabaseName + "_log", + database.SourceLogPath) + { + Size = 1.0 * 1024.0, GrowthType = FileGrowthType.Percent, Growth = 10.0 + }; db.LogFiles.Add(logFile); diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs index 6ac823da1..ac02fb009 100644 --- a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs +++ b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseContext.cs @@ -25,7 +25,7 @@ static DatabaseContext() => public DatabaseContext( IDefaultConnectionStringSource defaultConnectionStringSource, IOptions settings) - : this(defaultConnectionStringSource, settings.Value) + : this(defaultConnectionStringSource, settings.Value) { } @@ -56,7 +56,7 @@ private DatabaseContext(IDefaultConnectionStringSource defaultConnectionStringSo } this.Server = new Server(new ServerConnection(new SqlConnection( - CoreDatabaseUtil.CutInitialCatalog(this.Main.ConnectionString)))); + CoreDatabaseUtil.CutInitialCatalog(this.Main.ConnectionString)))); } public Server Server @@ -85,5 +85,3 @@ private static string GetLocalDbConnectionString(string connectionString, string private static readonly Regex DataSourceRegex = new("Data Source=([^;]*)", RegexOptions.Compiled | RegexOptions.NonBacktracking); } - - diff --git a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseItem.cs b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseItem.cs index def25cdc1..78fccee19 100644 --- a/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseItem.cs +++ b/src/AutomationCore/Framework.AutomationCore/Utils/DatabaseUtils/DatabaseItem.cs @@ -19,8 +19,8 @@ public DatabaseItem( this.builder = new SqlConnectionStringBuilder(connectionString); initialCatalog ??= this.builder.InitialCatalog; this.DatabaseName = randomizeDatabaseName - ? $"{initialCatalog}{TextRandomizer.RandomString(5)}" - : initialCatalog; + ? $"{initialCatalog}{TextRandomizer.RandomString(5)}" + : initialCatalog; var fileName = $"{this.InstanceName}_{this.DatabaseName}_{TextRandomizer.RandomString(5)}"; @@ -40,8 +40,6 @@ public DatabaseItem( public string Password => this.builder.Password; - public bool IntegratedSecurity => this.builder.IntegratedSecurity; - public string ConnectionString => this.builder.ConnectionString; public string InstanceName => this.builder.DataSource.Split('\\').LastOrDefault(); diff --git a/src/BssFramework.slnx b/src/BssFramework.slnx index aaad9c732..7519c41e2 100644 --- a/src/BssFramework.slnx +++ b/src/BssFramework.slnx @@ -191,7 +191,6 @@ - diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs index 125b5b937..4848e9a02 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/NHibTestEnvironment.cs @@ -1,17 +1,11 @@ -using Anch.DependencyInjection; -using Anch.Testing; -using Anch.Testing.Database; -using Anch.Testing.Database.DependencyInjection; -using Anch.Testing.Database.Mssql; +using Anch.Testing.Database.DependencyInjection; using Anch.Testing.Xunit; using Bss.Platform.Events.Abstractions; using Framework.Application.Jobs; +using Framework.AutomationCore; using Framework.AutomationCore.ServiceEnvironment; -using Framework.AutomationCore.Settings; -using Framework.Database; -using Framework.Database.ConnectionStringSource; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -30,67 +24,34 @@ namespace SampleSystem.IntegrationTests._Environment; -public class NHibTestEnvironment : ITestEnvironment +public class NHibTestEnvironment : BssTestEnvironment { - private readonly IConfiguration configuration; + private const string SettingsFileName = "testAppSettings.json"; + protected override IConfiguration Configuration { get; } = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile(SettingsFileName, false, true) + .AddJsonFile($"{Environment.MachineName}.{SettingsFileName}", true) + .AddEnvironmentVariables(nameof(SampleSystem)).Build(); + protected override void InitInitializers(IDatabaseTestingSetup setup) => - private readonly AutomationFrameworkSettings settings = new(); + setup.SetEmptySchemaInitializer() + .SetTestDataInitializer(); - private readonly TestDatabaseSettings databaseSettings; - public NHibTestEnvironment() - { - var settingsFileName = "testAppSettings.json"; + protected override void InitServices(IServiceCollection services) => - this.configuration = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile(settingsFileName, false, true) - .AddJsonFile($"{Environment.MachineName}.{settingsFileName}", true) - .AddEnvironmentVariables(nameof(SampleSystem)).Build(); + services.AddGeneralDependencyInjection(this.Configuration, new HostingEnvironment(), s => s.AddExtensions(new SampleSystemNHibernateExtension())) - this.configuration.Bind(this.settings); + .AddSingleton() - var defaultConnectionString = this.configuration.GetConnectionString("DefaultConnection") - ?? throw new InvalidOperationException("DefaultConnection string is not configured."); + .AddIntegrationTests() - this.databaseSettings = new TestDatabaseSettings { InitMode = this.settings.DatabaseInitMode, DefaultConnectionString = new(defaultConnectionString) }; - } + .AddScoped() - public bool AllowParallelization => this.settings.TestsParallelize; + .AddSingleton(new JobImpersonateData("sampleSystemTestJob")) + .AddJobs([typeof(SampleJob).Assembly]) - public IServiceProvider BuildServiceProvider(IServiceCollection services) - { - services.AddOptions(); + .AddTestControllers([typeof(EmployeeController).Assembly]) - return services.AddSingleton(this.configuration) - - .AddGeneralDependencyInjection(this.configuration, new HostingEnvironment(), s => s.AddExtensions(new SampleSystemNHibernateExtension())) - - .AddSingleton() - - .AddIntegrationTests() - - .AddScoped() - - .AddSingleton(new JobImpersonateData("sampleSystemTestJob")) - .AddJobs([typeof(SampleJob).Assembly]) - - .AddTestControllers([typeof(EmployeeController).Assembly]) - - .AddSingleton() - - .AddSingleton() - .AddSingleton() - - .AddDatabaseTesting(dts => dts - .SetProvider() - .SetEmptySchemaInitializer() - .SetTestDataInitializer() - .SetSettings(this.databaseSettings) - .RebindActualConnection(connectionString => - new ManualDefaultConnectionStringSource(connectionString.Value))) - - .AddValidator() - .BuildServiceProvider(new ServiceProviderOptions { ValidateScopes = true, ValidateOnBuild = true }); - } + .AddSingleton(); }