From 4aea49f8ba76f477a33d0eac8c4f6d4d104990d6 Mon Sep 17 00:00:00 2001 From: "Atsuta, Ivan" Date: Sat, 13 Jun 2026 12:11:25 +0200 Subject: [PATCH] add SyncSubscriptionService --- .../ISubscriptionService.cs | 1 - .../ISyncSubscriptionService.cs | 9 + .../SyncSubscriptionService.cs | 12 ++ .../ServiceCollectionExtensions.cs | 1 + ...ionPrincipalsByHierarchicalContextTests.cs | 204 +++++++++--------- .../NotificationCountryTests.cs | 48 ++--- ...bscriptionCustomNotPersistentModelTests.cs | 12 +- .../_Environment/TestData/DefaultConstants.cs | 2 +- src/__SolutionItems/CommonAssemblyInfo.cs | 2 +- 9 files changed, 159 insertions(+), 132 deletions(-) create mode 100644 src/Subscriptions/Framework.Subscriptions.Abstractions/ISyncSubscriptionService.cs create mode 100644 src/Subscriptions/Framework.Subscriptions.Runtime/SyncSubscriptionService.cs diff --git a/src/Subscriptions/Framework.Subscriptions.Abstractions/ISubscriptionService.cs b/src/Subscriptions/Framework.Subscriptions.Abstractions/ISubscriptionService.cs index 8a34d7522..3b1584f46 100644 --- a/src/Subscriptions/Framework.Subscriptions.Abstractions/ISubscriptionService.cs +++ b/src/Subscriptions/Framework.Subscriptions.Abstractions/ISubscriptionService.cs @@ -7,4 +7,3 @@ public interface ISubscriptionService { IAsyncEnumerable> ProcessAsync(DomainObjectVersions versions); } - diff --git a/src/Subscriptions/Framework.Subscriptions.Abstractions/ISyncSubscriptionService.cs b/src/Subscriptions/Framework.Subscriptions.Abstractions/ISyncSubscriptionService.cs new file mode 100644 index 000000000..79d32f22a --- /dev/null +++ b/src/Subscriptions/Framework.Subscriptions.Abstractions/ISyncSubscriptionService.cs @@ -0,0 +1,9 @@ +using Framework.Core; +using Framework.Subscriptions.Domain; + +namespace Framework.Subscriptions; + +public interface ISyncSubscriptionService +{ + List> Process(DomainObjectVersions versions); +} diff --git a/src/Subscriptions/Framework.Subscriptions.Runtime/SyncSubscriptionService.cs b/src/Subscriptions/Framework.Subscriptions.Runtime/SyncSubscriptionService.cs new file mode 100644 index 000000000..7d0141a74 --- /dev/null +++ b/src/Subscriptions/Framework.Subscriptions.Runtime/SyncSubscriptionService.cs @@ -0,0 +1,12 @@ +using Anch.Core; + +using Framework.Core; +using Framework.Subscriptions.Domain; + +namespace Framework.Subscriptions; + +public class SyncSubscriptionService(ISubscriptionService subscriptionService, IDefaultCancellationTokenSource? defaultCancellationTokenSource = null) : ISyncSubscriptionService +{ + public List> Process(DomainObjectVersions versions) => + defaultCancellationTokenSource.RunSync(async ct => await subscriptionService.ProcessAsync(versions).ToListAsync(ct)); +} diff --git a/src/Subscriptions/Framework.Subscriptions/DependencyInjection/ServiceCollectionExtensions.cs b/src/Subscriptions/Framework.Subscriptions/DependencyInjection/ServiceCollectionExtensions.cs index 6d3d4e305..bb9821aee 100644 --- a/src/Subscriptions/Framework.Subscriptions/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/Subscriptions/Framework.Subscriptions/DependencyInjection/ServiceCollectionExtensions.cs @@ -34,6 +34,7 @@ public void AddSubscriptions( services.AddSingleton(); services.AddScoped(); + services.AddScoped(); services.AddSingleton(new EmployeeInfo(emailPath.ToPropertyAccessors())); services.AddScoped>(); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs index 58ceb7ed5..db9f7e34d 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/GetNotificationPrincipalsByHierarchicalContextTests.cs @@ -79,26 +79,26 @@ await this.AuthManager.For(this.searchNotificationEmployeeLogin2).SetRoleAsync( this.child_1_1_ManagementUnit), ct); var fbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(BusinessUnit), - ExpandType = NotificationExpandType.Direct, - Idents = [this.child_1_1_BusinessUnit.Id] - }; + { + SecurityContextType = typeof(BusinessUnit), + ExpandType = NotificationExpandType.Direct, + Idents = [this.child_1_1_BusinessUnit.Id] + }; var mbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(ManagementUnit), - ExpandType = NotificationExpandType.Direct, - Idents = [this.child_1_1_ManagementUnit.Id] - }; + { + SecurityContextType = typeof(ManagementUnit), + ExpandType = NotificationExpandType.Direct, + Idents = [this.child_1_1_ManagementUnit.Id] + }; var employeeFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(Employee), - ExpandType = NotificationExpandType.DirectOrFirstParent, - Idents = [this.rootEmployee.Id] - }; + { + SecurityContextType = typeof(Employee), + ExpandType = NotificationExpandType.DirectOrFirstParent, + Idents = [this.rootEmployee.Id] + }; // Act var result = await this.GetNotificationPrincipalsByRoles([fbuChildFilter, mbuChildFilter, employeeFilter], ct); @@ -120,18 +120,18 @@ public async Task GetPrincipals_Direct_Test2_Missed(CancellationToken ct) this.child_1_1_ManagementUnit), ct); var fbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(BusinessUnit), - ExpandType = NotificationExpandType.Direct, - Idents = [this.child_1_1_BusinessUnit.Id] - }; + { + SecurityContextType = typeof(BusinessUnit), + ExpandType = NotificationExpandType.Direct, + Idents = [this.child_1_1_BusinessUnit.Id] + }; var mbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(ManagementUnit), - ExpandType = NotificationExpandType.Direct, - Idents = [this.child_1_1_ManagementUnit.Id] - }; + { + SecurityContextType = typeof(ManagementUnit), + ExpandType = NotificationExpandType.Direct, + Idents = [this.child_1_1_ManagementUnit.Id] + }; // Act var result = await this.GetNotificationPrincipalsByRoles([fbuChildFilter, mbuChildFilter], ct); @@ -152,24 +152,26 @@ public async Task GetPrincipals_Direct_Test3_Missed(CancellationToken ct) this.child_1_1_ManagementUnit), ct); var fbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(BusinessUnit), - ExpandType = NotificationExpandType.DirectOrEmpty, - Idents = [this.child_1_1_BusinessUnit.Id] - }; + { + SecurityContextType = typeof(BusinessUnit), + ExpandType = NotificationExpandType.DirectOrEmpty, + Idents = [this.child_1_1_BusinessUnit.Id] + }; var mbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(ManagementUnit), - ExpandType = NotificationExpandType.DirectOrEmpty, - Idents = [this.child_1_1_ManagementUnit.Id] - }; + { + SecurityContextType = typeof(ManagementUnit), + ExpandType = NotificationExpandType.DirectOrEmpty, + Idents = [this.child_1_1_ManagementUnit.Id] + }; var employeeChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(Employee), ExpandType = NotificationExpandType.Direct, Idents = [this.rootEmployee.Id] - }; + { + SecurityContextType = typeof(Employee), + ExpandType = NotificationExpandType.Direct, + Idents = [this.rootEmployee.Id] + }; // Act var result = await this.GetNotificationPrincipalsByRoles([fbuChildFilter, mbuChildFilter, employeeChildFilter], ct); @@ -192,24 +194,26 @@ public async Task GetPrincipals_Direct_Test4_Searched(CancellationToken ct) var fbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(BusinessUnit), - ExpandType = NotificationExpandType.DirectOrFirstParentOrEmpty, - Idents = [this.child_1_1_BusinessUnit.Id] - }; + { + SecurityContextType = typeof(BusinessUnit), + ExpandType = NotificationExpandType.DirectOrFirstParentOrEmpty, + Idents = [this.child_1_1_BusinessUnit.Id] + }; var mbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(ManagementUnit), - ExpandType = NotificationExpandType.DirectOrFirstParentOrEmpty, - Idents = [this.child_1_1_ManagementUnit.Id] - }; + { + SecurityContextType = typeof(ManagementUnit), + ExpandType = NotificationExpandType.DirectOrFirstParentOrEmpty, + Idents = [this.child_1_1_ManagementUnit.Id] + }; var employeeChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(Employee), ExpandType = NotificationExpandType.Direct, Idents = [this.rootEmployee.Id] - }; + { + SecurityContextType = typeof(Employee), + ExpandType = NotificationExpandType.Direct, + Idents = [this.rootEmployee.Id] + }; // Act var result = await this.GetNotificationPrincipalsByRoles([fbuChildFilter, mbuChildFilter, employeeChildFilter], ct); @@ -235,18 +239,18 @@ public async Task GetPrincipals_DirectOrEmpty_Test1_Searched(CancellationToken c this.child_1_1_ManagementUnit), ct); var fbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(BusinessUnit), - ExpandType = NotificationExpandType.DirectOrEmpty, - Idents = [this.child_1_1_BusinessUnit.Id] - }; + { + SecurityContextType = typeof(BusinessUnit), + ExpandType = NotificationExpandType.DirectOrEmpty, + Idents = [this.child_1_1_BusinessUnit.Id] + }; var mbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(ManagementUnit), - ExpandType = NotificationExpandType.Direct, - Idents = [this.child_1_1_ManagementUnit.Id] - }; + { + SecurityContextType = typeof(ManagementUnit), + ExpandType = NotificationExpandType.Direct, + Idents = [this.child_1_1_ManagementUnit.Id] + }; // Act var result = await this.GetNotificationPrincipalsByRoles([fbuChildFilter, mbuChildFilter], ct); @@ -274,18 +278,18 @@ public async Task GetPrincipals_DirectOrFirstParentOrEmpty_Test1_Searched(Cancel this.child_1_1_ManagementUnit), ct); var fbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(BusinessUnit), - ExpandType = NotificationExpandType.DirectOrFirstParentOrEmpty, - Idents = [this.child_1_1_BusinessUnit.Id] - }; + { + SecurityContextType = typeof(BusinessUnit), + ExpandType = NotificationExpandType.DirectOrFirstParentOrEmpty, + Idents = [this.child_1_1_BusinessUnit.Id] + }; var mbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(ManagementUnit), - ExpandType = NotificationExpandType.Direct, - Idents = [this.child_1_1_ManagementUnit.Id] - }; + { + SecurityContextType = typeof(ManagementUnit), + ExpandType = NotificationExpandType.Direct, + Idents = [this.child_1_1_ManagementUnit.Id] + }; // Act var result = await this.GetNotificationPrincipalsByRoles([fbuChildFilter, mbuChildFilter], ct); @@ -312,18 +316,18 @@ public async Task GetPrincipals_DirectOrFirstParentOrEmpty_Test2_Searched(Cancel this.rootManagementUnit), ct); var fbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(BusinessUnit), - ExpandType = NotificationExpandType.DirectOrFirstParentOrEmpty, - Idents = [this.child_1_1_BusinessUnit.Id] - }; + { + SecurityContextType = typeof(BusinessUnit), + ExpandType = NotificationExpandType.DirectOrFirstParentOrEmpty, + Idents = [this.child_1_1_BusinessUnit.Id] + }; var mbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(ManagementUnit), - ExpandType = NotificationExpandType.DirectOrFirstParentOrEmpty, - Idents = [this.child_1_1_ManagementUnit.Id] - }; + { + SecurityContextType = typeof(ManagementUnit), + ExpandType = NotificationExpandType.DirectOrFirstParentOrEmpty, + Idents = [this.child_1_1_ManagementUnit.Id] + }; // Act var result = await this.GetNotificationPrincipalsByRoles([fbuChildFilter, mbuChildFilter], ct); @@ -353,18 +357,18 @@ public async Task GetPrincipals_DirectOrFirstParentOrEmpty_Test3_Searched(bool s var fbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(BusinessUnit), - ExpandType = NotificationExpandType.DirectOrFirstParentOrEmpty, - Idents = [this.child_1_1_BusinessUnit.Id] - }; + { + SecurityContextType = typeof(BusinessUnit), + ExpandType = NotificationExpandType.DirectOrFirstParentOrEmpty, + Idents = [this.child_1_1_BusinessUnit.Id] + }; var mbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(ManagementUnit), - ExpandType = NotificationExpandType.DirectOrFirstParentOrEmpty, - Idents = [this.child_1_1_ManagementUnit.Id] - }; + { + SecurityContextType = typeof(ManagementUnit), + ExpandType = NotificationExpandType.DirectOrFirstParentOrEmpty, + Idents = [this.child_1_1_ManagementUnit.Id] + }; // Act var result = swapPriority @@ -394,16 +398,18 @@ public async Task GetPrincipals_All_Test1_Searched(CancellationToken ct) var fbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(BusinessUnit), ExpandType = NotificationExpandType.All, Idents = [this.child_1_1_BusinessUnit.Id] - }; + { + SecurityContextType = typeof(BusinessUnit), + ExpandType = NotificationExpandType.All, + Idents = [this.child_1_1_BusinessUnit.Id] + }; var mbuChildFilter = new NotificationFilterGroup - { - SecurityContextType = typeof(ManagementUnit), - ExpandType = NotificationExpandType.Direct, - Idents = [this.child_1_1_ManagementUnit.Id] - }; + { + SecurityContextType = typeof(ManagementUnit), + ExpandType = NotificationExpandType.Direct, + Idents = [this.child_1_1_ManagementUnit.Id] + }; // Act var result = await this.GetNotificationPrincipalsByRoles([fbuChildFilter, mbuChildFilter], ct); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs index e48112623..c0afe1950 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/NotificationCountryTests.cs @@ -26,12 +26,12 @@ public void CreateAndUpdateCountry_SingleModificationExists() var bll = context.Logics.Country; var country = new Country - { - Code = Guid.NewGuid().ToString(), - NameNative = Guid.NewGuid().ToString(), - Culture = Guid.NewGuid().ToString(), - Name = Guid.NewGuid().ToString() - }; + { + Code = Guid.NewGuid().ToString(), + NameNative = Guid.NewGuid().ToString(), + Culture = Guid.NewGuid().ToString(), + Name = Guid.NewGuid().ToString() + }; bll.Save(country); @@ -66,12 +66,12 @@ public void CreateAndRemoveCountry_ModificationNotExists() var bll = context.Logics.Country; var country = new Country - { - Code = Guid.NewGuid().ToString(), - NameNative = Guid.NewGuid().ToString(), - Culture = Guid.NewGuid().ToString(), - Name = Guid.NewGuid().ToString() - }; + { + Code = Guid.NewGuid().ToString(), + NameNative = Guid.NewGuid().ToString(), + Culture = Guid.NewGuid().ToString(), + Name = Guid.NewGuid().ToString() + }; bll.Save(country); @@ -94,12 +94,12 @@ public void RemoveCountry_RemoveModificationExists() var bll = context.Logics.Country; var country = new Country - { - Code = Guid.NewGuid().ToString(), - NameNative = Guid.NewGuid().ToString(), - Culture = Guid.NewGuid().ToString(), - Name = Guid.NewGuid().ToString() - }; + { + Code = Guid.NewGuid().ToString(), + NameNative = Guid.NewGuid().ToString(), + Culture = Guid.NewGuid().ToString(), + Name = Guid.NewGuid().ToString() + }; bll.Save(country); @@ -134,12 +134,12 @@ public async Task EmulateFailureCountryModification_RaisedException(Cancellation context => { var fakeModification = new DomainObjectModification() - { - DomainType = context.Configuration.GetDomainType(typeof(Country)), - Type = ModificationType.Save, - Revision = revision, - DomainObjectId = domainObjectId - }; + { + DomainType = context.Configuration.GetDomainType(typeof(Country)), + Type = ModificationType.Save, + Revision = revision, + DomainObjectId = domainObjectId + }; context.Configuration.Logics.DomainObjectModification.Save(fakeModification); }); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SubscriptionCustomNotPersistentModelTests.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SubscriptionCustomNotPersistentModelTests.cs index e2a34be19..916194fcd 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SubscriptionCustomNotPersistentModelTests.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/SubscriptionCustomNotPersistentModelTests.cs @@ -20,12 +20,12 @@ public async Task CustomNotPersistentNotificationModel_Always_ShouldNotThrowExce context => { var country = new Country - { - Code = Guid.NewGuid().ToString(), - NameNative = Guid.NewGuid().ToString(), - Culture = Guid.NewGuid().ToString(), - Name = Guid.NewGuid().ToString() - }; + { + Code = Guid.NewGuid().ToString(), + NameNative = Guid.NewGuid().ToString(), + Culture = Guid.NewGuid().ToString(), + Name = Guid.NewGuid().ToString() + }; context.Logics.Country.Save(country); diff --git a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/DefaultConstants.cs b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/DefaultConstants.cs index 7da018175..62e056851 100644 --- a/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/DefaultConstants.cs +++ b/src/_SampleSystem/_Tests/SampleSystem.IntegrationTests.NHibernate/_Environment/TestData/DefaultConstants.cs @@ -143,6 +143,6 @@ public static class DefaultConstants /// public static readonly Guid HRDepartment_DEFAULT_HEAD_EMPLOYEE_ID = new("2B2B2B2B-0000-0000-0007-000000000002"); - + public const string INTEGRATION_BUS = "IntegrationBus"; } diff --git a/src/__SolutionItems/CommonAssemblyInfo.cs b/src/__SolutionItems/CommonAssemblyInfo.cs index 533f93a6b..01855f213 100644 --- a/src/__SolutionItems/CommonAssemblyInfo.cs +++ b/src/__SolutionItems/CommonAssemblyInfo.cs @@ -4,7 +4,7 @@ [assembly: AssemblyCompany("Luxoft")] [assembly: AssemblyCopyright("Copyright © Luxoft 2009-2026")] -[assembly: AssemblyVersion("27.3.1.0")] +[assembly: AssemblyVersion("27.3.2.0")] #if DEBUG [assembly: AssemblyConfiguration("Debug")]