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 e18ffa8870..b1659c1e34 100644 Binary files a/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll and b/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll differ diff --git a/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs b/src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs index f2bc729011..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); }