Browse Source

Delete GetList and Count methods from the repository.

pull/194/head
Halil İbrahim Kalkan 9 years ago
parent
commit
d326b0b105
  1. 6
      src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs
  2. 2
      src/AbpDesk/AbpDesk.Web.Mvc/Controllers/IdentityServerTestController.cs
  3. BIN
      src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll
  4. 32
      src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs
  5. 6
      src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs
  6. 4
      src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs
  7. 14
      src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs
  8. 2
      src/Volo.Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.csproj.DotSettings
  9. 11
      src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs
  10. 4
      src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs
  11. 2
      src/Volo.Abp.IdentityServer.Domain/Volo.Abp.IdentityServer.Domain.csproj.DotSettings
  12. 4
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs
  13. 2
      src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo.Abp.IdentityServer.EntityFrameworkCore.csproj.DotSettings
  14. 8
      src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs
  15. 15
      test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs
  16. 66
      test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs
  17. 60
      test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/SoftDelete_Filter_Tests.cs
  18. 38
      test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Basic_Repository_Tests.cs
  19. 16
      test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs
  20. 1
      test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs
  21. 11
      test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs
  22. 10
      test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MemoryDb_SoftDelete_DataFilter_Tests.cs
  23. 19
      test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs
  24. 2
      test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs

6
src/AbpDesk/AbpDesk.MongoBlog/Areas/Blog/Controllers/PostsController.cs

@ -1,5 +1,5 @@
using System; using System;
using System.Threading.Tasks; using System.Linq;
using AbpDesk.Blogging; using AbpDesk.Blogging;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;
@ -17,9 +17,9 @@ namespace Areas.Blog.Controllers
_blogPostRepository = blogPostRepository; _blogPostRepository = blogPostRepository;
} }
public async Task<ActionResult> Index() public ActionResult Index()
{ {
var posts = await _blogPostRepository.GetListAsync(HttpContext.RequestAborted); var posts = _blogPostRepository.ToList(); //TODO: async..?
return View(posts); return View(posts);
} }
} }

2
src/AbpDesk/AbpDesk.Web.Mvc/Controllers/IdentityServerTestController.cs

@ -38,7 +38,7 @@ namespace AbpDesk.Web.Mvc.Controllers
[Route("create")] [Route("create")]
public async Task<IActionResult> CreateClient(string clientId) public async Task<IActionResult> CreateClient(string clientId)
{ {
var apiResource = (await _apiResourceRepository.GetListAsync()).FirstOrDefault(ar => ar.Name == "api1"); var apiResource = await _apiResourceRepository.FindByNameAsync("api1");
if (apiResource == null) if (apiResource == null)
{ {

BIN
src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll

Binary file not shown.

32
src/Volo.Abp.Ddd/Volo/Abp/Domain/Repositories/IRepository.cs

@ -1,6 +1,4 @@
using System; using System.Threading;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations; using JetBrains.Annotations;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
@ -22,19 +20,6 @@ namespace Volo.Abp.Domain.Repositories
public interface IRepository<TEntity, TPrimaryKey> : IRepository public interface IRepository<TEntity, TPrimaryKey> : IRepository
where TEntity : class, IEntity<TPrimaryKey> where TEntity : class, IEntity<TPrimaryKey>
{ {
/// <summary>
/// Get list of all entities without any filtering.
/// </summary>
/// <returns>List of entities</returns>
List<TEntity> GetList();
/// <summary>
/// Get list of all entities without any filtering.
/// </summary>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>List of entities</returns>
Task<List<TEntity>> GetListAsync(CancellationToken cancellationToken = default);
/// <summary> /// <summary>
/// Gets an entity with given primary key. /// Gets an entity with given primary key.
/// Throws <see cref="EntityNotFoundException"/> if can not find an entity with given id. /// Throws <see cref="EntityNotFoundException"/> if can not find an entity with given id.
@ -60,7 +45,7 @@ namespace Volo.Abp.Domain.Repositories
/// <param name="id">Primary key of the entity to get</param> /// <param name="id">Primary key of the entity to get</param>
/// <returns>Entity or null</returns> /// <returns>Entity or null</returns>
[CanBeNull] [CanBeNull]
TEntity Find(TPrimaryKey id); TEntity Find(TPrimaryKey id); //TODO: Rename to FirstOrDefault..?
/// <summary> /// <summary>
/// Gets an entity with given primary key or null if not found. /// Gets an entity with given primary key or null if not found.
@ -133,18 +118,5 @@ namespace Volo.Abp.Domain.Repositories
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param> /// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <param name="id">Primary key of the entity</param> /// <param name="id">Primary key of the entity</param>
Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default); //TODO: Return true if deleted Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default); //TODO: Return true if deleted
/// <summary>
/// Get list of all entities without any filtering.
/// </summary>
/// <returns>List of entities</returns>
long GetCount();
/// <summary>
/// Get list of all entities without any filtering.
/// </summary>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>List of entities</returns>
Task<long> GetCountAsync(CancellationToken cancellationToken = default);
} }
} }

6
src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs

@ -26,10 +26,10 @@ namespace Volo.Abp.Identity
); );
} }
public async Task<PagedResultDto<IdentityRoleDto>> GetListAsync(GetIdentityRolesInput input) public async Task<PagedResultDto<IdentityRoleDto>> GetListAsync(GetIdentityRolesInput input) //TODO: Remove input
{ {
var count = (int)await _roleRepository.GetCountAsync(); var count = (int) await _roleRepository.GetCountAsync();
var list = await _roleRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter); var list = await _roleRepository.GetListAsync();
return new PagedResultDto<IdentityRoleDto>( return new PagedResultDto<IdentityRoleDto>(
count, count,

4
src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs

@ -10,6 +10,8 @@ namespace Volo.Abp.Identity
{ {
Task<IdentityRole> FindByNormalizedNameAsync(string normalizedRoleName, CancellationToken cancellationToken); Task<IdentityRole> FindByNormalizedNameAsync(string normalizedRoleName, CancellationToken cancellationToken);
Task<List<IdentityRole>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter); Task<List<IdentityRole>> GetListAsync(string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0);
Task<long> GetCountAsync(CancellationToken cancellationToken = default);
} }
} }

14
src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs

@ -10,23 +10,25 @@ namespace Volo.Abp.Identity
{ {
public interface IIdentityUserRepository : IRepository<IdentityUser, Guid> public interface IIdentityUserRepository : IRepository<IdentityUser, Guid>
{ {
Task<IdentityUser> FindByNormalizedUserNameAsync([NotNull] string normalizedUserName, CancellationToken cancellationToken); Task<IdentityUser> FindByNormalizedUserNameAsync([NotNull] string normalizedUserName, CancellationToken cancellationToken = default);
Task<List<string>> GetRoleNamesAsync(Guid userId); Task<List<string>> GetRoleNamesAsync(Guid userId);
Task<IdentityUser> FindByLoginAsync([NotNull] string loginProvider, [NotNull] string providerKey, CancellationToken cancellationToken); Task<IdentityUser> FindByLoginAsync([NotNull] string loginProvider, [NotNull] string providerKey, CancellationToken cancellationToken = default);
Task<IdentityUser> FindByNormalizedEmailAsync([NotNull] string normalizedEmail, CancellationToken cancellationToken); Task<IdentityUser> FindByNormalizedEmailAsync([NotNull] string normalizedEmail, CancellationToken cancellationToken = default);
//TODO: Why not return List instead of IList //TODO: Why not return List instead of IList
Task<IList<IdentityUser>> GetListByClaimAsync(Claim claim, CancellationToken cancellationToken); Task<IList<IdentityUser>> GetListByClaimAsync(Claim claim, CancellationToken cancellationToken = default);
//TODO: Why not return List instead of IList //TODO: Why not return List instead of IList
Task<IList<IdentityUser>> GetListByNormalizedRoleNameAsync(string normalizedRoleName, CancellationToken cancellationToken); Task<IList<IdentityUser>> GetListByNormalizedRoleNameAsync(string normalizedRoleName, CancellationToken cancellationToken = default);
//TODO: DTO can be used instead of parameters //TODO: DTO can be used instead of parameters
Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter); Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter, CancellationToken cancellationToken = default);
Task<List<IdentityRole>> GetRolesAsync(Guid userId); Task<List<IdentityRole>> GetRolesAsync(Guid userId);
Task<long> GetCountAsync(CancellationToken cancellationToken = default);
} }
} }

2
src/Volo.Abp.Identity.EntityFrameworkCore/Volo.Abp.Identity.EntityFrameworkCore.csproj.DotSettings

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp71</s:String></wpf:ResourceDictionary>

11
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); return DbSet.FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, cancellationToken);
} }
public async Task<List<IdentityRole>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter) public async Task<List<IdentityRole>> GetListAsync(string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0)
{ {
return await this.WhereIf( return await this
!filter.IsNullOrWhiteSpace(), .OrderBy(sorting ?? nameof(IdentityRole.Name))
r => r.Name.Contains(filter) .PageBy(skipCount, maxResultCount)
).OrderBy(sorting ?? nameof(IdentityRole.Name)) .ToListAsync();
.PageBy(skipCount, maxResultCount).ToListAsync();
} }
} }
} }

4
src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs

@ -81,7 +81,7 @@ namespace Volo.Abp.Identity
return await query.ToListAsync(cancellationToken); return await query.ToListAsync(cancellationToken);
} }
public async Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter) public async Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter, CancellationToken cancellationToken = default)
{ {
return await this.WhereIf( return await this.WhereIf(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
@ -90,7 +90,7 @@ namespace Volo.Abp.Identity
u.Email.Contains(filter) u.Email.Contains(filter)
) )
.OrderBy(sorting ?? nameof(IdentityUser.UserName)) .OrderBy(sorting ?? nameof(IdentityUser.UserName))
.PageBy(skipCount, maxResultCount).ToListAsync(); .PageBy(skipCount, maxResultCount).ToListAsync(cancellationToken);
} }
public async Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount) public async Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount)

2
src/Volo.Abp.IdentityServer.Domain/Volo.Abp.IdentityServer.Domain.csproj.DotSettings

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp71</s:String></wpf:ResourceDictionary>

4
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/IApiResourceRepository.cs

@ -1,10 +1,12 @@
using System; using System;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
namespace Volo.Abp.IdentityServer.ApiResources namespace Volo.Abp.IdentityServer.ApiResources
{ {
public interface IApiResourceRepository : IRepository<ApiResource, Guid> public interface IApiResourceRepository : IRepository<ApiResource, Guid>
{ {
Task<ApiResource> FindByNameAsync(string name, CancellationToken cancellationToken = default);
} }
} }

2
src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo.Abp.IdentityServer.EntityFrameworkCore.csproj.DotSettings

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp71</s:String></wpf:ResourceDictionary>

8
src/Volo.Abp.IdentityServer.EntityFrameworkCore/Volo/Abp/IdentityServer/ApiResourceRepository.cs

@ -1,4 +1,7 @@
using System; using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.IdentityServer.ApiResources; using Volo.Abp.IdentityServer.ApiResources;
@ -12,5 +15,10 @@ namespace Volo.Abp.IdentityServer
{ {
} }
public async Task<ApiResource> FindByNameAsync(string name, CancellationToken cancellationToken = default)
{
return await this.FirstOrDefaultAsync(ar => ar.Name == name, cancellationToken);
}
} }
} }

15
test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs

@ -3,7 +3,6 @@ using Shouldly;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.TestApp.Application;
using Volo.Abp.TestApp.Domain; using Volo.Abp.TestApp.Domain;
using Xunit; using Xunit;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
@ -42,7 +41,7 @@ namespace Volo.Abp.AspNetCore.Mvc
[Fact] [Fact]
public async Task Get_Test() public async Task Get_Test()
{ {
var firstPerson = _personRepository.GetList().First(); var firstPerson = _personRepository.First();
var result = await GetResponseAsObjectAsync<PersonDto>($"/api/app/people/{firstPerson.Id}"); var result = await GetResponseAsObjectAsync<PersonDto>($"/api/app/people/{firstPerson.Id}");
result.Name.ShouldBe(firstPerson.Name); result.Name.ShouldBe(firstPerson.Name);
@ -51,7 +50,7 @@ namespace Volo.Abp.AspNetCore.Mvc
[Fact] [Fact]
public async Task Delete_Test() public async Task Delete_Test()
{ {
var firstPerson = _personRepository.GetList().First(); var firstPerson = _personRepository.First();
await Client.DeleteAsync($"/api/app/people/{firstPerson.Id}"); await Client.DeleteAsync($"/api/app/people/{firstPerson.Id}");
@ -89,7 +88,7 @@ namespace Volo.Abp.AspNetCore.Mvc
{ {
//Arrange //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 firstPersonAge = firstPerson.Age; //Persist to a variable since we are using in-memory database which shares same entity.
var updateDto = _objectMapper.Map<Person, PersonDto>(firstPerson); var updateDto = _objectMapper.Map<Person, PersonDto>(firstPerson);
updateDto.Age = updateDto.Age + 1; updateDto.Age = updateDto.Age + 1;
@ -123,7 +122,7 @@ namespace Volo.Abp.AspNetCore.Mvc
{ {
//Arrange //Arrange
var personToAddNewPhone = _personRepository.GetList().First(); var personToAddNewPhone = _personRepository.First();
var phoneNumberToAdd = RandomHelper.GetRandom(1000000, 9000000).ToString(); var phoneNumberToAdd = RandomHelper.GetRandom(1000000, 9000000).ToString();
//Act //Act
@ -152,7 +151,7 @@ namespace Volo.Abp.AspNetCore.Mvc
[Fact] [Fact]
public async Task GetPhones_Test() 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<ListResultDto<PhoneDto>>($"/api/app/people/{douglas.Id}/phones"); var result = await GetResponseAsObjectAsync<ListResultDto<PhoneDto>>($"/api/app/people/{douglas.Id}/phones");
result.Items.Count.ShouldBe(douglas.Phones.Count); result.Items.Count.ShouldBe(douglas.Phones.Count);
@ -161,12 +160,12 @@ namespace Volo.Abp.AspNetCore.Mvc
[Fact] [Fact]
public async Task DeletePhone_Test() 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(); var firstPhone = douglas.Phones.First();
await Client.DeleteAsync($"/api/app/people/{douglas.Id}/phones/{firstPhone.Id}"); 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(); douglas.Phones.Any(p => p.Id == firstPhone.Id).ShouldBeFalse();
} }
} }

66
test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DataFiltering/MultiTenant_Filter_Tests.cs

@ -14,15 +14,15 @@ using Xunit;
namespace Volo.Abp.EntityFrameworkCore.DataFiltering 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 ICurrentTenant _fakeCurrentTenant;
private readonly IRepository<Person, Guid> _personRepository; private readonly IQueryableRepository<Person, Guid> _personRepository;
private readonly IDataFilter<IMultiTenant> _multiTenantFilter; private readonly IDataFilter<IMultiTenant> _multiTenantFilter;
public MultiTenant_Filter_Tests() public MultiTenant_Filter_Tests()
{ {
_personRepository = GetRequiredService<IRepository<Person, Guid>>(); _personRepository = GetRequiredService<IQueryableRepository<Person, Guid>>();
_multiTenantFilter = GetRequiredService<IDataFilter<IMultiTenant>>(); _multiTenantFilter = GetRequiredService<IDataFilter<IMultiTenant>>();
} }
@ -33,48 +33,54 @@ namespace Volo.Abp.EntityFrameworkCore.DataFiltering
} }
[Fact] [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(); var people = _personRepository.ToList();
people.Count.ShouldBe(1); people.Count.ShouldBe(1);
people.Any(p => p.Name == "Douglas").ShouldBeTrue(); 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 = _personRepository.ToList();
people.Count.ShouldBe(2); people.Count.ShouldBe(2);
people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person1").ShouldBeTrue(); people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person1").ShouldBeTrue();
people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person2").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 = _personRepository.ToList();
people.Count.ShouldBe(0); people.Count.ShouldBe(0);
});
} }
[Fact] [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<Person> people; WithUnitOfWork(() =>
using (_multiTenantFilter.Disable())
{ {
//Filter disabled manually List<Person> people;
people = await _personRepository.GetListAsync();
people.Count.ShouldBe(3); using (_multiTenantFilter.Disable())
} {
//Filter disabled manually
people = _personRepository.ToList();
people.Count.ShouldBe(3);
}
//Filter re-enabled automatically //Filter re-enabled automatically
people = await _personRepository.GetListAsync(); people = _personRepository.ToList();
people.Count.ShouldBe(1); people.Count.ShouldBe(1);
});
} }
} }
} }

60
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 public class SoftDelete_Filter_Tests : EntityFrameworkCoreTestBase
{ {
private readonly IRepository<Person, Guid> _personRepository; private readonly IQueryableRepository<Person, Guid> _personRepository;
private readonly IDataFilter _dataFilter; private readonly IDataFilter _dataFilter;
public SoftDelete_Filter_Tests() public SoftDelete_Filter_Tests()
{ {
_personRepository = GetRequiredService<IRepository<Person, Guid>>(); _personRepository = GetRequiredService<IQueryableRepository<Person, Guid>>();
_dataFilter = GetRequiredService<IDataFilter>(); _dataFilter = GetRequiredService<IDataFilter>();
} }
[Fact] [Fact]
public void Should_Not_Get_Deleted_Entities_By_Default() public void Should_Not_Get_Deleted_Entities_By_Default()
{ {
var people = _personRepository.GetList(); WithUnitOfWork(() =>
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();
});
} }
[Fact] [Fact]
public void Should_Get_Deleted_Entities_When_Filter_Is_Disabled() public void Should_Get_Deleted_Entities_When_Filter_Is_Disabled()
{ {
//Soft delete is enabled by default WithUnitOfWork(() =>
var people = _personRepository.GetList();
people.Any(p => !p.IsDeleted).ShouldBeTrue();
people.Any(p => p.IsDeleted).ShouldBeFalse();
using (_dataFilter.Disable<ISoftDelete>())
{ {
//Soft delete is disabled //Soft delete is enabled by default
people = _personRepository.GetList(); var people = _personRepository.ToList();
people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => !p.IsDeleted).ShouldBeTrue();
people.Any(p => p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeFalse();
using (_dataFilter.Enable<ISoftDelete>()) using (_dataFilter.Disable<ISoftDelete>())
{ {
//Soft delete is enabled again //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<ISoftDelete>())
{
//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).ShouldBeTrue();
people.Any(p => p.IsDeleted).ShouldBeFalse(); people.Any(p => p.IsDeleted).ShouldBeTrue();
} }
//Soft delete is disabled (restored previous state) //Soft delete is enabled (restored previous state)
people = _personRepository.GetList(); people = _personRepository.ToList();
people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => !p.IsDeleted).ShouldBeTrue();
people.Any(p => p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeFalse();
} });
//Soft delete is enabled (restored previous state)
people = _personRepository.GetList();
people.Any(p => !p.IsDeleted).ShouldBeTrue();
people.Any(p => p.IsDeleted).ShouldBeFalse();
} }
} }
} }

38
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 public class Basic_Repository_Tests : EntityFrameworkCoreTestBase
{ {
private readonly IRepository<Person, Guid> _personRepository; private readonly IQueryableRepository<Person, Guid> _personRepository;
private readonly IRepository<BookInSecondDbContext, Guid> _bookRepository; private readonly IQueryableRepository<BookInSecondDbContext, Guid> _bookRepository;
private readonly IRepository<PhoneInSecondDbContext, long> _phoneInSecondDbContextRepository; private readonly IQueryableRepository<PhoneInSecondDbContext, long> _phoneInSecondDbContextRepository;
public Basic_Repository_Tests() public Basic_Repository_Tests()
{ {
_personRepository = ServiceProvider.GetRequiredService<IRepository<Person, Guid>>(); _personRepository = ServiceProvider.GetRequiredService<IQueryableRepository<Person, Guid>>();
_bookRepository = ServiceProvider.GetRequiredService<IRepository<BookInSecondDbContext, Guid>>(); _bookRepository = ServiceProvider.GetRequiredService<IQueryableRepository<BookInSecondDbContext, Guid>>();
_phoneInSecondDbContextRepository = ServiceProvider.GetRequiredService<IRepository<PhoneInSecondDbContext, long>>(); _phoneInSecondDbContextRepository = ServiceProvider.GetRequiredService<IQueryableRepository<PhoneInSecondDbContext, long>>();
} }
[Fact] [Fact]
public void GetPersonList() public void GetPersonList()
{ {
_personRepository.GetList().Any().ShouldBeTrue(); WithUnitOfWork(() =>
{
_personRepository.Any().ShouldBeTrue();
});
} }
[Fact] [Fact]
public void GetBookList() public void GetBookList()
{ {
_bookRepository.GetList().Any().ShouldBeTrue(); WithUnitOfWork(() =>
{
_bookRepository.Any().ShouldBeTrue();
});
} }
[Fact] [Fact]
public void GetPhoneInSecondDbContextList() public void GetPhoneInSecondDbContextList()
{ {
_phoneInSecondDbContextRepository.GetList().Any().ShouldBeTrue(); WithUnitOfWork(() =>
{
_phoneInSecondDbContextRepository.Any().ShouldBeTrue();
});
} }
[Fact] [Fact]
public async Task InsertAsync() 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); var person = await _personRepository.FindAsync(personId);
person.ShouldNotBeNull(); person.ShouldNotBeNull();
});
} }
} }
} }

16
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 public class PersonAppServiceClientProxy_Tests : AbpHttpTestBase
{ {
private readonly IPeopleAppService _peopleAppService; private readonly IPeopleAppService _peopleAppService;
private readonly IRepository<Person, Guid> _personRepository; private readonly IQueryableRepository<Person, Guid> _personRepository;
public PersonAppServiceClientProxy_Tests() public PersonAppServiceClientProxy_Tests()
{ {
_peopleAppService = ServiceProvider.GetRequiredService<IPeopleAppService>(); _peopleAppService = ServiceProvider.GetRequiredService<IPeopleAppService>();
_personRepository = ServiceProvider.GetRequiredService<IRepository<Person, Guid>>(); _personRepository = ServiceProvider.GetRequiredService<IQueryableRepository<Person, Guid>>();
} }
[Fact] [Fact]
public async Task Get() public async Task Get()
{ {
var firstPerson = _personRepository.GetList().First(); var firstPerson = _personRepository.First();
var person = await _peopleAppService.GetAsync(firstPerson.Id); var person = await _peopleAppService.GetAsync(firstPerson.Id);
person.ShouldNotBeNull(); person.ShouldNotBeNull();
@ -45,11 +45,11 @@ namespace Volo.Abp.Http.DynamicProxying
[Fact] [Fact]
public async Task Delete() public async Task Delete()
{ {
var firstPerson = _personRepository.GetList().First(); var firstPerson = _personRepository.First();
await _peopleAppService.DeleteAsync(firstPerson.Id); await _peopleAppService.DeleteAsync(firstPerson.Id);
firstPerson = _personRepository.GetList().FirstOrDefault(p => p.Id == firstPerson.Id); firstPerson = _personRepository.FirstOrDefault(p => p.Id == firstPerson.Id);
firstPerson.ShouldBeNull(); firstPerson.ShouldBeNull();
} }
@ -69,7 +69,7 @@ namespace Volo.Abp.Http.DynamicProxying
person.Id.ShouldNotBe(Guid.Empty); person.Id.ShouldNotBe(Guid.Empty);
person.Name.ShouldBe(uniquePersonName); person.Name.ShouldBe(uniquePersonName);
var personInDb = _personRepository.GetList().FirstOrDefault(p => p.Name == uniquePersonName); var personInDb = _personRepository.FirstOrDefault(p => p.Name == uniquePersonName);
personInDb.ShouldNotBeNull(); personInDb.ShouldNotBeNull();
personInDb.Id.ShouldBe(person.Id); personInDb.Id.ShouldBe(person.Id);
} }
@ -77,7 +77,7 @@ namespace Volo.Abp.Http.DynamicProxying
[Fact] [Fact]
public async Task Update() public async Task Update()
{ {
var firstPerson = _personRepository.GetList().First(); var firstPerson = _personRepository.First();
var uniquePersonName = Guid.NewGuid().ToString(); var uniquePersonName = Guid.NewGuid().ToString();
var person = await _peopleAppService.UpdateAsync( var person = await _peopleAppService.UpdateAsync(
@ -95,7 +95,7 @@ namespace Volo.Abp.Http.DynamicProxying
person.Name.ShouldBe(uniquePersonName); person.Name.ShouldBe(uniquePersonName);
person.Age.ShouldBe(firstPerson.Age); 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.ShouldNotBeNull();
personInDb.Id.ShouldBe(person.Id); personInDb.Id.ShouldBe(person.Id);
personInDb.Name.ShouldBe(person.Name); personInDb.Name.ShouldBe(person.Name);

1
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 Microsoft.Extensions.DependencyInjection;
using Xunit; using Xunit;
using Shouldly; using Shouldly;
using Volo.Abp.Application.Dtos;
namespace Volo.Abp.Identity namespace Volo.Abp.Identity
{ {

11
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 Microsoft.Extensions.DependencyInjection;
using Shouldly; using Shouldly;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Entities;
using Xunit; using Xunit;
namespace Volo.Abp.Identity namespace Volo.Abp.Identity
@ -184,12 +185,18 @@ namespace Volo.Abp.Identity
private async Task<IdentityUser> GetUserAsync(string userName) private async Task<IdentityUser> 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<IdentityUser> FindUserAsync(string userName) private async Task<IdentityUser> FindUserAsync(string userName)
{ {
return (await _userRepository.GetListAsync()).FirstOrDefault(u => u.UserName == userName); return await _userRepository.FindByNormalizedUserNameAsync(userName.ToUpperInvariant());
} }
private static string CreateRandomEmail() private static string CreateRandomEmail()

10
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() public void Should_Get_Deleted_Entities_When_Filter_Is_Disabled()
{ {
//Soft delete is enabled by default //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).ShouldBeTrue();
people.Any(p => p.IsDeleted).ShouldBeFalse(); people.Any(p => p.IsDeleted).ShouldBeFalse();
using (_dataFilter.Disable<ISoftDelete>()) using (_dataFilter.Disable<ISoftDelete>())
{ {
//Soft delete is disabled //Soft delete is disabled
people = _personRepository.GetList(); people = _personRepository.ToList();
people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => !p.IsDeleted).ShouldBeTrue();
people.Any(p => p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeTrue();
using (_dataFilter.Enable<ISoftDelete>()) using (_dataFilter.Enable<ISoftDelete>())
{ {
//Soft delete is enabled again //Soft delete is enabled again
people = _personRepository.GetList(); people = _personRepository.ToList();
people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => !p.IsDeleted).ShouldBeTrue();
people.Any(p => p.IsDeleted).ShouldBeFalse(); people.Any(p => p.IsDeleted).ShouldBeFalse();
} }
//Soft delete is disabled (restored previous state) //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();
people.Any(p => p.IsDeleted).ShouldBeTrue(); people.Any(p => p.IsDeleted).ShouldBeTrue();
} }
//Soft delete is enabled (restored previous state) //Soft delete is enabled (restored previous state)
people = _personRepository.GetList(); people = _personRepository.ToList();
people.Any(p => !p.IsDeleted).ShouldBeTrue(); people.Any(p => !p.IsDeleted).ShouldBeTrue();
people.Any(p => p.IsDeleted).ShouldBeFalse(); people.Any(p => p.IsDeleted).ShouldBeFalse();
} }

19
test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/DataFilters/MultiTenant_Filter_Tests.cs

@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using NSubstitute; using NSubstitute;
using Shouldly; using Shouldly;
@ -17,12 +16,12 @@ namespace Volo.Abp.MemoryDb.DataFilters
public class MemoryDb_MultiTenant_Filter_Tests : MemoryDbTestBase public class MemoryDb_MultiTenant_Filter_Tests : MemoryDbTestBase
{ {
private ICurrentTenant _fakeCurrentTenant; private ICurrentTenant _fakeCurrentTenant;
private readonly IRepository<Person, Guid> _personRepository; private readonly IQueryableRepository<Person, Guid> _personRepository;
private readonly IDataFilter<IMultiTenant> _multiTenantFilter; private readonly IDataFilter<IMultiTenant> _multiTenantFilter;
public MemoryDb_MultiTenant_Filter_Tests() public MemoryDb_MultiTenant_Filter_Tests()
{ {
_personRepository = GetRequiredService<IRepository<Person, Guid>>(); _personRepository = GetRequiredService<IQueryableRepository<Person, Guid>>();
_multiTenantFilter = GetRequiredService<IDataFilter<IMultiTenant>>(); _multiTenantFilter = GetRequiredService<IDataFilter<IMultiTenant>>();
} }
@ -33,13 +32,13 @@ namespace Volo.Abp.MemoryDb.DataFilters
} }
[Fact] [Fact]
public async Task Should_Get_Person_For_Current_Tenant() public void Should_Get_Person_For_Current_Tenant()
{ {
//TenantId = null //TenantId = null
_fakeCurrentTenant.Id.Returns((Guid?)null); _fakeCurrentTenant.Id.Returns((Guid?)null);
var people = await _personRepository.GetListAsync(); var people = _personRepository.ToList();
people.Count.ShouldBe(1); people.Count.ShouldBe(1);
people.Any(p => p.Name == "Douglas").ShouldBeTrue(); people.Any(p => p.Name == "Douglas").ShouldBeTrue();
@ -47,7 +46,7 @@ namespace Volo.Abp.MemoryDb.DataFilters
_fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId1); _fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId1);
people = await _personRepository.GetListAsync(); people = _personRepository.ToList();
people.Count.ShouldBe(2); people.Count.ShouldBe(2);
people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person1").ShouldBeTrue(); people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person1").ShouldBeTrue();
people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person2").ShouldBeTrue(); people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person2").ShouldBeTrue();
@ -56,24 +55,24 @@ namespace Volo.Abp.MemoryDb.DataFilters
_fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId2); _fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId2);
people = await _personRepository.GetListAsync(); people = _personRepository.ToList();
people.Count.ShouldBe(0); people.Count.ShouldBe(0);
} }
[Fact] [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<Person> people; List<Person> people;
using (_multiTenantFilter.Disable()) using (_multiTenantFilter.Disable())
{ {
//Filter disabled manually //Filter disabled manually
people = await _personRepository.GetListAsync(); people = _personRepository.ToList();
people.Count.ShouldBe(3); people.Count.ShouldBe(3);
} }
//Filter re-enabled automatically //Filter re-enabled automatically
people = await _personRepository.GetListAsync(); people = _personRepository.ToList();
people.Count.ShouldBe(1); people.Count.ShouldBe(1);
} }
} }

2
test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/MemoryDb_Basic_Repository_Tests.cs

@ -20,7 +20,7 @@ namespace Volo.Abp.MemoryDb.Repositories
[Fact] [Fact]
public void GetList() public void GetList()
{ {
var people = _personRepository.GetList(); var people = _personRepository.ToList();
people.Count.ShouldBeGreaterThan(0); people.Count.ShouldBeGreaterThan(0);
} }

Loading…
Cancel
Save