From a6d7ff959499b96e09c9715392531287ad5a73b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=B4=AA=E6=9E=97?= Date: Wed, 9 Sep 2020 21:07:58 +0800 Subject: [PATCH] fixed parentId parameter and tested complete --- .../Identity/IOrganizationUnitRepository.cs | 1 + .../EfCoreOrganizationUnitRepository.cs | 3 +++ .../MongoDB/MongoOrganizationUnitRepository.cs | 3 +++ .../OrganizationUnitRepository_Tests.cs | 18 +++++++++++++++++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs index 561abd893f..0e6272064d 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs @@ -28,6 +28,7 @@ namespace Volo.Abp.Identity ); Task> GetListAsync( + Guid? parentId, string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs index 311bb1a3dc..7dd1901fbc 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs @@ -45,6 +45,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore } public virtual async Task> GetListAsync( + Guid? parentId, string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, @@ -54,6 +55,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore { return await DbSet .IncludeDetails(includeDetails) + .Where(ou=>ou.ParentId==parentId) .WhereIf(!filter.IsNullOrWhiteSpace(), ou => ou.DisplayName.Contains(filter) || ou.Code.Contains(filter)) @@ -172,6 +174,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore CancellationToken cancellationToken = default) { return await DbSet + .Where(ou=>ou.ParentId==parentId) .WhereIf(!filter.IsNullOrWhiteSpace(), ou => ou.DisplayName.Contains(filter) || ou.Code.Contains(filter)) diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs index a31acf13ad..73397636f5 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs @@ -56,6 +56,7 @@ namespace Volo.Abp.Identity.MongoDB } public virtual async Task> GetListAsync( + Guid? parentId, string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, @@ -64,6 +65,7 @@ namespace Volo.Abp.Identity.MongoDB CancellationToken cancellationToken = default) { return await GetMongoQueryable() + .Where(ou=>ou.ParentId==parentId) .WhereIf(!filter.IsNullOrWhiteSpace(), ou => ou.DisplayName.Contains(filter) || ou.Code.Contains(filter)) @@ -165,6 +167,7 @@ namespace Volo.Abp.Identity.MongoDB CancellationToken cancellationToken = default) { return await GetMongoQueryable() + .Where(ou=>ou.ParentId==parentId) .WhereIf>(!filter.IsNullOrWhiteSpace(), ou => ou.DisplayName.Contains(filter) || ou.Code.Contains(filter)) diff --git a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs index bb8300d449..2725441719 100644 --- a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs @@ -59,6 +59,22 @@ namespace Volo.Abp.Identity var ous = await _organizationUnitRepository.GetListAsync(ouIds); ous.Count.ShouldBe(2); ous.ShouldContain(ou => ou.Id == ouIds.First()); + + var ou11 = await _organizationUnitRepository.GetAsync("OU11"); + ou11.ShouldNotBeNull(); + var ou11Children = await _organizationUnitRepository.GetListAsync(ou11.Id, includeDetails: true); + ou11Children.Count.ShouldBe(2); + } + + [Fact] + public async Task GetLongCountAsync() + { + (await _organizationUnitRepository.GetLongCountAsync(_guidGenerator.Create(), filter: "11")).ShouldBe(0); + var countRoot = await _organizationUnitRepository.GetLongCountAsync(null, filter: "1"); + countRoot.ShouldBe(1); + var ou11 = await _organizationUnitRepository.GetAsync("OU11"); + ou11.ShouldNotBeNull(); + (await _organizationUnitRepository.GetLongCountAsync(ou11.Id, "2")).ShouldBe(1); } [Fact] @@ -192,7 +208,7 @@ namespace Volo.Abp.Identity { OrganizationUnit ou1 = await _organizationUnitRepository.GetAsync("OU111", true); OrganizationUnit ou2 = await _organizationUnitRepository.GetAsync("OU112", true); - var users = await _identityUserRepository.GetUsersInOrganizationsListAsync(new List {ou1.Id, ou2.Id}); + var users = await _identityUserRepository.GetUsersInOrganizationsListAsync(new List { ou1.Id, ou2.Id }); users.Count.ShouldBeGreaterThan(0); }