From d326b0b105d66baf642dae45b1b29daf71b8616f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 25 Jan 2018 10:16:13 +0300 Subject: [PATCH] Delete GetList and Count methods from the repository. --- .../Areas/Blog/Controllers/PostsController.cs | 6 +- .../IdentityServerTestController.cs | 2 +- src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll | Bin 15360 -> 13824 bytes .../Abp/Domain/Repositories/IRepository.cs | 32 +-------- .../Abp/Identity/IdentityRoleAppService.cs | 6 +- .../Abp/Identity/IIdentityRoleRepository.cs | 4 +- .../Abp/Identity/IIdentityUserRepository.cs | 14 ++-- ...ity.EntityFrameworkCore.csproj.DotSettings | 2 + .../Identity/EfCoreIdentityRoleRepository.cs | 11 ++- .../Identity/EfCoreIdentityUserRepository.cs | 4 +- ...p.IdentityServer.Domain.csproj.DotSettings | 2 + .../ApiResources/IApiResourceRepository.cs | 4 +- ...ver.EntityFrameworkCore.csproj.DotSettings | 2 + .../IdentityServer/ApiResourceRepository.cs | 8 +++ .../AspNetCore/Mvc/PersonAppService_Tests.cs | 15 ++-- .../DataFiltering/MultiTenant_Filter_Tests.cs | 66 ++++++++++-------- .../DataFiltering/SoftDelete_Filter_Tests.cs | 60 +++++++++------- .../Repositories/Basic_Repository_Tests.cs | 38 ++++++---- .../PersonAppServiceClientProxy_Tests.cs | 16 ++--- .../Identity/IdentityRoleAppService_Tests.cs | 1 - .../Identity/IdentityUserAppService_Tests.cs | 11 ++- .../MemoryDb_SoftDelete_DataFilter_Tests.cs | 10 +-- .../DataFilters/MultiTenant_Filter_Tests.cs | 19 +++-- .../MemoryDb_Basic_Repository_Tests.cs | 2 +- 24 files changed, 177 insertions(+), 158 deletions(-) create mode 100644 src/Volo.Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.csproj.DotSettings create mode 100644 src/Volo.Abp.IdentityServer.Domain/Volo.Abp.IdentityServer.Domain.csproj.DotSettings create mode 100644 src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo.Abp.IdentityServer.EntityFrameworkCore.csproj.DotSettings diff --git a/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs b/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs index ec761ebfe4..c38b7a9c2c 100644 --- a/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs +++ b/src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs @@ -1,5 +1,5 @@ using System; -using System.Threading.Tasks; +using System.Linq; using AbpDesk.Blogging; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc; @@ -17,9 +17,9 @@ namespace Areas.Blog.Controllers _blogPostRepository = blogPostRepository; } - public async Task Index() + public ActionResult Index() { - var posts = await _blogPostRepository.GetListAsync(HttpContext.RequestAborted); + var posts = _blogPostRepository.ToList(); //TODO: async..? return View(posts); } } diff --git a/src/AbpDesk/AbpDesk.Web.Mvc/Controllers/IdentityServerTestController.cs b/src/AbpDesk/AbpDesk.Web.Mvc/Controllers/IdentityServerTestController.cs index 365efc29ee..fdd402d4a4 100644 --- a/src/AbpDesk/AbpDesk.Web.Mvc/Controllers/IdentityServerTestController.cs +++ b/src/AbpDesk/AbpDesk.Web.Mvc/Controllers/IdentityServerTestController.cs @@ -38,7 +38,7 @@ namespace AbpDesk.Web.Mvc.Controllers [Route("create")] public async Task CreateClient(string clientId) { - var apiResource = (await _apiResourceRepository.GetListAsync()).FirstOrDefault(ar => ar.Name == "api1"); + var apiResource = await _apiResourceRepository.FindByNameAsync("api1"); if (apiResource == null) { diff --git a/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll b/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll index e18ffa8870111b6acf25bcd5eff6e366b5f589de..b1659c1e3458fd38570b90275dad352539769fea 100644 GIT binary patch delta 4463 zcmZWt4Rln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..31dfd82682 100644 --- a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs +++ b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Threading; +using System.Threading; using System.Threading.Tasks; using JetBrains.Annotations; using Volo.Abp.DependencyInjection; @@ -22,19 +20,6 @@ namespace Volo.Abp.Domain.Repositories public interface IRepository : IRepository where TEntity : class, IEntity { - /// - /// Get list of all entities without any filtering. - /// - /// List of entities - List GetList(); - - /// - /// Get list of all entities without any filtering. - /// - /// A to observe while waiting for the task to complete. - /// List of entities - Task> GetListAsync(CancellationToken cancellationToken = default); - /// /// Gets an entity with given primary key. /// Throws if can not find an entity with given id. @@ -60,7 +45,7 @@ namespace Volo.Abp.Domain.Repositories /// Primary key of the entity to get /// Entity or null [CanBeNull] - TEntity Find(TPrimaryKey id); + TEntity Find(TPrimaryKey id); //TODO: Rename to FirstOrDefault..? /// /// Gets an entity with given primary key or null if not found. @@ -133,18 +118,5 @@ namespace Volo.Abp.Domain.Repositories /// A to observe while waiting for the task to complete. /// Primary key of the entity Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default); //TODO: Return true if deleted - - /// - /// Get list of all entities without any filtering. - /// - /// List of entities - long GetCount(); - - /// - /// Get list of all entities without any filtering. - /// - /// A to observe while waiting for the task to complete. - /// List of entities - Task GetCountAsync(CancellationToken cancellationToken = default); } } diff --git a/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs b/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs index 08b2ff4faa..f6bee59fa8 100644 --- a/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs +++ b/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs @@ -26,10 +26,10 @@ namespace Volo.Abp.Identity ); } - public async Task> GetListAsync(GetIdentityRolesInput input) + public async Task> GetListAsync(GetIdentityRolesInput input) //TODO: Remove input { - var count = (int)await _roleRepository.GetCountAsync(); - var list = await _roleRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter); + var count = (int) await _roleRepository.GetCountAsync(); + var list = await _roleRepository.GetListAsync(); return new PagedResultDto( count, diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs index 97fb33377b..87cce9658a 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs @@ -10,6 +10,8 @@ namespace Volo.Abp.Identity { Task FindByNormalizedNameAsync(string normalizedRoleName, CancellationToken cancellationToken); - Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter); + Task> GetListAsync(string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0); + + Task GetCountAsync(CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs index cc376acdc8..d764d69d48 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs +++ b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs @@ -10,23 +10,25 @@ namespace Volo.Abp.Identity { public interface IIdentityUserRepository : IRepository { - Task FindByNormalizedUserNameAsync([NotNull] string normalizedUserName, CancellationToken cancellationToken); + Task FindByNormalizedUserNameAsync([NotNull] string normalizedUserName, CancellationToken cancellationToken = default); Task> GetRoleNamesAsync(Guid userId); - Task FindByLoginAsync([NotNull] string loginProvider, [NotNull] string providerKey, CancellationToken cancellationToken); + Task FindByLoginAsync([NotNull] string loginProvider, [NotNull] string providerKey, CancellationToken cancellationToken = default); - Task FindByNormalizedEmailAsync([NotNull] string normalizedEmail, CancellationToken cancellationToken); + Task FindByNormalizedEmailAsync([NotNull] string normalizedEmail, CancellationToken cancellationToken = default); //TODO: Why not return List instead of IList - Task> GetListByClaimAsync(Claim claim, CancellationToken cancellationToken); + Task> GetListByClaimAsync(Claim claim, CancellationToken cancellationToken = default); //TODO: Why not return List instead of IList - Task> GetListByNormalizedRoleNameAsync(string normalizedRoleName, CancellationToken cancellationToken); + Task> GetListByNormalizedRoleNameAsync(string normalizedRoleName, CancellationToken cancellationToken = default); //TODO: DTO can be used instead of parameters - Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter); + Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter, CancellationToken cancellationToken = default); Task> GetRolesAsync(Guid userId); + + Task GetCountAsync(CancellationToken cancellationToken = default); } } diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.csproj.DotSettings b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.csproj.DotSettings new file mode 100644 index 0000000000..58ad6c8854 --- /dev/null +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.csproj.DotSettings @@ -0,0 +1,2 @@ + + CSharp71 \ No newline at end of file diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs index 2a6c6db2bb..8788cdf3dc 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs @@ -23,13 +23,12 @@ namespace Volo.Abp.Identity return DbSet.FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, cancellationToken); } - public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter) + public async Task> GetListAsync(string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0) { - return await this.WhereIf( - !filter.IsNullOrWhiteSpace(), - r => r.Name.Contains(filter) - ).OrderBy(sorting ?? nameof(IdentityRole.Name)) - .PageBy(skipCount, maxResultCount).ToListAsync(); + return await this + .OrderBy(sorting ?? nameof(IdentityRole.Name)) + .PageBy(skipCount, maxResultCount) + .ToListAsync(); } } } \ No newline at end of file diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs index 3b33b65390..834b663072 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs +++ b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs @@ -81,7 +81,7 @@ namespace Volo.Abp.Identity return await query.ToListAsync(cancellationToken); } - public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter) + public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter, CancellationToken cancellationToken = default) { return await this.WhereIf( !filter.IsNullOrWhiteSpace(), @@ -90,7 +90,7 @@ namespace Volo.Abp.Identity u.Email.Contains(filter) ) .OrderBy(sorting ?? nameof(IdentityUser.UserName)) - .PageBy(skipCount, maxResultCount).ToListAsync(); + .PageBy(skipCount, maxResultCount).ToListAsync(cancellationToken); } public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount) diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo.Abp.IdentityServer.Domain.csproj.DotSettings b/src/Volo.Abp.IdentityServer.Domain/Volo.Abp.IdentityServer.Domain.csproj.DotSettings new file mode 100644 index 0000000000..58ad6c8854 --- /dev/null +++ b/src/Volo.Abp.IdentityServer.Domain/Volo.Abp.IdentityServer.Domain.csproj.DotSettings @@ -0,0 +1,2 @@ + + CSharp71 \ No newline at end of file diff --git a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs index 1ae0e26295..1bc5d4793c 100644 --- a/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs +++ b/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs @@ -1,10 +1,12 @@ using System; +using System.Threading; +using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; namespace Volo.Abp.IdentityServer.ApiResources { public interface IApiResourceRepository : IRepository { - + Task FindByNameAsync(string name, CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo.Abp.IdentityServer.EntityFrameworkCore.csproj.DotSettings b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo.Abp.IdentityServer.EntityFrameworkCore.csproj.DotSettings new file mode 100644 index 0000000000..58ad6c8854 --- /dev/null +++ b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo.Abp.IdentityServer.EntityFrameworkCore.csproj.DotSettings @@ -0,0 +1,2 @@ + + CSharp71 \ No newline at end of file diff --git a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs index 359930e2e4..49e0715fb2 100644 --- a/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs +++ b/src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs @@ -1,4 +1,7 @@ using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.IdentityServer.ApiResources; @@ -12,5 +15,10 @@ namespace Volo.Abp.IdentityServer { } + + public async Task FindByNameAsync(string name, CancellationToken cancellationToken = default) + { + return await this.FirstOrDefaultAsync(ar => ar.Name == name, cancellationToken); + } } } \ No newline at end of file diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs index 7c21ad6ee5..cdf3b09bfa 100644 --- a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs @@ -3,7 +3,6 @@ using Shouldly; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Application.Dtos; -using Volo.Abp.TestApp.Application; using Volo.Abp.TestApp.Domain; using Xunit; using Volo.Abp.Domain.Repositories; @@ -42,7 +41,7 @@ namespace Volo.Abp.AspNetCore.Mvc [Fact] public async Task Get_Test() { - var firstPerson = _personRepository.GetList().First(); + var firstPerson = _personRepository.First(); var result = await GetResponseAsObjectAsync($"/api/app/people/{firstPerson.Id}"); result.Name.ShouldBe(firstPerson.Name); @@ -51,7 +50,7 @@ namespace Volo.Abp.AspNetCore.Mvc [Fact] public async Task Delete_Test() { - var firstPerson = _personRepository.GetList().First(); + var firstPerson = _personRepository.First(); await Client.DeleteAsync($"/api/app/people/{firstPerson.Id}"); @@ -89,7 +88,7 @@ namespace Volo.Abp.AspNetCore.Mvc { //Arrange - var firstPerson = _personRepository.GetList().First(); + var firstPerson = _personRepository.First(); var firstPersonAge = firstPerson.Age; //Persist to a variable since we are using in-memory database which shares same entity. var updateDto = _objectMapper.Map(firstPerson); updateDto.Age = updateDto.Age + 1; @@ -123,7 +122,7 @@ namespace Volo.Abp.AspNetCore.Mvc { //Arrange - var personToAddNewPhone = _personRepository.GetList().First(); + var personToAddNewPhone = _personRepository.First(); var phoneNumberToAdd = RandomHelper.GetRandom(1000000, 9000000).ToString(); //Act @@ -152,7 +151,7 @@ namespace Volo.Abp.AspNetCore.Mvc [Fact] public async Task GetPhones_Test() { - var douglas = _personRepository.GetList().First(p => p.Name == "Douglas"); + var douglas = _personRepository.First(p => p.Name == "Douglas"); var result = await GetResponseAsObjectAsync>($"/api/app/people/{douglas.Id}/phones"); result.Items.Count.ShouldBe(douglas.Phones.Count); @@ -161,12 +160,12 @@ namespace Volo.Abp.AspNetCore.Mvc [Fact] public async Task DeletePhone_Test() { - var douglas = _personRepository.GetList().First(p => p.Name == "Douglas"); + var douglas = _personRepository.First(p => p.Name == "Douglas"); var firstPhone = douglas.Phones.First(); await Client.DeleteAsync($"/api/app/people/{douglas.Id}/phones/{firstPhone.Id}"); - douglas = _personRepository.GetList().First(p => p.Name == "Douglas"); + douglas = _personRepository.First(p => p.Name == "Douglas"); douglas.Phones.Any(p => p.Id == firstPhone.Id).ShouldBeFalse(); } } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs index 6fe033ebce..e236362bae 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs @@ -14,15 +14,15 @@ using Xunit; namespace Volo.Abp.EntityFrameworkCore.DataFiltering { - public class MultiTenant_Filter_Tests : EntityFrameworkCoreTestBase + public class MultiTenant_Filter_Tests : EntityFrameworkCoreTestBase //TODO: This class is same of Volo.Abp.MemoryDb.DataFilters.MemoryDb_MultiTenant_Filter_Tests. Can we share source code? { private ICurrentTenant _fakeCurrentTenant; - private readonly IRepository _personRepository; + private readonly IQueryableRepository _personRepository; private readonly IDataFilter _multiTenantFilter; public MultiTenant_Filter_Tests() { - _personRepository = GetRequiredService>(); + _personRepository = GetRequiredService>(); _multiTenantFilter = GetRequiredService>(); } @@ -33,48 +33,54 @@ namespace Volo.Abp.EntityFrameworkCore.DataFiltering } [Fact] - public async Task Should_Get_Person_For_Current_Tenant() + public void Should_Get_Person_For_Current_Tenant() { - //TenantId = null + WithUnitOfWork(() => + { + //TenantId = null - _fakeCurrentTenant.Id.Returns((Guid?)null); + _fakeCurrentTenant.Id.Returns((Guid?)null); - var people = await _personRepository.GetListAsync(); - people.Count.ShouldBe(1); - people.Any(p => p.Name == "Douglas").ShouldBeTrue(); + var people = _personRepository.ToList(); + people.Count.ShouldBe(1); + people.Any(p => p.Name == "Douglas").ShouldBeTrue(); - //TenantId = TestDataBuilder.TenantId1 + //TenantId = TestDataBuilder.TenantId1 - _fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId1); + _fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId1); - people = await _personRepository.GetListAsync(); - people.Count.ShouldBe(2); - people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person1").ShouldBeTrue(); - people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person2").ShouldBeTrue(); + people = _personRepository.ToList(); + people.Count.ShouldBe(2); + people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person1").ShouldBeTrue(); + people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person2").ShouldBeTrue(); - //TenantId = TestDataBuilder.TenantId2 + //TenantId = TestDataBuilder.TenantId2 - _fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId2); + _fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId2); - people = await _personRepository.GetListAsync(); - people.Count.ShouldBe(0); + people = _personRepository.ToList(); + people.Count.ShouldBe(0); + }); } [Fact] - public async Task Should_Get_All_People_When_MultiTenant_Filter_Is_Disabled() + public void Should_Get_All_People_When_MultiTenant_Filter_Is_Disabled() { - List people; - - using (_multiTenantFilter.Disable()) + WithUnitOfWork(() => { - //Filter disabled manually - people = await _personRepository.GetListAsync(); - people.Count.ShouldBe(3); - } + List people; + + using (_multiTenantFilter.Disable()) + { + //Filter disabled manually + people = _personRepository.ToList(); + people.Count.ShouldBe(3); + } - //Filter re-enabled automatically - people = await _personRepository.GetListAsync(); - people.Count.ShouldBe(1); + //Filter re-enabled automatically + people = _personRepository.ToList(); + people.Count.ShouldBe(1); + }); } } } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs index fd087a4268..f845b2ca5f 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs @@ -10,56 +10,62 @@ namespace Volo.Abp.EntityFrameworkCore.DataFiltering { public class SoftDelete_Filter_Tests : EntityFrameworkCoreTestBase { - private readonly IRepository _personRepository; + private readonly IQueryableRepository _personRepository; private readonly IDataFilter _dataFilter; public SoftDelete_Filter_Tests() { - _personRepository = GetRequiredService>(); + _personRepository = GetRequiredService>(); _dataFilter = GetRequiredService(); } [Fact] public void Should_Not_Get_Deleted_Entities_By_Default() { - var people = _personRepository.GetList(); - people.Count.ShouldBe(1); - people.Any(p => p.Name == "Douglas").ShouldBeTrue(); + WithUnitOfWork(() => + { + var people = _personRepository.ToList(); + people.Count.ShouldBe(1); + people.Any(p => p.Name == "Douglas").ShouldBeTrue(); + }); } [Fact] public void Should_Get_Deleted_Entities_When_Filter_Is_Disabled() { - //Soft delete is enabled by default - var people = _personRepository.GetList(); - people.Any(p => !p.IsDeleted).ShouldBeTrue(); - people.Any(p => p.IsDeleted).ShouldBeFalse(); - - using (_dataFilter.Disable()) + WithUnitOfWork(() => { - //Soft delete is disabled - people = _personRepository.GetList(); + //Soft delete is enabled by default + var people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); - people.Any(p => p.IsDeleted).ShouldBeTrue(); + people.Any(p => p.IsDeleted).ShouldBeFalse(); - using (_dataFilter.Enable()) + using (_dataFilter.Disable()) { - //Soft delete is enabled again - people = _personRepository.GetList(); + //Soft delete is disabled + people = _personRepository.ToList(); + people.Any(p => !p.IsDeleted).ShouldBeTrue(); + people.Any(p => p.IsDeleted).ShouldBeTrue(); + + using (_dataFilter.Enable()) + { + //Soft delete is enabled again + people = _personRepository.ToList(); + people.Any(p => !p.IsDeleted).ShouldBeTrue(); + people.Any(p => p.IsDeleted).ShouldBeFalse(); + } + + //Soft delete is disabled (restored previous state) + people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); - people.Any(p => p.IsDeleted).ShouldBeFalse(); + people.Any(p => p.IsDeleted).ShouldBeTrue(); } - //Soft delete is disabled (restored previous state) - people = _personRepository.GetList(); + //Soft delete is enabled (restored previous state) + people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); - people.Any(p => p.IsDeleted).ShouldBeTrue(); - } - - //Soft delete is enabled (restored previous state) - people = _personRepository.GetList(); - people.Any(p => !p.IsDeleted).ShouldBeTrue(); - people.Any(p => p.IsDeleted).ShouldBeFalse(); + people.Any(p => p.IsDeleted).ShouldBeFalse(); + }); } } } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs index 55f35f94da..480a698cb2 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs @@ -12,44 +12,56 @@ namespace Volo.Abp.EntityFrameworkCore.Repositories { public class Basic_Repository_Tests : EntityFrameworkCoreTestBase { - private readonly IRepository _personRepository; - private readonly IRepository _bookRepository; - private readonly IRepository _phoneInSecondDbContextRepository; + private readonly IQueryableRepository _personRepository; + private readonly IQueryableRepository _bookRepository; + private readonly IQueryableRepository _phoneInSecondDbContextRepository; public Basic_Repository_Tests() { - _personRepository = ServiceProvider.GetRequiredService>(); - _bookRepository = ServiceProvider.GetRequiredService>(); - _phoneInSecondDbContextRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); + _bookRepository = ServiceProvider.GetRequiredService>(); + _phoneInSecondDbContextRepository = ServiceProvider.GetRequiredService>(); } [Fact] public void GetPersonList() { - _personRepository.GetList().Any().ShouldBeTrue(); + WithUnitOfWork(() => + { + _personRepository.Any().ShouldBeTrue(); + }); } [Fact] public void GetBookList() { - _bookRepository.GetList().Any().ShouldBeTrue(); + WithUnitOfWork(() => + { + _bookRepository.Any().ShouldBeTrue(); + }); } [Fact] public void GetPhoneInSecondDbContextList() { - _phoneInSecondDbContextRepository.GetList().Any().ShouldBeTrue(); + WithUnitOfWork(() => + { + _phoneInSecondDbContextRepository.Any().ShouldBeTrue(); + }); } [Fact] public async Task InsertAsync() { - var personId = Guid.NewGuid(); + await WithUnitOfWorkAsync(async () => + { + var personId = Guid.NewGuid(); - await _personRepository.InsertAsync(new Person(personId, "Adam", 42)); + await _personRepository.InsertAsync(new Person(personId, "Adam", 42)); - var person = await _personRepository.FindAsync(personId); - person.ShouldNotBeNull(); + var person = await _personRepository.FindAsync(personId); + person.ShouldNotBeNull(); + }); } } } diff --git a/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs index 71fa487415..858b2e007a 100644 --- a/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs +++ b/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs @@ -15,18 +15,18 @@ namespace Volo.Abp.Http.DynamicProxying public class PersonAppServiceClientProxy_Tests : AbpHttpTestBase { private readonly IPeopleAppService _peopleAppService; - private readonly IRepository _personRepository; + private readonly IQueryableRepository _personRepository; public PersonAppServiceClientProxy_Tests() { _peopleAppService = ServiceProvider.GetRequiredService(); - _personRepository = ServiceProvider.GetRequiredService>(); + _personRepository = ServiceProvider.GetRequiredService>(); } [Fact] public async Task Get() { - var firstPerson = _personRepository.GetList().First(); + var firstPerson = _personRepository.First(); var person = await _peopleAppService.GetAsync(firstPerson.Id); person.ShouldNotBeNull(); @@ -45,11 +45,11 @@ namespace Volo.Abp.Http.DynamicProxying [Fact] public async Task Delete() { - var firstPerson = _personRepository.GetList().First(); + var firstPerson = _personRepository.First(); await _peopleAppService.DeleteAsync(firstPerson.Id); - firstPerson = _personRepository.GetList().FirstOrDefault(p => p.Id == firstPerson.Id); + firstPerson = _personRepository.FirstOrDefault(p => p.Id == firstPerson.Id); firstPerson.ShouldBeNull(); } @@ -69,7 +69,7 @@ namespace Volo.Abp.Http.DynamicProxying person.Id.ShouldNotBe(Guid.Empty); person.Name.ShouldBe(uniquePersonName); - var personInDb = _personRepository.GetList().FirstOrDefault(p => p.Name == uniquePersonName); + var personInDb = _personRepository.FirstOrDefault(p => p.Name == uniquePersonName); personInDb.ShouldNotBeNull(); personInDb.Id.ShouldBe(person.Id); } @@ -77,7 +77,7 @@ namespace Volo.Abp.Http.DynamicProxying [Fact] public async Task Update() { - var firstPerson = _personRepository.GetList().First(); + var firstPerson = _personRepository.First(); var uniquePersonName = Guid.NewGuid().ToString(); var person = await _peopleAppService.UpdateAsync( @@ -95,7 +95,7 @@ namespace Volo.Abp.Http.DynamicProxying person.Name.ShouldBe(uniquePersonName); person.Age.ShouldBe(firstPerson.Age); - var personInDb = _personRepository.GetList().FirstOrDefault(p => p.Id == firstPerson.Id); + var personInDb = _personRepository.FirstOrDefault(p => p.Id == firstPerson.Id); personInDb.ShouldNotBeNull(); personInDb.Id.ShouldBe(person.Id); personInDb.Name.ShouldBe(person.Name); diff --git a/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs index 1eedd46355..b73bb755fa 100644 --- a/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs +++ b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Xunit; using Shouldly; -using Volo.Abp.Application.Dtos; namespace Volo.Abp.Identity { diff --git a/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs index 7cb07c46b0..5c4f2f4a75 100644 --- a/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs +++ b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Shouldly; using Volo.Abp.Application.Dtos; +using Volo.Abp.Domain.Entities; using Xunit; namespace Volo.Abp.Identity @@ -184,12 +185,18 @@ namespace Volo.Abp.Identity private async Task GetUserAsync(string userName) { - return (await _userRepository.GetListAsync()).First(u => u.UserName == userName); + var user = await FindUserAsync(userName); + if (user == null) + { + throw new EntityNotFoundException(); + } + + return user; } private async Task FindUserAsync(string userName) { - return (await _userRepository.GetListAsync()).FirstOrDefault(u => u.UserName == userName); + return await _userRepository.FindByNormalizedUserNameAsync(userName.ToUpperInvariant()); } private static string CreateRandomEmail() diff --git a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs index b3dc6cd4ed..2bf2b7f612 100644 --- a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs +++ b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs @@ -24,33 +24,33 @@ namespace Volo.Abp.MemoryDb.DataFilters public void Should_Get_Deleted_Entities_When_Filter_Is_Disabled() { //Soft delete is enabled by default - var people = _personRepository.GetList(); + var people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeFalse(); using (_dataFilter.Disable()) { //Soft delete is disabled - people = _personRepository.GetList(); + people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeTrue(); using (_dataFilter.Enable()) { //Soft delete is enabled again - people = _personRepository.GetList(); + people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeFalse(); } //Soft delete is disabled (restored previous state) - people = _personRepository.GetList(); + people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeTrue(); } //Soft delete is enabled (restored previous state) - people = _personRepository.GetList(); + people = _personRepository.ToList(); people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeFalse(); } diff --git a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs index e3c5c5fc24..9df33e4899 100644 --- a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs +++ b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using NSubstitute; using Shouldly; @@ -17,12 +16,12 @@ namespace Volo.Abp.MemoryDb.DataFilters public class MemoryDb_MultiTenant_Filter_Tests : MemoryDbTestBase { private ICurrentTenant _fakeCurrentTenant; - private readonly IRepository _personRepository; + private readonly IQueryableRepository _personRepository; private readonly IDataFilter _multiTenantFilter; public MemoryDb_MultiTenant_Filter_Tests() { - _personRepository = GetRequiredService>(); + _personRepository = GetRequiredService>(); _multiTenantFilter = GetRequiredService>(); } @@ -33,13 +32,13 @@ namespace Volo.Abp.MemoryDb.DataFilters } [Fact] - public async Task Should_Get_Person_For_Current_Tenant() + public void Should_Get_Person_For_Current_Tenant() { //TenantId = null _fakeCurrentTenant.Id.Returns((Guid?)null); - var people = await _personRepository.GetListAsync(); + var people = _personRepository.ToList(); people.Count.ShouldBe(1); people.Any(p => p.Name == "Douglas").ShouldBeTrue(); @@ -47,7 +46,7 @@ namespace Volo.Abp.MemoryDb.DataFilters _fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId1); - people = await _personRepository.GetListAsync(); + people = _personRepository.ToList(); people.Count.ShouldBe(2); people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person1").ShouldBeTrue(); people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person2").ShouldBeTrue(); @@ -56,24 +55,24 @@ namespace Volo.Abp.MemoryDb.DataFilters _fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId2); - people = await _personRepository.GetListAsync(); + people = _personRepository.ToList(); people.Count.ShouldBe(0); } [Fact] - public async Task Should_Get_All_People_When_MultiTenant_Filter_Is_Disabled() + public void Should_Get_All_People_When_MultiTenant_Filter_Is_Disabled() { List people; using (_multiTenantFilter.Disable()) { //Filter disabled manually - people = await _personRepository.GetListAsync(); + people = _personRepository.ToList(); people.Count.ShouldBe(3); } //Filter re-enabled automatically - people = await _personRepository.GetListAsync(); + people = _personRepository.ToList(); people.Count.ShouldBe(1); } } diff --git a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs index 9053d22363..3efb7d775e 100644 --- a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs +++ b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs @@ -20,7 +20,7 @@ namespace Volo.Abp.MemoryDb.Repositories [Fact] public void GetList() { - var people = _personRepository.GetList(); + var people = _personRepository.ToList(); people.Count.ShouldBeGreaterThan(0); }