From fb9b5be234261785c0a8bb5511e99f6966238bc2 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Sat, 28 Nov 2020 09:55:59 +0800 Subject: [PATCH] Remove some interfaces from the message repository --- .vs/VSWorkspaceState.json | 7 ++ .vs/slnx.sqlite | Bin 13246464 -> 13328384 bytes aspnet-core/LINGYUN.MicroService.Messages.sln | 29 ++++- .../LINGYUN.Abp.EventBus.CAP/LICENSE.txt | 1 + .../common/LINGYUN.Abp.EventBus.CAP/README.md | 17 +++ .../AbpNotificationCleanupOptions.cs | 4 +- .../Abp/Notifications/INotificationStore.cs | 6 +- .../Notifications/NullNotificationStore.cs | 13 +-- .../LINGYUN.Abp.Notifications/README.md | 19 +++ .../Dto/UserNotificationGetByPagedDto.cs | 2 +- .../AbpMessageServiceDomainModule.cs | 11 ++ .../IUserNotificationRepository.cs | 14 +-- .../Notifications/NotificationStore.cs | 23 ++-- .../Utils/SnowflakeIdGenerator.cs | 109 ++++++++++++++++++ .../Utils/SnowflakeIdOptions.cs | 24 ++++ .../EfCoreUserNotificationRepository.cs | 60 +++++----- .../BackendAdminHostModule.cs | 5 +- .../Utils/SnowflakeIdGenerator.cs | 16 --- ...YUN.Abp.MessageService.Domain.Tests.csproj | 23 ++++ .../AbpMessageServiceDomainTestModule.cs | 36 ++++++ .../AbpNotificationsTestsDataBuilder.cs | 75 ++++++++++++ ...geService.EntityFrameworkCore.Tests.csproj | 24 ++++ ...ssageServiceEntityFrameworkCoreTestBase.cs | 8 ++ ...ageServiceEntityFrameworkCoreTestModule.cs | 15 +++ .../UserNotificationRepositoryTests.cs | 81 +++++++++++++ .../AbpNotificationsTestsModule.cs | 1 - .../Notifications/NotificationsTestConsts.cs | 15 +++ 27 files changed, 553 insertions(+), 85 deletions(-) create mode 100644 .vs/VSWorkspaceState.json create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/README.md create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Notifications/README.md create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/SnowflakeIdGenerator.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/SnowflakeIdOptions.cs delete mode 100644 aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Utils/SnowflakeIdGenerator.cs create mode 100644 aspnet-core/tests/LINGYUN.Abp.MessageService.Domain.Tests/LINGYUN.Abp.MessageService.Domain.Tests.csproj create mode 100644 aspnet-core/tests/LINGYUN.Abp.MessageService.Domain.Tests/LINGYUN/Abp/MessageService/AbpMessageServiceDomainTestModule.cs create mode 100644 aspnet-core/tests/LINGYUN.Abp.MessageService.Domain.Tests/LINGYUN/Abp/MessageService/AbpNotificationsTestsDataBuilder.cs create mode 100644 aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests.csproj create mode 100644 aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreTestBase.cs create mode 100644 aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreTestModule.cs create mode 100644 aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN/Abp/MessageService/Notifications/UserNotificationRepositoryTests.cs create mode 100644 aspnet-core/tests/LINGYUN.Abp.Notifications.Tests/LINGYUN/Abp/Notifications/NotificationsTestConsts.cs diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 000000000..e23d5cfc9 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,7 @@ +{ + "ExpandedNodes": [ + "" + ], + "SelectedNode": "\\D:\\Projects\\MicroService\\CRM\\Vue\\vue-abp", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index f8debc5aae9f597b9e98414851ff62c95245a922..3963a2ce96138b242993d1bd4c644116c4175592 100644 GIT binary patch delta 52547 zcmcg#30PEDmPU~RWGP%wS%jk46$;$9u!&1rqmVYH6T?zPQD6yFl~sj`i9#mnj!7pP zljt#>R?Mm~Du^pCP>Cj~vOCK3bWeA>CrVE;nRNF=neLgdC)2I=xvwY|3%Hl}-o@|x z{q*B-{`cQ=mvfhQUxVYYqQP-Y@p6=(ua8ggncb?KQNAa%2bJUee0+RHDgTCl2cJ>? zE%<6MJe(Wy=-Dnu?5`AOGe-wh`NhZijq%AJx5Q9ZTlt92T4}J`*4hl#H3qxgXsWcW zG}Jv&eDZ4a3}18=eA=%?bx#?t7>f=S%Jn|V-zs+~uP6^I*DG(I{kc2oa13L4+cdh%m%B#CXI6#6(0mViIC9VhSPx5s8RGL?fmmVi2(i z6(SCyM#Li$5Q&H+L^2`;k&2jxn2tz8q$4zl3`8bk24W^+7GgGH4q`519%4RX0b(Iy z5#j+v79tx#wC5u75Q`D{h$V=nh-HZ7hzAkhL##loL_CC8g;JVEIPa>W|Y(s2E)FT=YPb2;b@eJZw#19caLOh4qfp{MA z0^-Mr7ZEQZb|Q8mUPkOjyn=WY@fua>utD&ddXq^mKg7pl}k z`+6$RRF_}4R_*@jwr;B@dyFmaMhY{U)@q=1?zxHZZwG!b4Prvh`L9)})ZIUJcMs@P zE+(yVO%Pb>A07+$z9^r=nJF4BnM#8IIU}IyONBpdUwtKjALj!wZq*}G;r3XyqFCJ< z7CuF}9RB+HrJ4N1Xh^XILD-jya46k(DT^Od1~^u=j|21S_6$xWc{d-+fiI4)i!b6D z6{N|4gQmyBVYlh=M2NMI=3NisZWd)g^YzDrp!0?1RDPwG1(ttR`$PNjbd?)6KVT$wU-kx;q% zN1@P|p^Jjf&$zc=L10JQjsVcshWNpo)3!_^|5E7nHZp2(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TGXZvDWp=Ddeo-@4QWJUn$VPHG^YhE zX+>+=(3W9OMv(Il@tnahwyJ;br#vIdb6)V0SG?v8Z+S-n@A<$-3i-rm NzVI~~N&A-Z>mSrLj>!N3 diff --git a/aspnet-core/LINGYUN.MicroService.Messages.sln b/aspnet-core/LINGYUN.MicroService.Messages.sln index a3daf872b..be9e5a1a2 100644 --- a/aspnet-core/LINGYUN.MicroService.Messages.sln +++ b/aspnet-core/LINGYUN.MicroService.Messages.sln @@ -53,17 +53,23 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.WeChat.MiniProg EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Notifications.Sms", "modules\common\LINGYUN.Abp.Notifications.Sms\LINGYUN.Abp.Notifications.Sms.csproj", "{454059F7-D087-439A-A724-80BDFE94776F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Notifications.WeChat.MiniProgram", "modules\wechat\LINGYUN.Abp.Notifications.WeChat.MiniProgram\LINGYUN.Abp.Notifications.WeChat.MiniProgram.csproj", "{64E2622A-611D-4056-9497-0B52A91DC59C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Notifications.WeChat.MiniProgram", "modules\wechat\LINGYUN.Abp.Notifications.WeChat.MiniProgram\LINGYUN.Abp.Notifications.WeChat.MiniProgram.csproj", "{64E2622A-611D-4056-9497-0B52A91DC59C}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{42800C56-9473-4B96-BF29-1B0F25C867F4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Notifications.Sms.Tests", "tests\LINGYUN.Abp.Notifications.Sms.Tests\LINGYUN.Abp.Notifications.Sms.Tests.csproj", "{5714481A-BDF5-4860-9158-3B18D3018EC5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Notifications.Sms.Tests", "tests\LINGYUN.Abp.Notifications.Sms.Tests\LINGYUN.Abp.Notifications.Sms.Tests.csproj", "{5714481A-BDF5-4860-9158-3B18D3018EC5}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.TestsBase", "tests\LINGYUN.Abp.TestBase\LINGYUN.Abp.TestsBase.csproj", "{B5E23AED-3068-4CFE-84B0-3B7725665506}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Notifications.Tests", "tests\LINGYUN.Abp.Notifications.Tests\LINGYUN.Abp.Notifications.Tests.csproj", "{E5257008-A0AD-473F-91B0-864FC601B84B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Notifications.Tests", "tests\LINGYUN.Abp.Notifications.Tests\LINGYUN.Abp.Notifications.Tests.csproj", "{E5257008-A0AD-473F-91B0-864FC601B84B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Notifications.WeChat.MiniProgram.Tests", "tests\LINGYUN.Abp.Notifications.WeChat.MiniProgram.Tests\LINGYUN.Abp.Notifications.WeChat.MiniProgram.Tests.csproj", "{DB425943-CEE6-4FF6-A0EE-233B6ADA3BD7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Notifications.WeChat.MiniProgram.Tests", "tests\LINGYUN.Abp.Notifications.WeChat.MiniProgram.Tests\LINGYUN.Abp.Notifications.WeChat.MiniProgram.Tests.csproj", "{DB425943-CEE6-4FF6-A0EE-233B6ADA3BD7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.EntityFrameworkCore.Tests", "tests\LINGYUN.Abp.EntityFrameworkCore.Tests\LINGYUN.Abp.EntityFrameworkCore.Tests.csproj", "{25267137-08BE-44A6-9F7E-7783CC8C62E8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests", "tests\LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests\LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests.csproj", "{CB6D56DA-539B-4D4F-81CD-D683ADEBFB5F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.MessageService.Domain.Tests", "tests\LINGYUN.Abp.MessageService.Domain.Tests\LINGYUN.Abp.MessageService.Domain.Tests.csproj", "{097319B9-D062-4A54-8F8C-001C180E2CB3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -171,6 +177,18 @@ Global {DB425943-CEE6-4FF6-A0EE-233B6ADA3BD7}.Debug|Any CPU.Build.0 = Debug|Any CPU {DB425943-CEE6-4FF6-A0EE-233B6ADA3BD7}.Release|Any CPU.ActiveCfg = Release|Any CPU {DB425943-CEE6-4FF6-A0EE-233B6ADA3BD7}.Release|Any CPU.Build.0 = Release|Any CPU + {25267137-08BE-44A6-9F7E-7783CC8C62E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {25267137-08BE-44A6-9F7E-7783CC8C62E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {25267137-08BE-44A6-9F7E-7783CC8C62E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {25267137-08BE-44A6-9F7E-7783CC8C62E8}.Release|Any CPU.Build.0 = Release|Any CPU + {CB6D56DA-539B-4D4F-81CD-D683ADEBFB5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CB6D56DA-539B-4D4F-81CD-D683ADEBFB5F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CB6D56DA-539B-4D4F-81CD-D683ADEBFB5F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CB6D56DA-539B-4D4F-81CD-D683ADEBFB5F}.Release|Any CPU.Build.0 = Release|Any CPU + {097319B9-D062-4A54-8F8C-001C180E2CB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {097319B9-D062-4A54-8F8C-001C180E2CB3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {097319B9-D062-4A54-8F8C-001C180E2CB3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {097319B9-D062-4A54-8F8C-001C180E2CB3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -204,6 +222,9 @@ Global {B5E23AED-3068-4CFE-84B0-3B7725665506} = {42800C56-9473-4B96-BF29-1B0F25C867F4} {E5257008-A0AD-473F-91B0-864FC601B84B} = {42800C56-9473-4B96-BF29-1B0F25C867F4} {DB425943-CEE6-4FF6-A0EE-233B6ADA3BD7} = {42800C56-9473-4B96-BF29-1B0F25C867F4} + {25267137-08BE-44A6-9F7E-7783CC8C62E8} = {42800C56-9473-4B96-BF29-1B0F25C867F4} + {CB6D56DA-539B-4D4F-81CD-D683ADEBFB5F} = {42800C56-9473-4B96-BF29-1B0F25C867F4} + {097319B9-D062-4A54-8F8C-001C180E2CB3} = {42800C56-9473-4B96-BF29-1B0F25C867F4} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {6238659A-7267-49B9-A499-8746BDEED6B8} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LICENSE.txt b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LICENSE.txt index e62cd50c0..5e48277d6 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LICENSE.txt +++ b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/LICENSE.txt @@ -21,4 +21,5 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ģԴ +https://github.com/dotnetcore/CAP https://github.com/EasyAbp/Abp.EventBus.CAP diff --git a/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/README.md b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/README.md new file mode 100644 index 000000000..f6f444444 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.EventBus.CAP/README.md @@ -0,0 +1,17 @@ +# LINGYUN.Abp.EventBus.CAP + +分布式事件总线 CAP 集成 + +#### 注意 + +* 由于 CAP 官方模块中, MySqlConnector 为高版本,与 Volo.Abp.EntityFrameworkCore.MySQL 依赖版本不兼容 +当 Abp 框架升级到 4.0 版本之后,此模块升级为 CAP 最新版本 + +## 配置使用 + +```csharp +[DependsOn(typeof(AbpCAPEventBusModule))] +public class YouProjectModule : AbpModule +{ + // other +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationCleanupOptions.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationCleanupOptions.cs index 3c92996b2..2fe7b3a1f 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationCleanupOptions.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/AbpNotificationCleanupOptions.cs @@ -9,9 +9,9 @@ public bool IsEnabled { get; set; } = true; /// /// 清理时间间隔 - /// 默认:300000ms + /// 默认:30_0000ms /// - public int CleanupPeriod { get; set; } = 300000; + public int CleanupPeriod { get; set; } = 30_0000; /// /// 清理批次 /// 默认: 200 diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationStore.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationStore.cs index 57040f150..9bbc95eb3 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationStore.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationStore.cs @@ -94,7 +94,7 @@ namespace LINGYUN.Abp.Notifications Task> GetUserNotificationsAsync( Guid? tenantId, Guid userId, - NotificationReadState readState = NotificationReadState.UnRead, + NotificationReadState? readState = null, int maxResultCount = 10, CancellationToken cancellationToken = default); @@ -102,7 +102,7 @@ namespace LINGYUN.Abp.Notifications Guid? tenantId, Guid userId, string filter = "", - NotificationReadState readState = NotificationReadState.UnRead, + NotificationReadState? readState = null, CancellationToken cancellationToken = default); Task> GetUserNotificationsAsync( @@ -111,7 +111,7 @@ namespace LINGYUN.Abp.Notifications string filter = "", string sorting = nameof(NotificationInfo.CreationTime), bool reverse = true, - NotificationReadState readState = NotificationReadState.UnRead, + NotificationReadState? readState = null, int skipCount = 1, int maxResultCount = 10, CancellationToken cancellationToken = default); diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NullNotificationStore.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NullNotificationStore.cs index a954bdddc..8062548a5 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NullNotificationStore.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NullNotificationStore.cs @@ -6,9 +6,8 @@ using Volo.Abp.DependencyInjection; namespace LINGYUN.Abp.Notifications { - [Dependency(Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton, TryRegister = true)] - [ExposeServices(typeof(INotificationStore))] - public class NullNotificationStore : INotificationStore + [Dependency(TryRegister = true)] + public class NullNotificationStore : INotificationStore, ISingletonDependency { public Task ChangeUserNotificationReadStateAsync( Guid? tenantId, @@ -88,8 +87,8 @@ namespace LINGYUN.Abp.Notifications public Task> GetUserNotificationsAsync( Guid? tenantId, - Guid userId, - NotificationReadState readState = NotificationReadState.UnRead, + Guid userId, + NotificationReadState? readState = null, int maxResultCount = 10, CancellationToken cancellationToken = default) { @@ -100,7 +99,7 @@ namespace LINGYUN.Abp.Notifications Guid? tenantId, Guid userId, string filter = "", - NotificationReadState readState = NotificationReadState.UnRead, + NotificationReadState? readState = null, CancellationToken cancellationToken = default) { return Task.FromResult(0); @@ -112,7 +111,7 @@ namespace LINGYUN.Abp.Notifications string filter = "", string sorting = nameof(NotificationInfo.CreationTime), bool reverse = true, - NotificationReadState readState = NotificationReadState.UnRead, + NotificationReadState? readState = null, int skipCount = 1, int maxResultCount = 10, CancellationToken cancellationToken = default) diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/README.md b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/README.md new file mode 100644 index 000000000..df6076035 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/README.md @@ -0,0 +1,19 @@ +# LINGYUN.Abp.Notifications + +实时通知基础模块 + + +#### 注意 + +* 当前的通知数据模型 NotificationData 设计极度不合理 + + 将在框架升级为4.0版本之后变更,将与现有通知数据不兼容(这可能就是敏捷开发的避免吧 ;) ) + +## 配置使用 + +```csharp +[DependsOn(typeof(AbpNotificationModule))] +public class YouProjectModule : AbpModule +{ + // other +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationGetByPagedDto.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationGetByPagedDto.cs index b1e811463..4f4651498 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationGetByPagedDto.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/Dto/UserNotificationGetByPagedDto.cs @@ -9,6 +9,6 @@ namespace LINGYUN.Abp.MessageService.Notifications public bool Reverse { get; set; } - public NotificationReadState ReadState { get; set; } = NotificationReadState.Read; + public NotificationReadState? ReadState { get; set; } } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/AbpMessageServiceDomainModule.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/AbpMessageServiceDomainModule.cs index 2f19e44ef..53ec1d2bd 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/AbpMessageServiceDomainModule.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/AbpMessageServiceDomainModule.cs @@ -2,6 +2,9 @@ using LINGYUN.Abp.MessageService.Localization; using LINGYUN.Abp.MessageService.Mapper; using LINGYUN.Abp.MessageService.ObjectExtending; +using LINGYUN.Abp.MessageService.Utils; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; using Volo.Abp.AutoMapper; using Volo.Abp.Caching; using Volo.Abp.Localization; @@ -51,5 +54,13 @@ namespace LINGYUN.Abp.MessageService typeof(Message) ); } + + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + context + .ServiceProvider + .GetRequiredService() + .Initialize(); + } } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/IUserNotificationRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/IUserNotificationRepository.cs index 6942ac069..16312df09 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/IUserNotificationRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/IUserNotificationRepository.cs @@ -25,14 +25,14 @@ namespace LINGYUN.Abp.MessageService.Notifications Task> GetNotificationsAsync( Guid userId, - NotificationReadState readState = NotificationReadState.UnRead, + NotificationReadState? readState = null, int maxResultCount = 10, CancellationToken cancellationToken = default); Task GetCountAsync( Guid userId, string filter = "", - NotificationReadState readState = NotificationReadState.UnRead, + NotificationReadState? readState = null, CancellationToken cancellationToken = default); Task> GetListAsync( @@ -40,15 +40,9 @@ namespace LINGYUN.Abp.MessageService.Notifications string filter = "", string sorting = nameof(Notification.CreationTime), bool reverse = true, - NotificationReadState readState = NotificationReadState.UnRead, - int skipCount = 1, + NotificationReadState? readState = null, + int skipCount = 0, int maxResultCount = 10, CancellationToken cancellationToken = default); - - Task ChangeUserNotificationReadStateAsync( - Guid userId, - long notificationId, - NotificationReadState readState, - CancellationToken cancellationToken = default); } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs index b3a77f5b0..c02be6207 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs @@ -1,6 +1,7 @@ using LINGYUN.Abp.MessageService.Subscriptions; using LINGYUN.Abp.MessageService.Utils; using LINGYUN.Abp.Notifications; +using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Linq; @@ -15,7 +16,9 @@ using Volo.Abp.Uow; namespace LINGYUN.Abp.MessageService.Notifications { - public class NotificationStore : INotificationStore, ITransientDependency + [Dependency(ServiceLifetime.Transient, ReplaceServices = true)] + [ExposeServices(typeof(INotificationStore))] + public class NotificationStore : INotificationStore { private readonly IClock _clock; @@ -68,10 +71,14 @@ namespace LINGYUN.Abp.MessageService.Notifications using (var unitOfWork = _unitOfWorkManager.Begin()) using (_currentTenant.Change(tenantId)) { - await _userNotificationRepository - .ChangeUserNotificationReadStateAsync(userId, notificationId, readState, cancellationToken); + var notification = await _userNotificationRepository.GetByIdAsync(userId, notificationId); + if (notification != null) + { + notification.ChangeReadState(readState); + await _userNotificationRepository.UpdateAsync(notification); - await unitOfWork.SaveChangesAsync(); + await unitOfWork.SaveChangesAsync(); + } } } @@ -212,8 +219,8 @@ namespace LINGYUN.Abp.MessageService.Notifications public virtual async Task> GetUserNotificationsAsync( Guid? tenantId, - Guid userId, - NotificationReadState readState = NotificationReadState.UnRead, + Guid userId, + NotificationReadState? readState = null, int maxResultCount = 10, CancellationToken cancellationToken = default) { @@ -230,7 +237,7 @@ namespace LINGYUN.Abp.MessageService.Notifications Guid? tenantId, Guid userId, string filter = "", - NotificationReadState readState = NotificationReadState.UnRead, + NotificationReadState? readState = null, CancellationToken cancellationToken = default) { using (_currentTenant.Change(tenantId)) @@ -246,7 +253,7 @@ namespace LINGYUN.Abp.MessageService.Notifications string filter = "", string sorting = nameof(NotificationInfo.CreationTime), bool reverse = true, - NotificationReadState readState = NotificationReadState.UnRead, + NotificationReadState? readState = null, int skipCount = 1, int maxResultCount = 10, CancellationToken cancellationToken = default) diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/SnowflakeIdGenerator.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/SnowflakeIdGenerator.cs new file mode 100644 index 000000000..65a67ecc6 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/SnowflakeIdGenerator.cs @@ -0,0 +1,109 @@ +using Microsoft.Extensions.Options; +using System; +using Volo.Abp; +using Volo.Abp.DependencyInjection; + +namespace LINGYUN.Abp.MessageService.Utils +{ + // reference: https://github.com/dotnetcore/CAP + // reference: https://blog.csdn.net/lq18050010830/article/details/89845790 + public class SnowflakeIdGenerator : ISnowflakeIdGenerator, ISingletonDependency + { + public const long Twepoch = 1288834974657L; + + private static readonly object _lock = new object(); + private long _lastTimestamp = -1L; + + protected long MaxWorkerId { get; set; } + protected long MaxDatacenterId { get; set; } + + protected int WorkerIdShift { get; } + protected int DatacenterIdShift { get; } + protected int TimestampLeftShift { get; } + protected long SequenceMask { get; } + + protected SnowflakeIdOptions Options { get; } + + public SnowflakeIdGenerator(IOptions options) + { + Options = options.Value; + + WorkerIdShift = Options.SequenceBits; + DatacenterIdShift = Options.SequenceBits + Options.WorkerIdBits; + TimestampLeftShift = Options.SequenceBits + Options.WorkerIdBits + Options.DatacenterIdBits; + SequenceMask = -1L ^ (-1L << Options.SequenceBits); + } + + internal void Initialize(long sequence = 0L) + { + Sequence = sequence; + MaxWorkerId = -1L ^ (-1L << Options.WorkerIdBits); + MaxDatacenterId = -1L ^ (-1L << Options.DatacenterIdBits); + + if (!int.TryParse(Environment.GetEnvironmentVariable("WORKERID", EnvironmentVariableTarget.Machine), out var workerId)) + { + workerId = RandomHelper.GetRandom((int)MaxWorkerId); + } + + if (!int.TryParse(Environment.GetEnvironmentVariable("DATACENTERID", EnvironmentVariableTarget.Machine), out var datacenterId)) + { + datacenterId = RandomHelper.GetRandom((int)MaxDatacenterId); + } + + if (workerId > MaxWorkerId || workerId < 0) + throw new ArgumentException($"worker Id can't be greater than {MaxWorkerId} or less than 0"); + + if (datacenterId > MaxDatacenterId || datacenterId < 0) + throw new ArgumentException($"datacenter Id can't be greater than {MaxDatacenterId} or less than 0"); + + WorkerId = workerId; + DatacenterId = datacenterId; + + } + + public long WorkerId { get; protected set; } + public long DatacenterId { get; protected set; } + public long Sequence { get; protected set; } + + public virtual long Create() + { + lock (_lock) + { + var timestamp = TimeGen(); + + if (timestamp < _lastTimestamp) + throw new Exception( + $"InvalidSystemClock: Clock moved backwards, Refusing to generate id for {_lastTimestamp - timestamp} milliseconds"); + + if (_lastTimestamp == timestamp) + { + Sequence = (Sequence + 1) & SequenceMask; + if (Sequence == 0) timestamp = TilNextMillis(_lastTimestamp); + } + else + { + Sequence = 0; + } + + _lastTimestamp = timestamp; + var id = ((timestamp - Twepoch) << TimestampLeftShift) | + (DatacenterId << DatacenterIdShift) | + (WorkerId << WorkerIdShift) | Sequence; + + return id; + } + } + + protected virtual long TilNextMillis(long lastTimestamp) + { + var timestamp = TimeGen(); + while (timestamp <= lastTimestamp) timestamp = TimeGen(); + return timestamp; + } + + protected virtual long TimeGen() + { + return DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); + } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/SnowflakeIdOptions.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/SnowflakeIdOptions.cs new file mode 100644 index 000000000..ac594b900 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Utils/SnowflakeIdOptions.cs @@ -0,0 +1,24 @@ +namespace LINGYUN.Abp.MessageService.Utils +{ + public class SnowflakeIdOptions + { + /// + /// 机器Id长度 + /// + public int WorkerIdBits { get; set; } + /// + /// 机房Id长度 + /// + public int DatacenterIdBits { get; set; } + /// + /// 每秒生成Id的数量 + /// + public int SequenceBits { get; set; } + public SnowflakeIdOptions() + { + WorkerIdBits = 5; + DatacenterIdBits = 5; + SequenceBits = 12; + } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreUserNotificationRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreUserNotificationRepository.cs index ee89175f9..2d410e561 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreUserNotificationRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreUserNotificationRepository.cs @@ -39,18 +39,6 @@ namespace LINGYUN.Abp.MessageService.Notifications await DbSet.AddRangeAsync(userNotifications, GetCancellationToken(cancellationToken)); } - public virtual async Task ChangeUserNotificationReadStateAsync( - Guid userId, - long notificationId, - NotificationReadState readState, - CancellationToken cancellationToken = default) - { - var userNofitication = await GetByIdAsync(userId, notificationId, cancellationToken); - userNofitication.ChangeReadState(readState); - - DbSet.Update(userNofitication); - } - public virtual async Task GetByIdAsync( Guid userId, long notificationId, @@ -65,17 +53,20 @@ namespace LINGYUN.Abp.MessageService.Notifications public virtual async Task> GetNotificationsAsync( Guid userId, - NotificationReadState readState = NotificationReadState.UnRead, + NotificationReadState? readState = null, int maxResultCount = 10, CancellationToken cancellationToken = default) { - var userNotifilerQuery = from un in DbContext.Set() - join n in DbContext.Set() + var userNotifilerQuery = DbContext.Set() + .Where(x => x.UserId == userId) + .WhereIf(readState.HasValue, x => x.ReadStatus == readState.Value); + + var notifilerQuery = from un in userNotifilerQuery + join n in DbContext.Set() on un.NotificationId equals n.NotificationId - where un.UserId.Equals(userId) && un.ReadStatus.Equals(readState) - select n; + select n; - return await userNotifilerQuery + return await notifilerQuery .OrderBy(nameof(Notification.CreationTime) + " DESC") .Take(maxResultCount) .AsNoTracking() @@ -84,17 +75,20 @@ namespace LINGYUN.Abp.MessageService.Notifications public virtual async Task GetCountAsync( Guid userId, - string filter = "", - NotificationReadState readState = NotificationReadState.UnRead, + string filter = "", + NotificationReadState? readState = null, CancellationToken cancellationToken = default) { - var userNotifilerQuery = from un in DbContext.Set() - join n in DbContext.Set() + var userNotifilerQuery = DbContext.Set() + .Where(x => x.UserId == userId) + .WhereIf(readState.HasValue, x => x.ReadStatus == readState.Value); + + var notifilerQuery = from un in userNotifilerQuery + join n in DbContext.Set() on un.NotificationId equals n.NotificationId - where un.UserId.Equals(userId) && un.ReadStatus.Equals(readState) - select n; + select n; - return await userNotifilerQuery + return await notifilerQuery .WhereIf(!filter.IsNullOrWhiteSpace(), nf => nf.NotificationName.Contains(filter) || nf.NotificationTypeName.Contains(filter)) @@ -106,7 +100,7 @@ namespace LINGYUN.Abp.MessageService.Notifications string filter = "", string sorting = nameof(Notification.CreationTime), bool reverse = true, - NotificationReadState readState = NotificationReadState.UnRead, + NotificationReadState? readState = null, int skipCount = 1, int maxResultCount = 10, CancellationToken cancellationToken = default) @@ -114,13 +108,17 @@ namespace LINGYUN.Abp.MessageService.Notifications sorting ??= nameof(Notification.CreationTime); sorting = reverse ? sorting + " DESC" : sorting; - var userNotifilerQuery = from un in DbContext.Set() - join n in DbContext.Set() + + var userNotifilerQuery = DbContext.Set() + .Where(x => x.UserId == userId) + .WhereIf(readState.HasValue, x => x.ReadStatus == readState.Value); + + var notifilerQuery = from un in userNotifilerQuery + join n in DbContext.Set() on un.NotificationId equals n.NotificationId - where un.UserId.Equals(userId) && un.ReadStatus.Equals(readState) - select n; + select n; - return await userNotifilerQuery + return await notifilerQuery .WhereIf(!filter.IsNullOrWhiteSpace(), nf => nf.NotificationName.Contains(filter) || nf.NotificationTypeName.Contains(filter)) diff --git a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs index 813ddbce0..c6f3ec8e2 100644 --- a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs +++ b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs @@ -349,10 +349,11 @@ namespace LINGYUN.Abp.BackendAdmin // 路由 app.UseConfiguredEndpoints(); + // 调试代理连接信息用,上线后注释掉 + app.UseProxyConnectTest(); + if (context.GetEnvironment().IsDevelopment()) { - // 开发模式下调试代理连接信息用 - app.UseProxyConnectTest(); SeedData(context); } } diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Utils/SnowflakeIdGenerator.cs b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Utils/SnowflakeIdGenerator.cs deleted file mode 100644 index 0b5d5b0c8..000000000 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Utils/SnowflakeIdGenerator.cs +++ /dev/null @@ -1,16 +0,0 @@ -using DotNetCore.CAP.Internal; -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.DependencyInjection; - -namespace LINGYUN.Abp.MessageService.Utils -{ - [Dependency(ServiceLifetime.Singleton, TryRegister = true)] - [ExposeServices(typeof(ISnowflakeIdGenerator))] - public class SnowflakeIdGenerator : ISnowflakeIdGenerator - { - public long Create() - { - return SnowflakeId.Default().NextId(); - } - } -} diff --git a/aspnet-core/tests/LINGYUN.Abp.MessageService.Domain.Tests/LINGYUN.Abp.MessageService.Domain.Tests.csproj b/aspnet-core/tests/LINGYUN.Abp.MessageService.Domain.Tests/LINGYUN.Abp.MessageService.Domain.Tests.csproj new file mode 100644 index 000000000..cc3016aab --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.MessageService.Domain.Tests/LINGYUN.Abp.MessageService.Domain.Tests.csproj @@ -0,0 +1,23 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + + + + + + + + diff --git a/aspnet-core/tests/LINGYUN.Abp.MessageService.Domain.Tests/LINGYUN/Abp/MessageService/AbpMessageServiceDomainTestModule.cs b/aspnet-core/tests/LINGYUN.Abp.MessageService.Domain.Tests/LINGYUN/Abp/MessageService/AbpMessageServiceDomainTestModule.cs new file mode 100644 index 000000000..b2b7ef786 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.MessageService.Domain.Tests/LINGYUN/Abp/MessageService/AbpMessageServiceDomainTestModule.cs @@ -0,0 +1,36 @@ +using LINGYUN.Abp.Notifications; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Volo.Abp.Data; +using Volo.Abp.Modularity; +using Volo.Abp.Threading; + +namespace LINGYUN.Abp.MessageService +{ + [DependsOn( + typeof(AbpMessageServiceDomainModule), + typeof(AbpNotificationsTestsModule) + )] + public class AbpMessageServiceDomainTestModule : AbpModule + { + public override void OnApplicationInitialization(ApplicationInitializationContext context) + { + SeedTestData(context); + } + + private static void SeedTestData(ApplicationInitializationContext context) + { + using (var scope = context.ServiceProvider.CreateScope()) + { + var dataSeeder = scope.ServiceProvider.GetRequiredService(); + AsyncHelper.RunSync(async () => + { + await dataSeeder.SeedAsync(); + await scope.ServiceProvider + .GetRequiredService() + .BuildAsync(); + }); + } + } + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.MessageService.Domain.Tests/LINGYUN/Abp/MessageService/AbpNotificationsTestsDataBuilder.cs b/aspnet-core/tests/LINGYUN.Abp.MessageService.Domain.Tests/LINGYUN/Abp/MessageService/AbpNotificationsTestsDataBuilder.cs new file mode 100644 index 000000000..72afa4cf8 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.MessageService.Domain.Tests/LINGYUN/Abp/MessageService/AbpNotificationsTestsDataBuilder.cs @@ -0,0 +1,75 @@ +using LINGYUN.Abp.MessageService.Notifications; +using LINGYUN.Abp.Notifications; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; + +namespace LINGYUN.Abp.MessageService +{ + public class AbpNotificationsTestDataBuilder : ITransientDependency + { + private readonly INotificationStore _notificationStore; + private readonly IUserNotificationRepository _userNotificationRepository; + public AbpNotificationsTestDataBuilder( + INotificationStore notificationStore, + IUserNotificationRepository userNotificationRepository) + { + _notificationStore = notificationStore; + _userNotificationRepository = userNotificationRepository; + } + + public async Task BuildAsync() + { + await AddNotificationsAsync(); + } + + private async Task AddUserNotificationsAsync(NotificationInfo notificationInfo, IEnumerable userIds) + { + await _notificationStore.InsertUserNotificationsAsync(notificationInfo, userIds); + } + + private async Task AddNotificationsAsync() + { + var notification1 = new NotificationInfo + { + Name = NotificationsTestsNames.Test1, + Severity = NotificationSeverity.Success, + CreationTime = DateTime.Now, + Lifetime = NotificationLifetime.OnlyOne, + Type = NotificationType.Application + }; + + var notification2 = new NotificationInfo + { + Name = NotificationsTestsNames.Test2, + Severity = NotificationSeverity.Success, + CreationTime = DateTime.Now, + Lifetime = NotificationLifetime.Persistent, + Type = NotificationType.Application + }; + + var notification3 = new NotificationInfo + { + Name = NotificationsTestsNames.Test3, + Severity = NotificationSeverity.Success, + CreationTime = DateTime.Now, + Lifetime = NotificationLifetime.OnlyOne, + Type = NotificationType.User + }; + + await _notificationStore.InsertNotificationAsync(notification1); + await _notificationStore.InsertNotificationAsync(notification2); + await _notificationStore.InsertNotificationAsync(notification3); + + NotificationsTestConsts.NotificationId1 = notification1.GetId(); + NotificationsTestConsts.NotificationId2 = notification2.GetId(); + NotificationsTestConsts.NotificationId3 = notification3.GetId(); + + await AddUserNotificationsAsync(notification2, new Guid[] { NotificationsTestConsts.User1Id, NotificationsTestConsts.User2Id }); + await AddUserNotificationsAsync(notification3, new Guid[] { NotificationsTestConsts.User1Id }); + + await _notificationStore.ChangeUserNotificationReadStateAsync(null, NotificationsTestConsts.User1Id, NotificationsTestConsts.NotificationId3, NotificationReadState.Read); + } + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests.csproj b/aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests.csproj new file mode 100644 index 000000000..4bb28eab1 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests.csproj @@ -0,0 +1,24 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + + + + + + + + + diff --git a/aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreTestBase.cs b/aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreTestBase.cs new file mode 100644 index 000000000..8ca6e6b72 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreTestBase.cs @@ -0,0 +1,8 @@ +using LINGYUN.Abp.Tests; + +namespace LINGYUN.Abp.MessageService.EntityFrameworkCore +{ + public abstract class AbpMessageServiceEntityFrameworkCoreTestBase : AbpTestsBase + { + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreTestModule.cs b/aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreTestModule.cs new file mode 100644 index 000000000..d31349d63 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreTestModule.cs @@ -0,0 +1,15 @@ +using LINGYUN.Abp.EntityFrameworkCore.Tests; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.MessageService.EntityFrameworkCore +{ + [DependsOn( + typeof(AbpMessageServiceEntityFrameworkCoreModule), + typeof(AbpMessageServiceDomainTestModule), + typeof(AbpEntityFrameworkCoreTestModule) + )] + public class AbpMessageServiceEntityFrameworkCoreTestModule : AbpModule + { + + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN/Abp/MessageService/Notifications/UserNotificationRepositoryTests.cs b/aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN/Abp/MessageService/Notifications/UserNotificationRepositoryTests.cs new file mode 100644 index 000000000..a23447bf1 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.MessageService.EntityFrameworkCore.Tests/LINGYUN/Abp/MessageService/Notifications/UserNotificationRepositoryTests.cs @@ -0,0 +1,81 @@ +using LINGYUN.Abp.MessageService.EntityFrameworkCore; +using LINGYUN.Abp.Notifications; +using Shouldly; +using System.Threading.Tasks; +using Xunit; + +namespace LINGYUN.Abp.MessageService.Notifications +{ + public class UserNotificationRepositoryTests : AbpMessageServiceEntityFrameworkCoreTestBase + { + private readonly IUserNotificationRepository _repository; + public UserNotificationRepositoryTests() + { + _repository = GetRequiredService(); + } + + [Fact] + public async Task AnyAsync_Test() + { + (await _repository.AnyAsync(NotificationsTestConsts.User1Id, NotificationsTestConsts.NotificationId1)).ShouldBeFalse(); + (await _repository.AnyAsync(NotificationsTestConsts.User1Id, NotificationsTestConsts.NotificationId3)).ShouldBeTrue(); + } + + [Fact] + public async Task GetByIdAsync_Test() + { + (await _repository.GetByIdAsync(NotificationsTestConsts.User1Id, NotificationsTestConsts.NotificationId2)).ShouldNotBeNull(); + (await _repository.GetByIdAsync(NotificationsTestConsts.User1Id, NotificationsTestConsts.NotificationId1)).ShouldBeNull(); + } + + [Fact] + public async Task GetNotificationsAsync_Test() + { + (await _repository.GetNotificationsAsync( + NotificationsTestConsts.User1Id, + NotificationReadState.Read)) + .Count + .ShouldBe(1); + (await _repository.GetNotificationsAsync( + NotificationsTestConsts.User1Id, + NotificationReadState.UnRead)) + .Count + .ShouldBe(1); + (await _repository.GetNotificationsAsync( + NotificationsTestConsts.User1Id)) + .Count + .ShouldBe(2); + (await _repository.GetNotificationsAsync( + NotificationsTestConsts.User2Id, + NotificationReadState.UnRead)) + .Count + .ShouldBe(1); + } + + [Fact] + public async Task GetCountAsync_Test() + { + (await _repository.GetCountAsync( + NotificationsTestConsts.User1Id, + readState: NotificationReadState.Read)) + .ShouldBe(1); + (await _repository.GetCountAsync( + NotificationsTestConsts.User1Id)) + .ShouldBe(2); + } + + [Fact] + public async Task GetListAsync_Test() + { + (await _repository.GetListAsync( + NotificationsTestConsts.User1Id, + readState: NotificationReadState.Read)) + .Count + .ShouldBe(1); + (await _repository.GetListAsync( + NotificationsTestConsts.User1Id)) + .Count + .ShouldBe(2); + } + } +} diff --git a/aspnet-core/tests/LINGYUN.Abp.Notifications.Tests/LINGYUN/Abp/Notifications/AbpNotificationsTestsModule.cs b/aspnet-core/tests/LINGYUN.Abp.Notifications.Tests/LINGYUN/Abp/Notifications/AbpNotificationsTestsModule.cs index 74eec8126..4e8bab37b 100644 --- a/aspnet-core/tests/LINGYUN.Abp.Notifications.Tests/LINGYUN/Abp/Notifications/AbpNotificationsTestsModule.cs +++ b/aspnet-core/tests/LINGYUN.Abp.Notifications.Tests/LINGYUN/Abp/Notifications/AbpNotificationsTestsModule.cs @@ -8,6 +8,5 @@ namespace LINGYUN.Abp.Notifications typeof(AbpTestsBaseModule))] public class AbpNotificationsTestsModule : AbpModule { - } } diff --git a/aspnet-core/tests/LINGYUN.Abp.Notifications.Tests/LINGYUN/Abp/Notifications/NotificationsTestConsts.cs b/aspnet-core/tests/LINGYUN.Abp.Notifications.Tests/LINGYUN/Abp/Notifications/NotificationsTestConsts.cs new file mode 100644 index 000000000..beb71a255 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.Notifications.Tests/LINGYUN/Abp/Notifications/NotificationsTestConsts.cs @@ -0,0 +1,15 @@ +using System; + +namespace LINGYUN.Abp.Notifications +{ + public static class NotificationsTestConsts + { + public static Guid User1Id { get; } = Guid.NewGuid(); + + public static Guid User2Id { get; } = Guid.NewGuid(); + + public static long NotificationId1 { get; set; } + public static long NotificationId2 { get; set; } + public static long NotificationId3 { get; set; } + } +}