Browse Source

Merge pull request #2464 from abpframework/remove-async-apis

Re-design interception & sync/async APIs
pull/2466/head
Halil İbrahim Kalkan 6 years ago
committed by GitHub
parent
commit
88ded4ef64
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/CachedApplicationConfigurationClient.cs
  2. 2
      framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/ICachedApplicationConfigurationClient.cs
  3. 2
      framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs
  4. 27
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingInterceptor.cs
  5. 15
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingManager.cs
  6. 2
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/IAuditLogSaveHandle.cs
  7. 2
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/IAuditingStore.cs
  8. 7
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/SimpleLogAuditingStore.cs
  9. 7
      framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AuthorizationInterceptor.cs
  10. 2
      framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs
  11. 6
      framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs
  12. 34
      framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/IBackgroundJobStore.cs
  13. 1
      framework/src/Volo.Abp.Castle.Core/Volo.Abp.Castle.Core.csproj
  14. 2
      framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/AbpCastleCoreModule.cs
  15. 15
      framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/AbpAsyncDeterminationInterceptor.cs
  16. 89
      framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpInterceptorAdapter.cs
  17. 67
      framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpMethodInvocationAdapter.cs
  18. 48
      framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpMethodInvocationAdapterBase.cs
  19. 27
      framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpMethodInvocationAdapterWithReturnValue.cs
  20. 36
      framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAsyncAbpInterceptorAdapter.cs
  21. 12
      framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/AbpInterceptor.cs
  22. 2
      framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/IAbpInterceptor.cs
  23. 2
      framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/IAbpMethodInvocation.cs
  24. 70
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs
  25. 42
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IBasicRepository.cs
  26. 31
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyBasicRepository.cs
  27. 13
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IRepository.cs
  28. 55
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs
  29. 73
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs
  30. 42
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs
  31. 13
      framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureInterceptor.cs
  32. 6
      framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs
  33. 45
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs
  34. 79
      framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs
  35. 120
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs
  36. 15
      framework/src/Volo.Abp.Uow/Volo/Abp/Uow/ChildUnitOfWork.cs
  37. 6
      framework/src/Volo.Abp.Uow/Volo/Abp/Uow/IUnitOfWork.cs
  38. 58
      framework/src/Volo.Abp.Uow/Volo/Abp/Uow/UnitOfWork.cs
  39. 15
      framework/src/Volo.Abp.Uow/Volo/Abp/Uow/UnitOfWorkInterceptor.cs
  40. 6
      framework/src/Volo.Abp.Validation/Volo/Abp/Validation/ValidationInterceptor.cs
  41. 18
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PeopleAppService_Tests.cs
  42. 6
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Uow/TestUnitOfWork.cs
  43. 1
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Uow/UnitOfWorkTestController.cs
  44. 3
      framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/v1/ITodoAppService.cs
  45. 7
      framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/v1/TodoAppService.cs
  46. 3
      framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/v2/ITodoAppService.cs
  47. 7
      framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/v2/TodoAppService.cs
  48. 7
      framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Test/v1/TodoAppService_Tests.cs
  49. 7
      framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Test/v2/TodoAppService_Tests.cs
  50. 10
      framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/Authorization_Tests.cs
  51. 4
      framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/TestServices/IMyAuthorizedService1.cs
  52. 8
      framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/TestServices/MyAuthorizedService1.cs
  53. 94
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/AbpInterceptionTestBase.cs
  54. 9
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/SimpleAsyncInterceptor.cs
  55. 11
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/SimpleResultCacheTestInterceptor.cs
  56. 14
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/SimpleSyncInterceptor.cs
  57. 34
      framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs
  58. 5
      framework/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/AbpEfCoreTestSecondContextModule.cs
  59. 5
      framework/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/SecondContextTestDataBuilder.cs
  60. 15
      framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DbContext_Replace_Tests.cs
  61. 16
      framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Queryable_Tests.cs
  62. 11
      framework/test/Volo.Abp.Features.Tests/Volo/Abp/Features/ClassFeatureTestService.cs
  63. 12
      framework/test/Volo.Abp.Features.Tests/Volo/Abp/Features/FeatureInterceptor_Tests.cs
  64. 45
      framework/test/Volo.Abp.FluentValidation.Tests/Volo/Abp/FluentValidation/ApplicationService_FluentValidation_Tests.cs
  65. 2
      framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/IRegularTestController.cs
  66. 12
      framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs
  67. 7
      framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestController.cs
  68. 6
      framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestControllerClientProxy_Tests.cs
  69. 11
      framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests.cs
  70. 7
      framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests_With_Int_Pk.cs
  71. 6
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs
  72. 5
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestAppModule.cs
  73. 47
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs
  74. 6
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs
  75. 13
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/MultiTenant_Filter_Tests.cs
  76. 12
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Basic_Tests_With_Int_Pk.cs
  77. 21
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Queryable_Tests.cs
  78. 6
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Specifications_Tests.cs
  79. 16
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/SoftDelete_Filter_Tests.cs
  80. 40
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/TestAppTestBase.cs
  81. 17
      framework/test/Volo.Abp.Uow.Tests/Volo/Abp/Uow/UnitOfWork_Events_Tests.cs
  82. 122
      framework/test/Volo.Abp.Validation.Tests/Volo/Abp/Validation/ApplicationService_Validation_Tests.cs
  83. 27
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs
  84. 6
      modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AuditLogRepository_Tests.cs
  85. 12
      modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLogRepository_Tests.cs
  86. 2
      modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs
  87. 31
      modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobStore.cs
  88. 5
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/AbpBackgroundJobsTestBaseModule.cs
  89. 9
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestDataBuilder.cs
  90. 2
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs
  91. 3
      modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Tagging/ITagRepository.cs
  92. 7
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs
  93. 11
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs
  94. 2
      modules/blogging/test/Volo.Blogging.TestBase/Volo/Blogging/Tagging/TagRepository_Tests.cs
  95. 5
      modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocsTestBaseModule.cs
  96. 7
      modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocsTestDataBuilder.cs
  97. 5
      modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementTestBaseModule.cs
  98. 33
      modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementTestDataBuilder.cs
  99. 5
      modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/AbpIdentityDomainTestModule.cs
  100. 4
      modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityClaimTypeManager_Tests.cs

27
framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/CachedApplicationConfigurationClient.cs

@ -31,33 +31,6 @@ namespace Volo.Abp.AspNetCore.Mvc.Client
Cache = cache;
}
public ApplicationConfigurationDto Get()
{
var cacheKey = CreateCacheKey();
var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration)
{
return configuration;
}
configuration = Cache.GetOrAdd(
cacheKey,
() => AsyncHelper.RunSync(Proxy.Service.GetAsync),
() => new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(120) //TODO: Should be configurable. Default value should be higher (5 mins would be good).
}
);
if (httpContext != null)
{
httpContext.Items[cacheKey] = configuration;
}
return configuration;
}
public async Task<ApplicationConfigurationDto> GetAsync()
{
var cacheKey = CreateCacheKey();

2
framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/ICachedApplicationConfigurationClient.cs

@ -5,8 +5,6 @@ namespace Volo.Abp.AspNetCore.Mvc.Client
{
public interface ICachedApplicationConfigurationClient
{
ApplicationConfigurationDto Get();
Task<ApplicationConfigurationDto> GetAsync();
}
}

2
framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs

@ -55,7 +55,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Client
private Dictionary<string, string> GetResourceOrNull()
{
var applicationConfigurationDto = _applicationConfigurationClient.Get();
var applicationConfigurationDto = AsyncHelper.RunSync(() => _applicationConfigurationClient.GetAsync());
var resource = applicationConfigurationDto
.Localization.Values

27
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingInterceptor.cs

@ -18,33 +18,6 @@ namespace Volo.Abp.Auditing
_auditingManager = auditingManager;
}
public override void Intercept(IAbpMethodInvocation invocation)
{
if (!ShouldIntercept(invocation, out var auditLog, out var auditLogAction))
{
invocation.Proceed();
return;
}
var stopwatch = Stopwatch.StartNew();
try
{
invocation.Proceed();
}
catch (Exception ex)
{
auditLog.Exceptions.Add(ex);
throw;
}
finally
{
stopwatch.Stop();
auditLogAction.ExecutionDuration = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds);
auditLog.Actions.Add(auditLogAction);
}
}
public override async Task InterceptAsync(IAbpMethodInvocation invocation)
{
if (!ShouldIntercept(invocation, out var auditLog, out var auditLogAction))

15
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingManager.cs

@ -120,16 +120,6 @@ namespace Volo.Abp.Auditing
}
}
protected virtual void Save(DisposableSaveHandle saveHandle)
{
BeforeSave(saveHandle);
if (ShouldSave(saveHandle.AuditLog))
{
_auditingStore.Save(saveHandle.AuditLog);
}
}
protected bool ShouldSave(AuditLogInfo auditLog)
{
if (!auditLog.Actions.Any() && !auditLog.EntityChanges.Any())
@ -165,11 +155,6 @@ namespace Volo.Abp.Auditing
await _auditingManager.SaveAsync(this);
}
public void Save()
{
_auditingManager.Save(this);
}
public void Dispose()
{
_scope.Dispose();

2
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/IAuditLogSaveHandle.cs

@ -5,8 +5,6 @@ namespace Volo.Abp.Auditing
{
public interface IAuditLogSaveHandle : IDisposable
{
void Save();
Task SaveAsync();
}
}

2
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/IAuditingStore.cs

@ -4,8 +4,6 @@ namespace Volo.Abp.Auditing
{
public interface IAuditingStore
{
void Save(AuditLogInfo auditInfo);
Task SaveAsync(AuditLogInfo auditInfo);
}
}

7
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/SimpleLogAuditingStore.cs

@ -15,14 +15,9 @@ namespace Volo.Abp.Auditing
Logger = NullLogger<SimpleLogAuditingStore>.Instance;
}
public void Save(AuditLogInfo auditInfo)
{
Logger.LogInformation(auditInfo.ToString());
}
public Task SaveAsync(AuditLogInfo auditInfo)
{
Save(auditInfo);
Logger.LogInformation(auditInfo.ToString());
return Task.FromResult(0);
}
}

7
framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AuthorizationInterceptor.cs

@ -1,7 +1,6 @@
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy;
using Volo.Abp.Threading;
namespace Volo.Abp.Authorization
{
@ -14,12 +13,6 @@ namespace Volo.Abp.Authorization
_methodInvocationAuthorizationService = methodInvocationAuthorizationService;
}
public override void Intercept(IAbpMethodInvocation invocation)
{
AsyncHelper.RunSync(() => AuthorizeAsync(invocation));
invocation.Proceed();
}
public override async Task InterceptAsync(IAbpMethodInvocation invocation)
{
await AuthorizeAsync(invocation);

2
framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs

@ -89,7 +89,7 @@ namespace Autofac.Builder
foreach (var interceptor in interceptors)
{
registrationBuilder.InterceptedBy(
typeof(CastleAbpInterceptorAdapter<>).MakeGenericType(interceptor)
typeof(AbpAsyncDeterminationInterceptor<>).MakeGenericType(interceptor)
);
}

6
framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/BackgroundJobWorker.cs

@ -36,7 +36,7 @@ namespace Volo.Abp.BackgroundJobs
{
var store = scope.ServiceProvider.GetRequiredService<IBackgroundJobStore>();
var waitingJobs = store.GetWaitingJobs(WorkerOptions.MaxJobFetchCount);
var waitingJobs = AsyncHelper.RunSync(() => store.GetWaitingJobsAsync(WorkerOptions.MaxJobFetchCount));
if (!waitingJobs.Any())
{
@ -62,7 +62,7 @@ namespace Volo.Abp.BackgroundJobs
{
jobExecuter.Execute(context);
store.Delete(jobInfo.Id);
AsyncHelper.RunSync(() => store.DeleteAsync(jobInfo.Id));
}
catch (BackgroundJobExecutionException)
{
@ -94,7 +94,7 @@ namespace Volo.Abp.BackgroundJobs
{
try
{
store.Update(jobInfo);
AsyncHelper.RunSync(() => store.UpdateAsync(jobInfo));
}
catch (Exception updateEx)
{

34
framework/src/Volo.Abp.BackgroundJobs/Volo/Abp/BackgroundJobs/IBackgroundJobStore.cs

@ -9,13 +9,6 @@ namespace Volo.Abp.BackgroundJobs
/// </summary>
public interface IBackgroundJobStore
{
/// <summary>
/// Gets a BackgroundJobInfo based on the given jobId.
/// </summary>
/// <param name="jobId">The Job Unique Identifier.</param>
/// <returns>The BackgroundJobInfo object.</returns>
BackgroundJobInfo Find(Guid jobId);
/// <summary>
/// Gets a BackgroundJobInfo based on the given jobId.
/// </summary>
@ -23,27 +16,12 @@ namespace Volo.Abp.BackgroundJobs
/// <returns>The BackgroundJobInfo object.</returns>
Task<BackgroundJobInfo> FindAsync(Guid jobId);
/// <summary>
/// Inserts a background job.
/// </summary>
/// <param name="jobInfo">Job information.</param>
void Insert(BackgroundJobInfo jobInfo);
/// <summary>
/// Inserts a background job.
/// </summary>
/// <param name="jobInfo">Job information.</param>
Task InsertAsync(BackgroundJobInfo jobInfo);
/// <summary>
/// Gets waiting jobs. It should get jobs based on these:
/// Conditions: !IsAbandoned And NextTryTime &lt;= Clock.Now.
/// Order by: Priority DESC, TryCount ASC, NextTryTime ASC.
/// Maximum result: <paramref name="maxResultCount"/>.
/// </summary>
/// <param name="maxResultCount">Maximum result count.</param>
List<BackgroundJobInfo> GetWaitingJobs(int maxResultCount);
/// <summary>
/// Gets waiting jobs. It should get jobs based on these:
/// Conditions: !IsAbandoned And NextTryTime &lt;= Clock.Now.
@ -53,24 +31,12 @@ namespace Volo.Abp.BackgroundJobs
/// <param name="maxResultCount">Maximum result count.</param>
Task<List<BackgroundJobInfo>> GetWaitingJobsAsync(int maxResultCount);
/// <summary>
/// Deletes a job.
/// </summary>
/// <param name="jobId">The Job Unique Identifier.</param>
void Delete(Guid jobId);
/// <summary>
/// Deletes a job.
/// </summary>
/// <param name="jobId">The Job Unique Identifier.</param>
Task DeleteAsync(Guid jobId);
/// <summary>
/// Updates a job.
/// </summary>
/// <param name="jobInfo">Job information.</param>
void Update(BackgroundJobInfo jobInfo);
/// <summary>
/// Updates a job.
/// </summary>

1
framework/src/Volo.Abp.Castle.Core/Volo.Abp.Castle.Core.csproj

@ -15,6 +15,7 @@
<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.4.0" />
<PackageReference Include="Castle.Core.AsyncInterceptor" Version="2.0.21-alpha" />
</ItemGroup>
<ItemGroup>

2
framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/AbpCastleCoreModule.cs

@ -8,7 +8,7 @@ namespace Volo.Abp.Castle
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddTransient(typeof(CastleAbpInterceptorAdapter<>));
context.Services.AddTransient(typeof(AbpAsyncDeterminationInterceptor<>));
}
}
}

15
framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/AbpAsyncDeterminationInterceptor.cs

@ -0,0 +1,15 @@
using Castle.DynamicProxy;
using Volo.Abp.DynamicProxy;
namespace Volo.Abp.Castle.DynamicProxy
{
public class AbpAsyncDeterminationInterceptor<TInterceptor> : AsyncDeterminationInterceptor
where TInterceptor : IAbpInterceptor
{
public AbpAsyncDeterminationInterceptor(TInterceptor abpInterceptor)
: base(new CastleAsyncAbpInterceptorAdapter<TInterceptor>(abpInterceptor))
{
}
}
}

89
framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpInterceptorAdapter.cs

@ -1,89 +0,0 @@
using System.Reflection;
using System.Threading.Tasks;
using Castle.DynamicProxy;
using Volo.Abp.DynamicProxy;
using Volo.Abp.Threading;
namespace Volo.Abp.Castle.DynamicProxy
{
public class CastleAbpInterceptorAdapter<TInterceptor> : IInterceptor
where TInterceptor : IAbpInterceptor
{
private static readonly MethodInfo MethodExecuteWithoutReturnValueAsync =
typeof(CastleAbpInterceptorAdapter<TInterceptor>)
.GetMethod(
nameof(ExecuteWithoutReturnValueAsync),
BindingFlags.NonPublic | BindingFlags.Instance
);
private static readonly MethodInfo MethodExecuteWithReturnValueAsync =
typeof(CastleAbpInterceptorAdapter<TInterceptor>)
.GetMethod(
nameof(ExecuteWithReturnValueAsync),
BindingFlags.NonPublic | BindingFlags.Instance
);
private readonly TInterceptor _abpInterceptor;
public CastleAbpInterceptorAdapter(TInterceptor abpInterceptor)
{
_abpInterceptor = abpInterceptor;
}
public void Intercept(IInvocation invocation)
{
var proceedInfo = invocation.CaptureProceedInfo();
var method = invocation.MethodInvocationTarget ?? invocation.Method;
if (method.IsAsync())
{
InterceptAsyncMethod(invocation, proceedInfo);
}
else
{
InterceptSyncMethod(invocation, proceedInfo);
}
}
private void InterceptSyncMethod(IInvocation invocation, IInvocationProceedInfo proceedInfo)
{
_abpInterceptor.Intercept(new CastleAbpMethodInvocationAdapter(invocation, proceedInfo));
}
private void InterceptAsyncMethod(IInvocation invocation, IInvocationProceedInfo proceedInfo)
{
if (invocation.Method.ReturnType == typeof(Task))
{
invocation.ReturnValue = MethodExecuteWithoutReturnValueAsync
.Invoke(this, new object[] { invocation, proceedInfo });
}
else
{
invocation.ReturnValue = MethodExecuteWithReturnValueAsync
.MakeGenericMethod(invocation.Method.ReturnType.GenericTypeArguments[0])
.Invoke(this, new object[] {invocation, proceedInfo});
}
}
private async Task ExecuteWithoutReturnValueAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo)
{
await Task.Yield();
await _abpInterceptor.InterceptAsync(
new CastleAbpMethodInvocationAdapter(invocation, proceedInfo)
);
}
private async Task<T> ExecuteWithReturnValueAsync<T>(IInvocation invocation, IInvocationProceedInfo proceedInfo)
{
await Task.Yield();
await _abpInterceptor.InterceptAsync(
new CastleAbpMethodInvocationAdapter(invocation, proceedInfo)
);
return await (Task<T>)invocation.ReturnValue;
}
}
}

67
framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpMethodInvocationAdapter.cs

@ -1,77 +1,26 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using Castle.DynamicProxy;
using Volo.Abp.DynamicProxy;
using Volo.Abp.Threading;
namespace Volo.Abp.Castle.DynamicProxy
{
public class CastleAbpMethodInvocationAdapter : IAbpMethodInvocation
public class CastleAbpMethodInvocationAdapter : CastleAbpMethodInvocationAdapterBase, IAbpMethodInvocation
{
public object[] Arguments => Invocation.Arguments;
public IReadOnlyDictionary<string, object> ArgumentsDictionary => _lazyArgumentsDictionary.Value;
private readonly Lazy<IReadOnlyDictionary<string, object>> _lazyArgumentsDictionary;
public Type[] GenericArguments => Invocation.GenericArguments;
public object TargetObject => Invocation.InvocationTarget ?? Invocation.MethodInvocationTarget;
public MethodInfo Method => Invocation.MethodInvocationTarget ?? Invocation.Method;
public object ReturnValue
{
get => _actualReturnValue ?? Invocation.ReturnValue;
set => Invocation.ReturnValue = value;
}
private object _actualReturnValue;
protected IInvocation Invocation { get; }
protected IInvocationProceedInfo ProceedInfo { get; }
protected Func<IInvocation, IInvocationProceedInfo, Task> Proceed { get; }
public CastleAbpMethodInvocationAdapter(IInvocation invocation, IInvocationProceedInfo proceedInfo)
public CastleAbpMethodInvocationAdapter(IInvocation invocation, IInvocationProceedInfo proceedInfo,
Func<IInvocation, IInvocationProceedInfo, Task> proceed)
: base(invocation)
{
Invocation = invocation;
ProceedInfo = proceedInfo;
_lazyArgumentsDictionary = new Lazy<IReadOnlyDictionary<string, object>>(GetArgumentsDictionary);
Proceed = proceed;
}
public void Proceed()
public override async Task ProceedAsync()
{
ProceedInfo.Invoke();
if (Invocation.Method.IsAsync())
{
AsyncHelper.RunSync(() => (Task)Invocation.ReturnValue);
}
}
public Task ProceedAsync()
{
ProceedInfo.Invoke();
_actualReturnValue = Invocation.ReturnValue;
return Invocation.Method.IsAsync()
? (Task)_actualReturnValue
: Task.FromResult(_actualReturnValue);
}
private IReadOnlyDictionary<string, object> GetArgumentsDictionary()
{
var dict = new Dictionary<string, object>();
var methodParameters = Method.GetParameters();
for (int i = 0; i < methodParameters.Length; i++)
{
dict[methodParameters[i].Name] = Invocation.Arguments[i];
}
return dict;
await Proceed(Invocation, ProceedInfo);
}
}
}

48
framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpMethodInvocationAdapterBase.cs

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using Castle.DynamicProxy;
using Volo.Abp.DynamicProxy;
namespace Volo.Abp.Castle.DynamicProxy
{
public abstract class CastleAbpMethodInvocationAdapterBase : IAbpMethodInvocation
{
public object[] Arguments => Invocation.Arguments;
public IReadOnlyDictionary<string, object> ArgumentsDictionary => _lazyArgumentsDictionary.Value;
private readonly Lazy<IReadOnlyDictionary<string, object>> _lazyArgumentsDictionary;
public Type[] GenericArguments => Invocation.GenericArguments;
public object TargetObject => Invocation.InvocationTarget ?? Invocation.MethodInvocationTarget;
public MethodInfo Method => Invocation.MethodInvocationTarget ?? Invocation.Method;
public object ReturnValue { get; set; }
protected IInvocation Invocation { get; }
protected CastleAbpMethodInvocationAdapterBase(IInvocation invocation)
{
Invocation = invocation;
_lazyArgumentsDictionary = new Lazy<IReadOnlyDictionary<string, object>>(GetArgumentsDictionary);
}
public abstract Task ProceedAsync();
private IReadOnlyDictionary<string, object> GetArgumentsDictionary()
{
var dict = new Dictionary<string, object>();
var methodParameters = Method.GetParameters();
for (int i = 0; i < methodParameters.Length; i++)
{
dict[methodParameters[i].Name] = Invocation.Arguments[i];
}
return dict;
}
}
}

27
framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpMethodInvocationAdapterWithReturnValue.cs

@ -0,0 +1,27 @@
using System;
using System.Threading.Tasks;
using Castle.DynamicProxy;
using Volo.Abp.DynamicProxy;
namespace Volo.Abp.Castle.DynamicProxy
{
public class CastleAbpMethodInvocationAdapterWithReturnValue<TResult> : CastleAbpMethodInvocationAdapterBase, IAbpMethodInvocation
{
protected IInvocationProceedInfo ProceedInfo { get; }
protected Func<IInvocation, IInvocationProceedInfo, Task<TResult>> Proceed { get; }
public CastleAbpMethodInvocationAdapterWithReturnValue(IInvocation invocation,
IInvocationProceedInfo proceedInfo,
Func<IInvocation, IInvocationProceedInfo, Task<TResult>> proceed)
: base(invocation)
{
ProceedInfo = proceedInfo;
Proceed = proceed;
}
public override async Task ProceedAsync()
{
ReturnValue = await Proceed(Invocation, ProceedInfo);
}
}
}

36
framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAsyncAbpInterceptorAdapter.cs

@ -0,0 +1,36 @@
using System;
using System.Threading.Tasks;
using Castle.DynamicProxy;
using Volo.Abp.DynamicProxy;
namespace Volo.Abp.Castle.DynamicProxy
{
public class CastleAsyncAbpInterceptorAdapter<TInterceptor> : AsyncInterceptorBase
where TInterceptor : IAbpInterceptor
{
private readonly TInterceptor _abpInterceptor;
public CastleAsyncAbpInterceptorAdapter(TInterceptor abpInterceptor)
{
_abpInterceptor = abpInterceptor;
}
protected override async Task InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func<IInvocation, IInvocationProceedInfo, Task> proceed)
{
await _abpInterceptor.InterceptAsync(
new CastleAbpMethodInvocationAdapter(invocation, proceedInfo, proceed)
);
}
protected override async Task<TResult> InterceptAsync<TResult>(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func<IInvocation, IInvocationProceedInfo, Task<TResult>> proceed)
{
var adapter = new CastleAbpMethodInvocationAdapterWithReturnValue<TResult>(invocation, proceedInfo, proceed);
await _abpInterceptor.InterceptAsync(
adapter
);
return (TResult)adapter.ReturnValue;
}
}
}

12
framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/AbpInterceptor.cs

@ -3,13 +3,7 @@
namespace Volo.Abp.DynamicProxy
{
public abstract class AbpInterceptor : IAbpInterceptor
{
public abstract void Intercept(IAbpMethodInvocation invocation);
public virtual Task InterceptAsync(IAbpMethodInvocation invocation)
{
Intercept(invocation);
return Task.CompletedTask;
}
}
{
public abstract Task InterceptAsync(IAbpMethodInvocation invocation);
}
}

2
framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/IAbpInterceptor.cs

@ -4,8 +4,6 @@ namespace Volo.Abp.DynamicProxy
{
public interface IAbpInterceptor
{
void Intercept(IAbpMethodInvocation invocation);
Task InterceptAsync(IAbpMethodInvocation invocation);
}
}

2
framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/IAbpMethodInvocation.cs

@ -19,8 +19,6 @@ namespace Volo.Abp.DynamicProxy
object ReturnValue { get; set; }
void Proceed();
Task ProceedAsync();
}
}

70
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs

@ -25,54 +25,28 @@ namespace Volo.Abp.Domain.Repositories
CancellationTokenProvider = NullCancellationTokenProvider.Instance;
}
public abstract TEntity Insert(TEntity entity, bool autoSave = false);
public abstract Task<TEntity> InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default);
public virtual Task<TEntity> InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
return Task.FromResult(Insert(entity, autoSave));
}
public abstract Task<TEntity> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default);
public abstract TEntity Update(TEntity entity, bool autoSave = false);
public abstract Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default);
public virtual Task<TEntity> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
return Task.FromResult(Update(entity));
}
public abstract Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default);
public abstract void Delete(TEntity entity, bool autoSave = false);
public virtual Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
Delete(entity);
return Task.CompletedTask;
}
public abstract Task<long> GetCountAsync(CancellationToken cancellationToken = default);
protected virtual CancellationToken GetCancellationToken(CancellationToken prefferedValue = default)
protected virtual CancellationToken GetCancellationToken(CancellationToken preferredValue = default)
{
return CancellationTokenProvider.FallbackToProvider(prefferedValue);
}
public abstract List<TEntity> GetList(bool includeDetails = false);
public virtual Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default)
{
return Task.FromResult(GetList(includeDetails));
}
public abstract long GetCount();
public virtual Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{
return Task.FromResult(GetCount());
return CancellationTokenProvider.FallbackToProvider(preferredValue);
}
}
public abstract class BasicRepositoryBase<TEntity, TKey> : BasicRepositoryBase<TEntity>, IBasicRepository<TEntity, TKey>
where TEntity : class, IEntity<TKey>
{
public virtual TEntity Get(TKey id, bool includeDetails = true)
public virtual async Task<TEntity> GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default)
{
var entity = Find(id, includeDetails);
var entity = await FindAsync(id, includeDetails, cancellationToken);
if (entity == null)
{
@ -82,33 +56,17 @@ namespace Volo.Abp.Domain.Repositories
return entity;
}
public virtual Task<TEntity> GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return Task.FromResult(Get(id, includeDetails));
}
public abstract TEntity Find(TKey id, bool includeDetails = true);
public virtual Task<TEntity> FindAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return Task.FromResult(Find(id, includeDetails));
}
public virtual void Delete(TKey id, bool autoSave = false)
public abstract Task<TEntity> FindAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default);
public virtual async Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default)
{
var entity = Find(id);
var entity = await FindAsync(id, cancellationToken: cancellationToken);
if (entity == null)
{
return;
}
Delete(entity);
}
public virtual Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default)
{
Delete(id);
return Task.CompletedTask;
await DeleteAsync(entity, autoSave, cancellationToken);
}
}
}

42
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IBasicRepository.cs

@ -8,17 +8,6 @@ namespace Volo.Abp.Domain.Repositories
public interface IBasicRepository<TEntity> : IReadOnlyBasicRepository<TEntity>
where TEntity : class, IEntity
{
/// <summary>
/// Inserts a new entity.
/// </summary>
/// <param name="entity">Inserted entity</param>
/// <param name="autoSave">
/// Set true to automatically save entity to database.
/// This is useful for ORMs / database APIs those only save changes with an explicit method call, but you need to immediately save changes to the database.
/// </param>
[NotNull]
TEntity Insert([NotNull] TEntity entity, bool autoSave = false);
/// <summary>
/// Inserts a new entity.
/// </summary>
@ -31,17 +20,6 @@ namespace Volo.Abp.Domain.Repositories
[NotNull]
Task<TEntity> InsertAsync([NotNull] TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default);
/// <summary>
/// Updates an existing entity.
/// </summary>
/// <param name="entity">Entity</param>
/// <param name="autoSave">
/// Set true to automatically save changes to database.
/// This is useful for ORMs / database APIs those only save changes with an explicit method call, but you need to immediately save changes to the database.
/// </param>
[NotNull]
TEntity Update([NotNull] TEntity entity, bool autoSave = false);
/// <summary>
/// Updates an existing entity.
/// </summary>
@ -54,16 +32,6 @@ namespace Volo.Abp.Domain.Repositories
[NotNull]
Task<TEntity> UpdateAsync([NotNull] TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default);
/// <summary>
/// Deletes an entity.
/// </summary>
/// <param name="entity">Entity to be deleted</param>
/// <param name="autoSave">
/// Set true to automatically save changes to database.
/// This is useful for ORMs / database APIs those only save changes with an explicit method call, but you need to immediately save changes to the database.
/// </param>
void Delete([NotNull] TEntity entity, bool autoSave = false);
/// <summary>
/// Deletes an entity.
/// </summary>
@ -79,16 +47,6 @@ namespace Volo.Abp.Domain.Repositories
public interface IBasicRepository<TEntity, TKey> : IBasicRepository<TEntity>, IReadOnlyBasicRepository<TEntity, TKey>
where TEntity : class, IEntity<TKey>
{
/// <summary>
/// Deletes an entity by primary key.
/// </summary>
/// <param name="id">Primary key of the entity</param>
/// <param name="autoSave">
/// Set true to automatically save changes to database.
/// This is useful for ORMs / database APIs those only save changes with an explicit method call, but you need to immediately save changes to the database.
/// </param>
void Delete(TKey id, bool autoSave = false); //TODO: Return true if deleted
/// <summary>
/// Deletes an entity by primary key.
/// </summary>

31
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyBasicRepository.cs

@ -9,13 +9,6 @@ namespace Volo.Abp.Domain.Repositories
public interface IReadOnlyBasicRepository<TEntity> : IRepository
where TEntity : class, IEntity
{
/// <summary>
/// Gets a list of all the entities.
/// </summary>
/// <param name="includeDetails">Set true to include all children of this entity</param>
/// <returns>Entity</returns>
List<TEntity> GetList(bool includeDetails = false);
/// <summary>
/// Gets a list of all the entities.
/// </summary>
@ -24,11 +17,6 @@ namespace Volo.Abp.Domain.Repositories
/// <returns>Entity</returns>
Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default);
/// <summary>
/// Gets total count of all entities.
/// </summary>
long GetCount();
/// <summary>
/// Gets total count of all entities.
/// </summary>
@ -38,16 +26,6 @@ namespace Volo.Abp.Domain.Repositories
public interface IReadOnlyBasicRepository<TEntity, TKey> : IReadOnlyBasicRepository<TEntity>
where TEntity : class, IEntity<TKey>
{
/// <summary>
/// Gets an entity with given primary key.
/// Throws <see cref="EntityNotFoundException"/> if can not find an entity with given id.
/// </summary>
/// <param name="id">Primary key of the entity to get</param>
/// <param name="includeDetails">Set true to include all children of this entity</param>
/// <returns>Entity</returns>
[NotNull]
TEntity Get(TKey id, bool includeDetails = true);
/// <summary>
/// Gets an entity with given primary key.
/// Throws <see cref="EntityNotFoundException"/> if can not find an entity with given id.
@ -59,15 +37,6 @@ namespace Volo.Abp.Domain.Repositories
[NotNull]
Task<TEntity> GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default);
/// <summary>
/// Gets an entity with given primary key or null if not found.
/// </summary>
/// <param name="id">Primary key of the entity to get</param>
/// <param name="includeDetails">Set true to include all children of this entity</param>
/// <returns>Entity or null</returns>
[CanBeNull]
TEntity Find(TKey id, bool includeDetails = true);
/// <summary>
/// Gets an entity with given primary key or null if not found.
/// </summary>

13
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IRepository.cs

@ -18,19 +18,6 @@ namespace Volo.Abp.Domain.Repositories
public interface IRepository<TEntity> : IReadOnlyRepository<TEntity>, IBasicRepository<TEntity>
where TEntity : class, IEntity
{
/// <summary>
/// Deletes many entities by function.
/// Notice that: All entities fits to given predicate are retrieved and deleted.
/// This may cause major performance problems if there are too many entities with
/// given predicate.
/// </summary>
/// <param name="predicate">A condition to filter entities</param>
/// <param name="autoSave">
/// Set true to automatically save changes to database.
/// This is useful for ORMs / database APIs those only save changes with an explicit method call, but you need to immediately save changes to the database.
/// </param>
void Delete([NotNull] Expression<Func<TEntity, bool>> predicate, bool autoSave = false);
/// <summary>
/// Deletes many entities by function.
/// Notice that: All entities fits to given predicate are retrieved and deleted.

55
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs

@ -46,19 +46,7 @@ namespace Volo.Abp.Domain.Repositories
protected abstract IQueryable<TEntity> GetQueryable();
public virtual void Delete(Expression<Func<TEntity, bool>> predicate, bool autoSave = false)
{
foreach (var entity in GetQueryable().Where(predicate).ToList())
{
Delete(entity, autoSave);
}
}
public virtual Task DeleteAsync(Expression<Func<TEntity, bool>> predicate, bool autoSave = false, CancellationToken cancellationToken = default)
{
Delete(predicate, autoSave);
return Task.CompletedTask;
}
public abstract Task DeleteAsync(Expression<Func<TEntity, bool>> predicate, bool autoSave = false, CancellationToken cancellationToken = default);
protected virtual TQueryable ApplyDataFilters<TQueryable>(TQueryable query)
where TQueryable : IQueryable<TEntity>
@ -81,50 +69,19 @@ namespace Volo.Abp.Domain.Repositories
public abstract class RepositoryBase<TEntity, TKey> : RepositoryBase<TEntity>, IRepository<TEntity, TKey>
where TEntity : class, IEntity<TKey>
{
public virtual TEntity Find(TKey id, bool includeDetails = true)
{
return includeDetails
? WithDetails().FirstOrDefault(EntityHelper.CreateEqualityExpressionForId<TEntity, TKey>(id))
: GetQueryable().FirstOrDefault(EntityHelper.CreateEqualityExpressionForId<TEntity, TKey>(id));
}
public abstract Task<TEntity> GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default);
public virtual TEntity Get(TKey id, bool includeDetails = true)
{
var entity = Find(id, includeDetails);
public abstract Task<TEntity> FindAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default);
if (entity == null)
{
throw new EntityNotFoundException(typeof(TEntity), id);
}
return entity;
}
public virtual Task<TEntity> GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return Task.FromResult(Get(id, includeDetails));
}
public virtual Task<TEntity> FindAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default)
{
return Task.FromResult(Find(id, includeDetails));
}
public virtual void Delete(TKey id, bool autoSave = false)
{
var entity = Find(id, includeDetails: false);
var entity = await FindAsync(id, cancellationToken: cancellationToken);
if (entity == null)
{
return;
}
Delete(entity, autoSave);
}
public virtual Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default)
{
Delete(id, autoSave);
return Task.CompletedTask;
await DeleteAsync(entity, autoSave, cancellationToken);
}
}
}

73
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs

@ -40,18 +40,6 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
);
}
public override TEntity Insert(TEntity entity, bool autoSave = false)
{
var savedEntity = DbSet.Add(entity).Entity;
if (autoSave)
{
DbContext.SaveChanges();
}
return savedEntity;
}
public override async Task<TEntity> InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
var savedEntity = DbSet.Add(entity).Entity;
@ -64,20 +52,6 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
return savedEntity;
}
public override TEntity Update(TEntity entity, bool autoSave = false)
{
DbContext.Attach(entity);
var updatedEntity = DbContext.Update(entity).Entity;
if (autoSave)
{
DbContext.SaveChanges();
}
return updatedEntity;
}
public override async Task<TEntity> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
DbContext.Attach(entity);
@ -91,17 +65,7 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
return updatedEntity;
}
public override void Delete(TEntity entity, bool autoSave = false)
{
DbSet.Remove(entity);
if (autoSave)
{
DbContext.SaveChanges();
}
}
public override async Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
DbSet.Remove(entity);
@ -112,13 +76,6 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
}
}
public override List<TEntity> GetList(bool includeDetails = false)
{
return includeDetails
? WithDetails().ToList()
: DbSet.ToList();
}
public override async Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default)
{
return includeDetails
@ -126,11 +83,6 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
: await DbSet.ToListAsync(GetCancellationToken(cancellationToken));
}
public override long GetCount()
{
return DbSet.LongCount();
}
public override async Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{
return await DbSet.LongCountAsync(GetCancellationToken(cancellationToken));
@ -141,16 +93,6 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
return DbSet.AsQueryable();
}
public override void Delete(Expression<Func<TEntity, bool>> predicate, bool autoSave = false)
{
base.Delete(predicate, autoSave);
if (autoSave)
{
DbContext.SaveChanges();
}
}
public override async Task DeleteAsync(Expression<Func<TEntity, bool>> predicate, bool autoSave = false, CancellationToken cancellationToken = default)
{
var entities = await GetQueryable()
@ -269,20 +211,9 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
: await DbSet.FindAsync(new object[] { id }, GetCancellationToken(cancellationToken));
}
public virtual void Delete(TKey id, bool autoSave = false)
{
var entity = Find(id, includeDetails: false);
if (entity == null)
{
return;
}
Delete(entity, autoSave);
}
public virtual async Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default)
{
var entity = await FindAsync(id, includeDetails: false, cancellationToken: cancellationToken);
var entity = await FindAsync(id, cancellationToken: cancellationToken);
if (entity == null)
{
return;

42
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs

@ -22,7 +22,6 @@ using Volo.Abp.EntityFrameworkCore.ValueConverters;
using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Reflection;
using Volo.Abp.Threading;
using Volo.Abp.Timing;
namespace Volo.Abp.EntityFrameworkCore
@ -92,46 +91,7 @@ namespace Volo.Abp.EntityFrameworkCore
.Invoke(this, new object[] { modelBuilder, entityType });
}
}
public override int SaveChanges(bool acceptAllChangesOnSuccess)
{
//TODO: Reduce duplications with SaveChangesAsync
//TODO: Instead of adding entity changes to audit log, write them to uow and add to audit log only if uow succeed
try
{
var auditLog = AuditingManager?.Current?.Log;
List<EntityChangeInfo> entityChangeList = null;
if (auditLog != null)
{
entityChangeList = EntityHistoryHelper.CreateChangeList(ChangeTracker.Entries().ToList());
}
var changeReport = ApplyAbpConcepts();
var result = base.SaveChanges(acceptAllChangesOnSuccess);
AsyncHelper.RunSync(() => EntityChangeEventHelper.TriggerEventsAsync(changeReport));
if (auditLog != null)
{
EntityHistoryHelper.UpdateChangeList(entityChangeList);
auditLog.EntityChanges.AddRange(entityChangeList);
}
return result;
}
catch (DbUpdateConcurrencyException ex)
{
throw new AbpDbConcurrencyException(ex.Message, ex);
}
finally
{
ChangeTracker.AutoDetectChangesEnabled = true;
}
}
public override async Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
{
try

13
framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureInterceptor.cs

@ -2,7 +2,6 @@
using Volo.Abp.Aspects;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy;
using Volo.Abp.Threading;
namespace Volo.Abp.Features
{
@ -16,18 +15,6 @@ namespace Volo.Abp.Features
_methodInvocationFeatureCheckerService = methodInvocationFeatureCheckerService;
}
public override void Intercept(IAbpMethodInvocation invocation)
{
if (AbpCrossCuttingConcerns.IsApplied(invocation.TargetObject, AbpCrossCuttingConcerns.FeatureChecking))
{
invocation.Proceed();
return;
}
AsyncHelper.RunSync(() => CheckFeaturesAsync(invocation));
invocation.Proceed();
}
public override async Task InterceptAsync(IAbpMethodInvocation invocation)
{
if (AbpCrossCuttingConcerns.IsApplied(invocation.TargetObject, AbpCrossCuttingConcerns.FeatureChecking))

6
framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs

@ -53,7 +53,7 @@ namespace Microsoft.Extensions.DependencyInjection
foreach (var serviceType in serviceTypes)
{
services.AddHttpClientProxy(
serviceType,
serviceType,
remoteServiceConfigurationName,
asDefaultServices
);
@ -153,7 +153,7 @@ namespace Microsoft.Extensions.DependencyInjection
var interceptorType = typeof(DynamicHttpProxyInterceptor<>).MakeGenericType(type);
services.AddTransient(interceptorType);
var interceptorAdapterType = typeof(CastleAbpInterceptorAdapter<>).MakeGenericType(interceptorType);
var interceptorAdapterType = typeof(AbpAsyncDeterminationInterceptor<>).MakeGenericType(interceptorType);
if (asDefaultService)
{
@ -174,7 +174,7 @@ namespace Microsoft.Extensions.DependencyInjection
var service = ProxyGeneratorInstance
.CreateInterfaceProxyWithoutTarget(
type,
(IInterceptor) serviceProvider.GetRequiredService(interceptorAdapterType)
(IInterceptor)serviceProvider.GetRequiredService(interceptorAdapterType)
);
return Activator.CreateInstance(

45
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs

@ -74,43 +74,33 @@ namespace Volo.Abp.Http.Client.DynamicProxying
Logger = NullLogger<DynamicHttpProxyInterceptor<TService>>.Instance;
}
public override void Intercept(IAbpMethodInvocation invocation)
public override async Task InterceptAsync(IAbpMethodInvocation invocation)
{
if (invocation.Method.ReturnType == typeof(void))
if (invocation.Method.ReturnType.GenericTypeArguments.IsNullOrEmpty())
{
AsyncHelper.RunSync(() => MakeRequestAsync(invocation));
await MakeRequestAsync(invocation);
}
else
{
var responseAsString = AsyncHelper.RunSync(() => MakeRequestAsync(invocation));
var result = (Task)GenericInterceptAsyncMethod
.MakeGenericMethod(invocation.Method.ReturnType.GenericTypeArguments[0])
.Invoke(this, new object[] { invocation });
//TODO: Think on that
if (TypeHelper.IsPrimitiveExtended(invocation.Method.ReturnType, true))
{
invocation.ReturnValue = Convert.ChangeType(responseAsString, invocation.Method.ReturnType);
}
else
{
invocation.ReturnValue = JsonSerializer.Deserialize(
invocation.Method.ReturnType,
responseAsString
);
}
invocation.ReturnValue = await GetResultAsync(
result,
invocation.Method.ReturnType.GetGenericArguments()[0]
);
}
}
public override Task InterceptAsync(IAbpMethodInvocation invocation)
private async Task<object> GetResultAsync(Task task, Type resultType)
{
if (invocation.Method.ReturnType.GenericTypeArguments.IsNullOrEmpty())
{
return MakeRequestAsync(invocation);
}
invocation.ReturnValue = GenericInterceptAsyncMethod
.MakeGenericMethod(invocation.Method.ReturnType.GenericTypeArguments[0])
.Invoke(this, new object[] { invocation });
return Task.CompletedTask;
await task;
return typeof(Task<>)
.MakeGenericType(resultType)
.GetProperty(nameof(Task<object>.Result), BindingFlags.Instance | BindingFlags.Public)
.GetValue(task);
}
private async Task<T> MakeRequestAndGetResultAsync<T>(IAbpMethodInvocation invocation)
@ -163,7 +153,6 @@ namespace Volo.Abp.Http.Client.DynamicProxying
return await response.Content.ReadAsStringAsync();
}
private ApiVersionInfo GetApiVersionInfo(ActionApiDescriptionModel action)
{
var apiVersion = FindBestApiVersion(action);

79
framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Entities;
@ -25,40 +26,52 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb
DatabaseProvider = databaseProvider;
}
public override TEntity Insert(TEntity entity, bool autoSave = false)
protected override IQueryable<TEntity> GetQueryable()
{
Collection.Add(entity);
return entity;
return ApplyDataFilters(Collection.AsQueryable());
}
public override TEntity Update(TEntity entity, bool autoSave = false)
public override Task DeleteAsync(Expression<Func<TEntity, bool>> predicate, bool autoSave = false, CancellationToken cancellationToken = default)
{
Collection.Update(entity);
return entity;
var entities = Collection.AsQueryable().Where(predicate).ToList();
foreach (var entity in entities)
{
Collection.Remove(entity);
}
return Task.CompletedTask;
}
public override void Delete(TEntity entity, bool autoSave = false)
public override Task<TEntity> InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
Collection.Remove(entity);
Collection.Add(entity);
return Task.FromResult(entity);
}
public override Task<TEntity> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
Collection.Update(entity);
return Task.FromResult(entity);
}
public override List<TEntity> GetList(bool includeDetails = false)
public override Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
return Collection.ToList();
Collection.Remove(entity);
return Task.CompletedTask;
}
public override long GetCount()
public override Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default)
{
return Collection.Count();
return Task.FromResult(Collection.ToList());
}
protected override IQueryable<TEntity> GetQueryable()
public override Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{
return ApplyDataFilters(Collection.AsQueryable());
return Task.FromResult(Collection.LongCount());
}
}
public class MemoryDbRepository<TMemoryDbContext, TEntity, TKey> : MemoryDbRepository<TMemoryDbContext, TEntity>, IMemoryDbRepository<TEntity, TKey>
public class MemoryDbRepository<TMemoryDbContext, TEntity, TKey> : MemoryDbRepository<TMemoryDbContext, TEntity>, IMemoryDbRepository<TEntity, TKey>
where TMemoryDbContext : MemoryDbContext
where TEntity : class, IEntity<TKey>
{
@ -67,16 +80,16 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb
{
}
public override TEntity Insert(TEntity entity, bool autoSave = false)
public override Task<TEntity> InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
SetIdIfNeeded(entity);
return base.Insert(entity, autoSave);
return base.InsertAsync(entity, autoSave, cancellationToken);
}
protected virtual void SetIdIfNeeded(TEntity entity)
{
if (typeof(TKey) == typeof(int) ||
typeof(TKey) == typeof(long) ||
if (typeof(TKey) == typeof(int) ||
typeof(TKey) == typeof(long) ||
typeof(TKey) == typeof(Guid))
{
if (EntityHelper.HasDefaultId(entity))
@ -86,14 +99,9 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb
}
}
public virtual TEntity Find(TKey id, bool includeDetails = true)
{
return GetQueryable().FirstOrDefault(e => e.Id.Equals(id));
}
public virtual TEntity Get(TKey id, bool includeDetails = true)
public virtual async Task<TEntity> GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default)
{
var entity = Find(id, includeDetails);
var entity = await FindAsync(id, includeDetails, cancellationToken);
if (entity == null)
{
@ -103,31 +111,20 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb
return entity;
}
public virtual Task<TEntity> GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return Task.FromResult(Get(id, includeDetails));
}
public virtual Task<TEntity> FindAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return Task.FromResult(Find(id, includeDetails));
return Task.FromResult(GetQueryable().FirstOrDefault(e => e.Id.Equals(id)));
}
public virtual void Delete(TKey id, bool autoSave = false)
public virtual async Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default)
{
var entity = Find(id);
var entity = await FindAsync(id, cancellationToken: cancellationToken);
if (entity == null)
{
return;
}
Delete(entity);
}
public virtual Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default)
{
Delete(id);
return Task.CompletedTask;
await DeleteAsync(entity, autoSave, cancellationToken);
}
}
}

120
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

@ -53,20 +53,6 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
EntityChangeEventHelper = NullEntityChangeEventHelper.Instance;
}
public override TEntity Insert(TEntity entity, bool autoSave = false)
{
/* EntityCreatedEvent (OnUowCompleted) is triggered as the first because it should be
* triggered before other events triggered inside an EntityCreating event handler.
* This is also true for other "ed" & "ing" events.
*/
AsyncHelper.RunSync(() => ApplyAbpConceptsForAddedEntityAsync(entity));
Collection.InsertOne(entity);
return entity;
}
public override async Task<TEntity> InsertAsync(
TEntity entity,
bool autoSave = false,
@ -82,37 +68,6 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
return entity;
}
public override TEntity Update(TEntity entity, bool autoSave = false)
{
SetModificationAuditProperties(entity);
if (entity is ISoftDelete softDeleteEntity && softDeleteEntity.IsDeleted)
{
SetDeletionAuditProperties(entity);
AsyncHelper.RunSync(() => TriggerEntityDeleteEventsAsync(entity));
}
else
{
AsyncHelper.RunSync(() => TriggerEntityUpdateEventsAsync(entity));
}
AsyncHelper.RunSync(() => TriggerDomainEventsAsync(entity));
var oldConcurrencyStamp = SetNewConcurrencyStamp(entity);
var result = Collection.ReplaceOne(
CreateEntityFilter(entity, true, oldConcurrencyStamp),
entity
);
if (result.MatchedCount <= 0)
{
ThrowOptimisticConcurrencyException();
}
return entity;
}
public override async Task<TEntity> UpdateAsync(
TEntity entity,
bool autoSave = false,
@ -148,37 +103,6 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
return entity;
}
public override void Delete(TEntity entity, bool autoSave = false)
{
AsyncHelper.RunSync(() => ApplyAbpConceptsForDeletedEntityAsync(entity));
var oldConcurrencyStamp = SetNewConcurrencyStamp(entity);
if (entity is ISoftDelete softDeleteEntity)
{
softDeleteEntity.IsDeleted = true;
var result = Collection.ReplaceOne(
CreateEntityFilter(entity, true, oldConcurrencyStamp),
entity
);
if (result.MatchedCount <= 0)
{
ThrowOptimisticConcurrencyException();
}
}
else
{
var result = Collection.DeleteOne(
CreateEntityFilter(entity, true, oldConcurrencyStamp)
);
if (result.DeletedCount <= 0)
{
ThrowOptimisticConcurrencyException();
}
}
}
public override async Task DeleteAsync(
TEntity entity,
bool autoSave = false,
@ -215,38 +139,16 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
}
}
public override List<TEntity> GetList(bool includeDetails = false)
{
return GetMongoQueryable().ToList();
}
public override async Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().ToListAsync(GetCancellationToken(cancellationToken));
}
public override long GetCount()
{
return GetMongoQueryable().LongCount();
}
public override async Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().LongCountAsync(GetCancellationToken(cancellationToken));
}
public override void Delete(Expression<Func<TEntity, bool>> predicate, bool autoSave = false)
{
var entities = GetMongoQueryable()
.Where(predicate)
.ToList();
foreach (var entity in entities)
{
Delete(entity, autoSave);
}
}
public override async Task DeleteAsync(
Expression<Func<TEntity, bool>> predicate,
bool autoSave = false,
@ -417,18 +319,6 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
}
public virtual TEntity Get(TKey id, bool includeDetails = true)
{
var entity = Find(id, includeDetails);
if (entity == null)
{
throw new EntityNotFoundException(typeof(TEntity), id);
}
return entity;
}
public virtual async Task<TEntity> GetAsync(
TKey id,
bool includeDetails = true,
@ -454,16 +344,6 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual TEntity Find(TKey id, bool includeDetails = true)
{
return Collection.Find(CreateEntityFilter(id, true)).FirstOrDefault();
}
public virtual void Delete(TKey id, bool autoSave = false)
{
Collection.DeleteOne(CreateEntityFilter(id));
}
public virtual Task DeleteAsync(
TKey id,
bool autoSave = false,

15
framework/src/Volo.Abp.Uow/Volo/Abp/Uow/ChildUnitOfWork.cs

@ -53,31 +53,16 @@ namespace Volo.Abp.Uow
_parent.Reserve(reservationName);
}
public void SaveChanges()
{
_parent.SaveChanges();
}
public Task SaveChangesAsync(CancellationToken cancellationToken = default)
{
return _parent.SaveChangesAsync(cancellationToken);
}
public void Complete()
{
}
public Task CompleteAsync(CancellationToken cancellationToken = default)
{
return Task.CompletedTask;
}
public void Rollback()
{
_parent.Rollback();
}
public Task RollbackAsync(CancellationToken cancellationToken = default)
{
return _parent.RollbackAsync(cancellationToken);

6
framework/src/Volo.Abp.Uow/Volo/Abp/Uow/IUnitOfWork.cs

@ -32,16 +32,10 @@ namespace Volo.Abp.Uow
void Reserve([NotNull] string reservationName);
void SaveChanges();
Task SaveChangesAsync(CancellationToken cancellationToken = default);
void Complete();
Task CompleteAsync(CancellationToken cancellationToken = default);
void Rollback();
Task RollbackAsync(CancellationToken cancellationToken = default);
void OnCompleted(Func<Task> handler);

58
framework/src/Volo.Abp.Uow/Volo/Abp/Uow/UnitOfWork.cs

@ -5,7 +5,6 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Threading;
namespace Volo.Abp.Uow
{
@ -75,14 +74,6 @@ namespace Volo.Abp.Uow
Outer = outer;
}
public virtual void SaveChanges()
{
foreach (var databaseApi in GetAllActiveDatabaseApis())
{
(databaseApi as ISupportsSavingChanges)?.SaveChanges();
}
}
public virtual async Task SaveChangesAsync(CancellationToken cancellationToken = default)
{
foreach (var databaseApi in GetAllActiveDatabaseApis())
@ -104,30 +95,6 @@ namespace Volo.Abp.Uow
return _transactionApis.Values.ToImmutableList();
}
public virtual void Complete()
{
if (_isRolledback)
{
return;
}
PreventMultipleComplete();
try
{
_isCompleting = true;
SaveChanges();
CommitTransactions();
IsCompleted = true;
OnCompleted();
}
catch (Exception ex)
{
_exception = ex;
throw;
}
}
public virtual async Task CompleteAsync(CancellationToken cancellationToken = default)
{
if (_isRolledback)
@ -152,18 +119,6 @@ namespace Volo.Abp.Uow
}
}
public virtual void Rollback()
{
if (_isRolledback)
{
return;
}
_isRolledback = true;
RollbackAll();
}
public virtual async Task RollbackAsync(CancellationToken cancellationToken = default)
{
if (_isRolledback)
@ -235,19 +190,6 @@ namespace Volo.Abp.Uow
CompletedHandlers.Add(handler);
}
public void OnFailed(Func<Task> handler)
{
throw new NotImplementedException();
}
protected virtual void OnCompleted()
{
foreach (var handler in CompletedHandlers)
{
AsyncHelper.RunSync(handler);
}
}
protected virtual async Task OnCompletedAsync()
{
foreach (var handler in CompletedHandlers)

15
framework/src/Volo.Abp.Uow/Volo/Abp/Uow/UnitOfWorkInterceptor.cs

@ -18,21 +18,6 @@ namespace Volo.Abp.Uow
_defaultOptions = options.Value;
}
public override void Intercept(IAbpMethodInvocation invocation)
{
if (!UnitOfWorkHelper.IsUnitOfWorkMethod(invocation.Method, out var unitOfWorkAttribute))
{
invocation.Proceed();
return;
}
using (var uow = _unitOfWorkManager.Begin(CreateOptions(invocation, unitOfWorkAttribute)))
{
invocation.Proceed();
uow.Complete();
}
}
public override async Task InterceptAsync(IAbpMethodInvocation invocation)
{
if (!UnitOfWorkHelper.IsUnitOfWorkMethod(invocation.Method, out var unitOfWorkAttribute))

6
framework/src/Volo.Abp.Validation/Volo/Abp/Validation/ValidationInterceptor.cs

@ -13,12 +13,6 @@ namespace Volo.Abp.Validation
_methodInvocationValidator = methodInvocationValidator;
}
public override void Intercept(IAbpMethodInvocation invocation)
{
Validate(invocation);
invocation.Proceed();
}
public override async Task InterceptAsync(IAbpMethodInvocation invocation)
{
Validate(invocation);

18
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs → framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PeopleAppService_Tests.cs

@ -19,13 +19,13 @@ namespace Volo.Abp.AspNetCore.Mvc
{
//TODO: Refactor to make tests easier.
public class PersonAppService_Tests : AspNetCoreMvcTestBase
public class PeopleAppService_Tests : AspNetCoreMvcTestBase
{
private readonly IRepository<Person, Guid> _personRepository;
private readonly IJsonSerializer _jsonSerializer;
private readonly IObjectMapper _objectMapper;
public PersonAppService_Tests()
public PeopleAppService_Tests()
{
_personRepository = ServiceProvider.GetRequiredService<IRepository<Person, Guid>>();
_jsonSerializer = ServiceProvider.GetRequiredService<IJsonSerializer>();
@ -42,7 +42,7 @@ namespace Volo.Abp.AspNetCore.Mvc
[Fact]
public async Task Get_Test()
{
var firstPerson = _personRepository.First();
var firstPerson = (await _personRepository.GetListAsync()).First();
var result = await GetResponseAsObjectAsync<PersonDto>($"/api/app/people/{firstPerson.Id}");
result.Name.ShouldBe(firstPerson.Name);
@ -51,7 +51,7 @@ namespace Volo.Abp.AspNetCore.Mvc
[Fact]
public async Task Delete_Test()
{
var firstPerson = _personRepository.First();
var firstPerson = (await _personRepository.GetListAsync()).First();
await Client.DeleteAsync($"/api/app/people/{firstPerson.Id}");
@ -89,7 +89,7 @@ namespace Volo.Abp.AspNetCore.Mvc
{
//Arrange
var firstPerson = _personRepository.First();
var firstPerson = (await _personRepository.GetListAsync()).First();
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);
updateDto.Age = updateDto.Age + 1;
@ -123,7 +123,7 @@ namespace Volo.Abp.AspNetCore.Mvc
{
//Arrange
var personToAddNewPhone = _personRepository.First();
var personToAddNewPhone = (await _personRepository.GetListAsync()).First();
var phoneNumberToAdd = RandomHelper.GetRandom(1000000, 9000000).ToString();
//Act
@ -152,7 +152,7 @@ namespace Volo.Abp.AspNetCore.Mvc
[Fact]
public async Task GetPhones_Test()
{
var douglas = _personRepository.First(p => p.Name == "Douglas");
var douglas = (await _personRepository.GetListAsync()).First(p => p.Name == "Douglas");
var result = await GetResponseAsObjectAsync<ListResultDto<PhoneDto>>($"/api/app/people/{douglas.Id}/phones");
result.Items.Count.ShouldBe(douglas.Phones.Count);
@ -161,12 +161,12 @@ namespace Volo.Abp.AspNetCore.Mvc
[Fact]
public async Task DeletePhone_Test()
{
var douglas = _personRepository.First(p => p.Name == "Douglas");
var douglas = (await _personRepository.GetListAsync()).First(p => p.Name == "Douglas");
var firstPhone = douglas.Phones.First();
await Client.DeleteAsync($"/api/app/people/{douglas.Id}/phones?number={firstPhone.Number}");
douglas = _personRepository.First(p => p.Name == "Douglas");
douglas = (await _personRepository.GetListAsync()).First(p => p.Name == "Douglas");
douglas.Phones.Any(p => p.Number == firstPhone.Number).ShouldBeFalse();
}
}

6
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Uow/TestUnitOfWork.cs

@ -19,12 +19,6 @@ namespace Volo.Abp.AspNetCore.Mvc.Uow
_config = config;
}
public override void Complete()
{
ThrowExceptionIfRequested();
base.Complete();
}
public override Task CompleteAsync(CancellationToken cancellationToken = default(CancellationToken))
{
ThrowExceptionIfRequested();

1
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Uow/UnitOfWorkTestController.cs

@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Shouldly;
using Volo.Abp.UI;
using Volo.Abp.Uow;
namespace Volo.Abp.AspNetCore.Mvc.Uow

3
framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/v1/ITodoAppService.cs

@ -1,9 +1,10 @@
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
namespace Volo.Abp.AspNetCore.Mvc.Versioning.App.v1
{
public interface ITodoAppService : IApplicationService
{
string Get(int id);
Task<string> GetAsync(int id);
}
}

7
framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/v1/TodoAppService.cs

@ -1,4 +1,5 @@
using Volo.Abp.ApiVersioning;
using System.Threading.Tasks;
using Volo.Abp.ApiVersioning;
using Volo.Abp.Application.Services;
namespace Volo.Abp.AspNetCore.Mvc.Versioning.App.v1
@ -12,9 +13,9 @@ namespace Volo.Abp.AspNetCore.Mvc.Versioning.App.v1
_requestedApiVersion = requestedApiVersion;
}
public string Get(int id)
public Task<string> GetAsync(int id)
{
return $"Compat-{id}-{GetVersionOrNone()}";
return Task.FromResult($"Compat-{id}-{GetVersionOrNone()}");
}
private string GetVersionOrNone()

3
framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/v2/ITodoAppService.cs

@ -1,9 +1,10 @@
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
namespace Volo.Abp.AspNetCore.Mvc.Versioning.App.v2
{
public interface ITodoAppService : IApplicationService
{
string Get(int id);
Task<string> GetAsync(int id);
}
}

7
framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/v2/TodoAppService.cs

@ -1,4 +1,5 @@
using Volo.Abp.ApiVersioning;
using System.Threading.Tasks;
using Volo.Abp.ApiVersioning;
using Volo.Abp.Application.Services;
namespace Volo.Abp.AspNetCore.Mvc.Versioning.App.v2
@ -12,9 +13,9 @@ namespace Volo.Abp.AspNetCore.Mvc.Versioning.App.v2
_requestedApiVersion = requestedApiVersion;
}
public string Get(int id)
public Task<string> GetAsync(int id)
{
return id + "-" + GetVersionOrNone();
return Task.FromResult(id + "-" + GetVersionOrNone());
}
private string GetVersionOrNone()

7
framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Test/v1/TodoAppService_Tests.cs

@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.AspNetCore.Mvc.Versioning.App.v1;
using Xunit;
@ -15,9 +16,9 @@ namespace Volo.Abp.AspNetCore.Mvc.Versioning.Test.v1
}
[Fact]
public void Get()
public async Task GetAsync()
{
_todoAppService.Get(42).ShouldBe("Compat-42-1.0");
(await _todoAppService.GetAsync(42)).ShouldBe("Compat-42-1.0");
}
}
}

7
framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Test/v2/TodoAppService_Tests.cs

@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.AspNetCore.Mvc.Versioning.App.v2;
using Xunit;
@ -15,9 +16,9 @@ namespace Volo.Abp.AspNetCore.Mvc.Versioning.Test.v2
}
[Fact]
public void Get()
public async Task GetAsync()
{
_todoAppService.Get(42).ShouldBe("42-2.0");
(await _todoAppService.GetAsync(42)).ShouldBe("42-2.0");
}
}
}

10
framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/Authorization_Tests.cs

@ -18,11 +18,11 @@ namespace Volo.Abp.Authorization
}
[Fact]
public void Should_Not_Allow_To_Call_Method_If_Has_No_Permission_ProtectedByClass()
public async Task Should_Not_Allow_To_Call_Method_If_Has_No_Permission_ProtectedByClass()
{
Assert.Throws<AbpAuthorizationException>(() =>
await Assert.ThrowsAsync<AbpAuthorizationException>(async () =>
{
_myAuthorizedService1.ProtectedByClass();
await _myAuthorizedService1.ProtectedByClass();
});
}
@ -36,9 +36,9 @@ namespace Volo.Abp.Authorization
}
[Fact]
public void Should_Allow_To_Call_Anonymous_Method()
public async Task Should_Allow_To_Call_Anonymous_Method()
{
_myAuthorizedService1.Anonymous().ShouldBe(42);
(await _myAuthorizedService1.Anonymous()).ShouldBe(42);
}
[Fact]

4
framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/TestServices/IMyAuthorizedService1.cs

@ -4,11 +4,11 @@ namespace Volo.Abp.Authorization.TestServices
{
public interface IMyAuthorizedService1
{
int Anonymous();
Task<int> Anonymous();
Task<int> AnonymousAsync();
int ProtectedByClass();
Task<int> ProtectedByClass();
Task<int> ProtectedByClassAsync();
}

8
framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/TestServices/MyAuthorizedService1.cs

@ -8,9 +8,9 @@ namespace Volo.Abp.Authorization.TestServices
public class MyAuthorizedService1 : IMyAuthorizedService1, ITransientDependency
{
[AllowAnonymous]
public virtual int Anonymous()
public virtual Task<int> Anonymous()
{
return 42;
return Task.FromResult(42);
}
[AllowAnonymous]
@ -20,9 +20,9 @@ namespace Volo.Abp.Authorization.TestServices
return 42;
}
public virtual int ProtectedByClass()
public virtual Task<int> ProtectedByClass()
{
return 42;
return Task.FromResult(42);
}
public virtual async Task<int> ProtectedByClassAsync()

94
framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/AbpInterceptionTestBase.cs

@ -12,7 +12,6 @@ namespace Volo.Abp.DynamicProxy
protected override void BeforeAddApplication(IServiceCollection services)
{
services.AddTransient<SimpleAsyncInterceptor>();
services.AddTransient<SimpleSyncInterceptor>();
services.AddTransient<SimpleAsyncInterceptor2>();
services.AddTransient<SimpleInterceptionTargetClass>();
@ -24,7 +23,6 @@ namespace Volo.Abp.DynamicProxy
if (typeof(SimpleInterceptionTargetClass) == registration.ImplementationType)
{
registration.Interceptors.Add<SimpleAsyncInterceptor>();
registration.Interceptors.Add<SimpleSyncInterceptor>();
registration.Interceptors.Add<SimpleAsyncInterceptor2>();
}
@ -48,16 +46,14 @@ namespace Volo.Abp.DynamicProxy
//Assert
target.Logs.Count.ShouldBe(9);
target.Logs.Count.ShouldBe(7);
target.Logs[0].ShouldBe("SimpleAsyncInterceptor_InterceptAsync_BeforeInvocation");
target.Logs[1].ShouldBe("SimpleSyncInterceptor_Intercept_BeforeInvocation");
target.Logs[2].ShouldBe("SimpleAsyncInterceptor2_InterceptAsync_BeforeInvocation");
target.Logs[3].ShouldBe("EnterDoItAsync");
target.Logs[4].ShouldBe("MiddleDoItAsync");
target.Logs[5].ShouldBe("ExitDoItAsync");
target.Logs[6].ShouldBe("SimpleAsyncInterceptor2_InterceptAsync_AfterInvocation");
target.Logs[7].ShouldBe("SimpleSyncInterceptor_Intercept_AfterInvocation");
target.Logs[8].ShouldBe("SimpleAsyncInterceptor_InterceptAsync_AfterInvocation");
target.Logs[1].ShouldBe("SimpleAsyncInterceptor2_InterceptAsync_BeforeInvocation");
target.Logs[2].ShouldBe("EnterDoItAsync");
target.Logs[3].ShouldBe("MiddleDoItAsync");
target.Logs[4].ShouldBe("ExitDoItAsync");
target.Logs[5].ShouldBe("SimpleAsyncInterceptor2_InterceptAsync_AfterInvocation");
target.Logs[6].ShouldBe("SimpleAsyncInterceptor_InterceptAsync_AfterInvocation");
}
[Fact]
@ -73,77 +69,15 @@ namespace Volo.Abp.DynamicProxy
//Assert
result.ShouldBe(42);
target.Logs.Count.ShouldBe(9);
target.Logs[0].ShouldBe("SimpleAsyncInterceptor_InterceptAsync_BeforeInvocation");
target.Logs[1].ShouldBe("SimpleSyncInterceptor_Intercept_BeforeInvocation");
target.Logs[2].ShouldBe("SimpleAsyncInterceptor2_InterceptAsync_BeforeInvocation");
target.Logs[3].ShouldBe("EnterGetValueAsync");
target.Logs[4].ShouldBe("MiddleGetValueAsync");
target.Logs[5].ShouldBe("ExitGetValueAsync");
target.Logs[6].ShouldBe("SimpleAsyncInterceptor2_InterceptAsync_AfterInvocation");
target.Logs[7].ShouldBe("SimpleSyncInterceptor_Intercept_AfterInvocation");
target.Logs[8].ShouldBe("SimpleAsyncInterceptor_InterceptAsync_AfterInvocation");
}
[Fact]
public void Should_Intercept_Sync_Method_Without_Return_Value()
{
//Arrange
var target = ServiceProvider.GetService<SimpleInterceptionTargetClass>();
//Act
target.DoIt();
//Assert
target.Logs.Count.ShouldBe(7);
target.Logs[0].ShouldBe("SimpleAsyncInterceptor_Intercept_BeforeInvocation");
target.Logs[1].ShouldBe("SimpleSyncInterceptor_Intercept_BeforeInvocation");
target.Logs[2].ShouldBe("SimpleAsyncInterceptor2_Intercept_BeforeInvocation");
target.Logs[3].ShouldBe("ExecutingDoIt");
target.Logs[4].ShouldBe("SimpleAsyncInterceptor2_Intercept_AfterInvocation");
target.Logs[5].ShouldBe("SimpleSyncInterceptor_Intercept_AfterInvocation");
target.Logs[6].ShouldBe("SimpleAsyncInterceptor_Intercept_AfterInvocation");
}
[Fact]
public void Should_Intercept_Sync_Method_With_Return_Value()
{
//Arrange
var target = ServiceProvider.GetService<SimpleInterceptionTargetClass>();
//Act
var result = target.GetValue();
//Assert
result.ShouldBe(42);
target.Logs.Count.ShouldBe(7);
target.Logs[0].ShouldBe("SimpleAsyncInterceptor_Intercept_BeforeInvocation");
target.Logs[1].ShouldBe("SimpleSyncInterceptor_Intercept_BeforeInvocation");
target.Logs[2].ShouldBe("SimpleAsyncInterceptor2_Intercept_BeforeInvocation");
target.Logs[3].ShouldBe("ExecutingGetValue");
target.Logs[4].ShouldBe("SimpleAsyncInterceptor2_Intercept_AfterInvocation");
target.Logs[5].ShouldBe("SimpleSyncInterceptor_Intercept_AfterInvocation");
target.Logs[6].ShouldBe("SimpleAsyncInterceptor_Intercept_AfterInvocation");
}
[Fact]
public void Should_Cache_Results()
{
//Arrange
var target = ServiceProvider.GetService<CachedTestObject>();
//Act & Assert
target.GetValue(42).ShouldBe(42); //First run, not cached yet
target.GetValue(43).ShouldBe(42); //First run, cached previous value
target.GetValue(44).ShouldBe(42); //First run, cached previous value
target.Logs[0].ShouldBe("SimpleAsyncInterceptor_InterceptAsync_BeforeInvocation");
target.Logs[1].ShouldBe("SimpleAsyncInterceptor2_InterceptAsync_BeforeInvocation");
target.Logs[2].ShouldBe("EnterGetValueAsync");
target.Logs[3].ShouldBe("MiddleGetValueAsync");
target.Logs[4].ShouldBe("ExitGetValueAsync");
target.Logs[5].ShouldBe("SimpleAsyncInterceptor2_InterceptAsync_AfterInvocation");
target.Logs[6].ShouldBe("SimpleAsyncInterceptor_InterceptAsync_AfterInvocation");
}
[Fact]

9
framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/SimpleAsyncInterceptor.cs

@ -5,14 +5,7 @@ namespace Volo.Abp.DynamicProxy
{
public class SimpleAsyncInterceptor : AbpInterceptor
{
public override void Intercept(IAbpMethodInvocation invocation)
{
(invocation.TargetObject as ICanLogOnObject)?.Logs?.Add($"{GetType().Name}_Intercept_BeforeInvocation");
invocation.ProceedAsync();
(invocation.TargetObject as ICanLogOnObject)?.Logs?.Add($"{GetType().Name}_Intercept_AfterInvocation");
}
public override async Task InterceptAsync(IAbpMethodInvocation invocation)
public override async Task InterceptAsync(IAbpMethodInvocation invocation)
{
await Task.Delay(5);
(invocation.TargetObject as ICanLogOnObject)?.Logs?.Add($"{GetType().Name}_InterceptAsync_BeforeInvocation");

11
framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/SimpleResultCacheTestInterceptor.cs

@ -12,16 +12,7 @@ namespace Volo.Abp.DynamicProxy
{
_cache = new ConcurrentDictionary<MethodInfo, object>();
}
public override void Intercept(IAbpMethodInvocation invocation)
{
invocation.ReturnValue = _cache.GetOrAdd(invocation.Method, m =>
{
invocation.Proceed();
return invocation.ReturnValue;
});
}
public override async Task InterceptAsync(IAbpMethodInvocation invocation)
{
if (_cache.ContainsKey(invocation.Method))

14
framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/SimpleSyncInterceptor.cs

@ -1,14 +0,0 @@
using Volo.Abp.TestBase.Logging;
namespace Volo.Abp.DynamicProxy
{
public class SimpleSyncInterceptor : AbpInterceptor
{
public override void Intercept(IAbpMethodInvocation invocation)
{
(invocation.TargetObject as ICanLogOnObject)?.Logs?.Add($"{GetType().Name}_Intercept_BeforeInvocation");
invocation.Proceed();
(invocation.TargetObject as ICanLogOnObject)?.Logs?.Add($"{GetType().Name}_Intercept_AfterInvocation");
}
}
}

34
framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
@ -239,51 +240,47 @@ namespace Volo.Abp.Domain.Repositories
public class MyTestDefaultRepository<TEntity> : RepositoryBase<TEntity>
where TEntity : class, IEntity
{
public override TEntity Insert(TEntity entity, bool autoSave = false)
{
throw new NotImplementedException();
}
public override TEntity Update(TEntity entity, bool autoSave = false)
protected override IQueryable<TEntity> GetQueryable()
{
throw new NotImplementedException();
}
public override void Delete(TEntity entity, bool autoSave = false)
public override Task DeleteAsync(Expression<Func<TEntity, bool>> predicate, bool autoSave = false, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public override List<TEntity> GetList(bool includeDetails = false)
public override Task<TEntity> InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public override long GetCount()
public override Task<TEntity> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
protected override IQueryable<TEntity> GetQueryable()
public override Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
}
public class MyTestDefaultRepository<TEntity, TKey> : MyTestDefaultRepository<TEntity>, IRepository<TEntity, TKey>
where TEntity : class, IEntity<TKey>
{
public TEntity Get(TKey id, bool includeDetails = true)
public override Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public Task<TEntity> GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default)
public override Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
}
public TEntity Find(TKey id, bool includeDetails = true)
public class MyTestDefaultRepository<TEntity, TKey> : MyTestDefaultRepository<TEntity>, IRepository<TEntity, TKey>
where TEntity : class, IEntity<TKey>
{
public Task<TEntity> GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
@ -293,11 +290,6 @@ namespace Volo.Abp.Domain.Repositories
throw new NotImplementedException();
}
public void Delete(TKey id, bool autoSave = false)
{
throw new NotImplementedException();
}
public Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();

5
framework/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/AbpEfCoreTestSecondContextModule.cs

@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EntityFrameworkCore.TestApp.ThirdDbContext;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
namespace Volo.Abp.EntityFrameworkCore.TestApp.SecondContext
{
@ -29,9 +30,9 @@ namespace Volo.Abp.EntityFrameworkCore.TestApp.SecondContext
{
using (var scope = context.ServiceProvider.CreateScope())
{
scope.ServiceProvider
AsyncHelper.RunSync(() => scope.ServiceProvider
.GetRequiredService<SecondContextTestDataBuilder>()
.Build();
.BuildAsync());
}
}
}

5
framework/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/SecondContextTestDataBuilder.cs

@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Guids;
@ -16,9 +17,9 @@ namespace Volo.Abp.EntityFrameworkCore.TestApp.SecondContext
_guidGenerator = guidGenerator;
}
public void Build()
public async Task BuildAsync()
{
_bookRepository.Insert(
await _bookRepository.InsertAsync(
new BookInSecondDbContext(
_guidGenerator.Create(),
"TestBook1"

15
framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DbContext_Replace_Tests.cs

@ -1,9 +1,11 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.EntityFrameworkCore.TestApp.ThirdDbContext;
using Volo.Abp.TestApp.EntityFrameworkCore;
using Volo.Abp.Uow;
using Xunit;
namespace Volo.Abp.EntityFrameworkCore
@ -11,19 +13,26 @@ namespace Volo.Abp.EntityFrameworkCore
public class DbContext_Replace_Tests : EntityFrameworkCoreTestBase
{
private readonly IBasicRepository<ThirdDbContextDummyEntity, Guid> _dummyRepository;
private readonly IUnitOfWorkManager _unitOfWorkManager;
public DbContext_Replace_Tests()
{
_dummyRepository = ServiceProvider.GetRequiredService<IBasicRepository<ThirdDbContextDummyEntity, Guid>>();
_unitOfWorkManager = ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
}
[Fact]
public void Should_Replace_DbContext()
public async Task Should_Replace_DbContext()
{
(ServiceProvider.GetRequiredService<IThirdDbContext>() is TestAppDbContext).ShouldBeTrue();
(_dummyRepository.GetDbContext() is IThirdDbContext).ShouldBeTrue();
(_dummyRepository.GetDbContext() is TestAppDbContext).ShouldBeTrue();
using (_unitOfWorkManager.Begin())
{
(_dummyRepository.GetDbContext() is IThirdDbContext).ShouldBeTrue();
(_dummyRepository.GetDbContext() is TestAppDbContext).ShouldBeTrue();
await _unitOfWorkManager.Current.CompleteAsync();
}
}
}
}

16
framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Queryable_Tests.cs

@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
@ -23,31 +24,34 @@ namespace Volo.Abp.EntityFrameworkCore.Repositories
}
[Fact]
public void GetBookList()
public async Task GetBookList()
{
WithUnitOfWork(() =>
await WithUnitOfWorkAsync(() =>
{
_bookRepository.Any().ShouldBeTrue();
return Task.CompletedTask;
});
}
[Fact]
public void GetPhoneInSecondDbContextList()
public async Task GetPhoneInSecondDbContextList()
{
WithUnitOfWork(() =>
await WithUnitOfWorkAsync(() =>
{
_phoneInSecondDbContextRepository.Any().ShouldBeTrue();
return Task.CompletedTask;
});
}
[Fact]
public void EfCore_Include_Extension()
public async Task EfCore_Include_Extension()
{
WithUnitOfWork(() =>
await WithUnitOfWorkAsync(() =>
{
var person = PersonRepository.Include(p => p.Phones).Single(p => p.Id == TestDataBuilder.UserDouglasId);
person.Name.ShouldBe("Douglas");
person.Phones.Count.ShouldBe(2);
return Task.CompletedTask;
});
}
}

11
framework/test/Volo.Abp.Features.Tests/Volo/Abp/Features/ClassFeatureTestService.cs

@ -1,4 +1,5 @@
using Volo.Abp.DependencyInjection;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Features
{
@ -10,14 +11,14 @@ namespace Volo.Abp.Features
*/
[RequiresFeature("BooleanTestFeature2")]
public virtual int Feature2()
public virtual Task<int> Feature2Async()
{
return 42;
return Task.FromResult(42);
}
public virtual void NoAdditionalFeature()
public virtual Task NoAdditionalFeatureAsync()
{
return Task.CompletedTask;
}
}
}

12
framework/test/Volo.Abp.Features.Tests/Volo/Abp/Features/FeatureInterceptor_Tests.cs

@ -27,14 +27,14 @@ namespace Volo.Abp.Features
{
using (_currentTenant.Change(ParseNullableGuid(tenantIdValue)))
{
Assert.Throws<AbpAuthorizationException>(() =>
await Assert.ThrowsAsync<AbpAuthorizationException>(async () =>
{
_classFeatureTestService.NoAdditionalFeature();
await _classFeatureTestService.NoAdditionalFeatureAsync();
});
Assert.Throws<AbpAuthorizationException>(() =>
await Assert.ThrowsAsync<AbpAuthorizationException>(async () =>
{
_classFeatureTestService.Feature2();
await _classFeatureTestService.Feature2Async();
});
await Assert.ThrowsAsync<AbpAuthorizationException>(async () =>
@ -50,8 +50,8 @@ namespace Volo.Abp.Features
//Features were enabled for Tenant 1
using (_currentTenant.Change(TestFeatureStore.Tenant1Id))
{
_classFeatureTestService.NoAdditionalFeature();
_classFeatureTestService.Feature2().ShouldBe(42);
await _classFeatureTestService.NoAdditionalFeatureAsync();
(await _classFeatureTestService.Feature2Async()).ShouldBe(42);
(await _methodFeatureTestService.Feature1Async()).ShouldBe(42);
}
}

45
framework/test/Volo.Abp.FluentValidation.Tests/Volo/Abp/FluentValidation/ApplicationService_FluentValidation_Tests.cs

@ -27,21 +27,6 @@ namespace Volo.Abp.FluentValidation
[Fact]
public async Task Should_Work_Proper_With_Right_Inputs()
{
// MyStringValue should be aaa, MyStringValue2 should be bbb. MyStringValue3 should be ccc
var output = _myAppService.MyMethod(new MyMethodInput
{
MyStringValue = "aaa",
MyMethodInput2 = new MyMethodInput2
{
MyStringValue2 = "bbb"
},
MyMethodInput3 = new MyMethodInput3
{
MyStringValue3 = "ccc"
}
});
output.ShouldBe("aaabbbccc");
var asyncOutput = await _myAppService.MyMethodAsync(new MyMethodInput
{
MyStringValue = "aaa",
@ -63,19 +48,6 @@ namespace Volo.Abp.FluentValidation
{
// MyStringValue should be aaa, MyStringValue2 should be bbb. MyStringValue3 should be ccc
Assert.Throws<AbpValidationException>(() => _myAppService.MyMethod(new MyMethodInput
{
MyStringValue = "a",
MyMethodInput2 = new MyMethodInput2
{
MyStringValue2 = "b"
},
MyMethodInput3 = new MyMethodInput3
{
MyStringValue3 = "c"
}
}));
await Assert.ThrowsAsync<AbpValidationException>(async () => await _myAppService.MyMethodAsync(
new MyMethodInput
{
@ -92,9 +64,9 @@ namespace Volo.Abp.FluentValidation
}
[Fact]
public void NotValidateMyMethod_Test()
public async Task NotValidateMyMethod_Test()
{
var output = _myAppService.NotValidateMyMethod(new MyMethodInput4
var output = await _myAppService.NotValidateMyMethod(new MyMethodInput4
{
MyStringValue4 = "444"
});
@ -125,29 +97,22 @@ namespace Volo.Abp.FluentValidation
public interface IMyAppService
{
string MyMethod(MyMethodInput input);
Task<string> MyMethodAsync(MyMethodInput input);
string NotValidateMyMethod(MyMethodInput4 input);
Task<string> NotValidateMyMethod(MyMethodInput4 input);
}
public class MyAppService : IMyAppService, ITransientDependency
{
public string MyMethod(MyMethodInput input)
{
return input.MyStringValue + input.MyMethodInput2.MyStringValue2 + input.MyMethodInput3.MyStringValue3;
}
public Task<string> MyMethodAsync(MyMethodInput input)
{
return Task.FromResult(input.MyStringValue + input.MyMethodInput2.MyStringValue2 +
input.MyMethodInput3.MyStringValue3);
}
public string NotValidateMyMethod(MyMethodInput4 input)
public Task<string> NotValidateMyMethod(MyMethodInput4 input)
{
return input.MyStringValue4;
return Task.FromResult(input.MyStringValue4);
}
}

2
framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/IRegularTestController.cs

@ -4,8 +4,6 @@ namespace Volo.Abp.Http.DynamicProxying
{
public interface IRegularTestController
{
int IncrementValue(int value);
Task<int> IncrementValueAsync(int value);
Task GetException1Async();

12
framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs

@ -27,7 +27,7 @@ namespace Volo.Abp.Http.DynamicProxying
[Fact]
public async Task Get()
{
var firstPerson = _personRepository.First();
var firstPerson = (await _personRepository.GetListAsync()).First();
var person = await _peopleAppService.GetAsync(firstPerson.Id);
person.ShouldNotBeNull();
@ -46,11 +46,11 @@ namespace Volo.Abp.Http.DynamicProxying
[Fact]
public async Task Delete()
{
var firstPerson = _personRepository.First();
var firstPerson = (await _personRepository.GetListAsync()).First();
await _peopleAppService.DeleteAsync(firstPerson.Id);
firstPerson = _personRepository.FirstOrDefault(p => p.Id == firstPerson.Id);
firstPerson = (await _personRepository.GetListAsync()).FirstOrDefault(p => p.Id == firstPerson.Id);
firstPerson.ShouldBeNull();
}
@ -70,7 +70,7 @@ namespace Volo.Abp.Http.DynamicProxying
person.Id.ShouldNotBe(Guid.Empty);
person.Name.ShouldBe(uniquePersonName);
var personInDb = _personRepository.FirstOrDefault(p => p.Name == uniquePersonName);
var personInDb = (await _personRepository.GetListAsync()).FirstOrDefault(p => p.Name == uniquePersonName);
personInDb.ShouldNotBeNull();
personInDb.Id.ShouldBe(person.Id);
}
@ -78,7 +78,7 @@ namespace Volo.Abp.Http.DynamicProxying
[Fact]
public async Task Update()
{
var firstPerson = _personRepository.First();
var firstPerson = (await _personRepository.GetListAsync()).First();
var uniquePersonName = Guid.NewGuid().ToString();
var person = await _peopleAppService.UpdateAsync(
@ -96,7 +96,7 @@ namespace Volo.Abp.Http.DynamicProxying
person.Name.ShouldBe(uniquePersonName);
person.Age.ShouldBe(firstPerson.Age);
var personInDb = _personRepository.FirstOrDefault(p => p.Id == firstPerson.Id);
var personInDb = (await _personRepository.GetListAsync()).FirstOrDefault(p => p.Id == firstPerson.Id);
personInDb.ShouldNotBeNull();
personInDb.Id.ShouldBe(person.Id);
personInDb.Name.ShouldBe(person.Name);

7
framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestController.cs

@ -11,13 +11,6 @@ namespace Volo.Abp.Http.DynamicProxying
//[ApiExplorerSettings(IgnoreApi = false)] //alternative
public class RegularTestController : AbpController, IRegularTestController
{
[HttpGet]
[Route("increment/{value}")] //full URL: .../api/regular-test-controller/increment/{value}
public int IncrementValue(int value)
{
return value + 1;
}
[HttpGet]
[Route("increment")]
public Task<int> IncrementValueAsync(int value)

6
framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestControllerClientProxy_Tests.cs

@ -17,12 +17,6 @@ namespace Volo.Abp.Http.DynamicProxying
_controller = ServiceProvider.GetRequiredService<IRegularTestController>();
}
[Fact]
public void IncrementValue()
{
_controller.IncrementValue(42).ShouldBe(43);
}
[Fact]
public async Task IncrementValueAsync()
{

11
framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests.cs

@ -12,11 +12,14 @@ namespace Volo.Abp.MongoDB.Repositories
public class Repository_Basic_Tests : Repository_Basic_Tests<AbpMongoDbTestModule>
{
[Fact]
public void Linq_Queries()
public async Task Linq_Queries()
{
PersonRepository.FirstOrDefault(p => p.Name == "Douglas").ShouldNotBeNull();
PersonRepository.Count().ShouldBeGreaterThan(0);
await WithUnitOfWorkAsync(() =>
{
PersonRepository.FirstOrDefault(p => p.Name == "Douglas").ShouldNotBeNull();
PersonRepository.Count().ShouldBeGreaterThan(0);
return Task.CompletedTask;
});
}
[Fact]

7
framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests_With_Int_Pk.cs

@ -1,4 +1,5 @@
using Volo.Abp.TestApp.Testing;
using System.Threading.Tasks;
using Volo.Abp.TestApp.Testing;
using Xunit;
namespace Volo.Abp.MongoDB.Repositories
@ -6,9 +7,9 @@ namespace Volo.Abp.MongoDB.Repositories
public class Repository_Basic_Tests_With_Int_Pk : Repository_Basic_Tests_With_Int_Pk<AbpMongoDbTestModule>
{
[Fact(Skip = "Int PKs are not working for MongoDb")]
public override void Get()
public override Task Get()
{
return Task.CompletedTask;
}
}
}

6
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs

@ -13,7 +13,7 @@ namespace Volo.Abp.TestApp.Application
{
public class PeopleAppService : CrudAppService<Person, PersonDto, Guid>, IPeopleAppService
{
public PeopleAppService(IRepository<Person, Guid> repository)
public PeopleAppService(IRepository<Person, Guid> repository)
: base(repository)
{
@ -36,7 +36,7 @@ namespace Volo.Abp.TestApp.Application
var phone = new Phone(person.Id, phoneDto.Number, phoneDto.Type);
person.Phones.Add(phone);
Repository.Update(person);
await Repository.UpdateAsync(person);
return ObjectMapper.Map<Phone, PhoneDto>(phone);
}
@ -44,7 +44,7 @@ namespace Volo.Abp.TestApp.Application
{
var person = await GetEntityByIdAsync(id);
person.Phones.RemoveAll(p => p.Number == number);
Repository.Update(person);
await Repository.UpdateAsync(person);
}
[Authorize]

5
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestAppModule.cs

@ -6,6 +6,7 @@ using Volo.Abp.TestApp.Domain;
using Volo.Abp.AutoMapper;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.TestApp.Application.Dto;
using Volo.Abp.Threading;
namespace Volo.Abp.TestApp
{
@ -54,9 +55,9 @@ namespace Volo.Abp.TestApp
{
using (var scope = context.ServiceProvider.CreateScope())
{
scope.ServiceProvider
AsyncHelper.RunSync(() => scope.ServiceProvider
.GetRequiredService<TestDataBuilder>()
.Build();
.BuildAsync());
}
}
}

47
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs

@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.TestApp.Domain;
@ -29,53 +30,53 @@ namespace Volo.Abp.TestApp
_entityWithIntPksRepository = entityWithIntPksRepository;
}
public void Build()
public async Task BuildAsync()
{
AddCities();
AddPeople();
AddEntitiesWithPks();
await AddCities();
await AddPeople();
await AddEntitiesWithPks();
}
private void AddCities()
private async Task AddCities()
{
var istanbul = new City(IstanbulCityId, "Istanbul");
istanbul.Districts.Add(new District(istanbul.Id, "Bakirkoy", 1283999));
istanbul.Districts.Add(new District(istanbul.Id, "Mecidiyeköy", 2222321));
istanbul.Districts.Add(new District(istanbul.Id, "Uskudar", 726172));
_cityRepository.Insert(new City(Guid.NewGuid(), "Tokyo"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Madrid"));
_cityRepository.Insert(new City(LondonCityId, "London") {ExtraProperties = { { "Population", 10_470_000 } } });
_cityRepository.Insert(istanbul);
_cityRepository.Insert(new City(Guid.NewGuid(), "Paris"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Washington"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Sao Paulo"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Berlin"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Amsterdam"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Beijing"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Rome"));
await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Tokyo"));
await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Madrid"));
await _cityRepository.InsertAsync(new City(LondonCityId, "London") {ExtraProperties = { { "Population", 10_470_000 } } });
await _cityRepository.InsertAsync(istanbul);
await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Paris"));
await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Washington"));
await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Sao Paulo"));
await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Berlin"));
await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Amsterdam"));
await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Beijing"));
await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Rome"));
}
private void AddPeople()
private async Task AddPeople()
{
var douglas = new Person(UserDouglasId, "Douglas", 42, cityId: LondonCityId);
douglas.Phones.Add(new Phone(douglas.Id, "123456789"));
douglas.Phones.Add(new Phone(douglas.Id, "123456780", PhoneType.Home));
_personRepository.Insert(douglas);
await _personRepository.InsertAsync(douglas);
_personRepository.Insert(new Person(UserJohnDeletedId, "John-Deleted", 33) { IsDeleted = true });
await _personRepository.InsertAsync(new Person(UserJohnDeletedId, "John-Deleted", 33) { IsDeleted = true });
var tenant1Person1 = new Person(Guid.NewGuid(), TenantId1 + "-Person1", 42, TenantId1);
var tenant1Person2 = new Person(Guid.NewGuid(), TenantId1 + "-Person2", 43, TenantId1);
_personRepository.Insert(tenant1Person1);
_personRepository.Insert(tenant1Person2);
await _personRepository.InsertAsync(tenant1Person1);
await _personRepository.InsertAsync(tenant1Person2);
}
private void AddEntitiesWithPks()
private async Task AddEntitiesWithPks()
{
_entityWithIntPksRepository.Insert(new EntityWithIntPk("Entity1"));
await _entityWithIntPksRepository.InsertAsync(new EntityWithIntPk("Entity1"));
}
}
}

6
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs

@ -28,7 +28,7 @@ namespace Volo.Abp.TestApp.Testing
}
[Fact]
public void Complex_Event_Test()
public async Task Complex_Event_Test()
{
var personName = Guid.NewGuid().ToString("N");
@ -75,9 +75,9 @@ namespace Volo.Abp.TestApp.Testing
return Task.CompletedTask;
});
PersonRepository.Insert(new Person(Guid.NewGuid(), personName, 15));
await PersonRepository.InsertAsync(new Person(Guid.NewGuid(), personName, 15));
uow.Complete();
await uow.CompleteAsync();
}
creatingEventTriggered.ShouldBeTrue();

13
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/MultiTenant_Filter_Tests.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using Shouldly;
@ -33,9 +34,9 @@ namespace Volo.Abp.TestApp.Testing
}
[Fact]
public void Should_Get_Person_For_Current_Tenant()
public async Task Should_Get_Person_For_Current_Tenant()
{
WithUnitOfWork(() =>
await WithUnitOfWorkAsync(() =>
{
//TenantId = null
@ -60,13 +61,15 @@ namespace Volo.Abp.TestApp.Testing
people = _personRepository.ToList();
people.Count.ShouldBe(0);
return Task.CompletedTask;
});
}
[Fact]
public void Should_Get_All_People_When_MultiTenant_Filter_Is_Disabled()
public async Task Should_Get_All_People_When_MultiTenant_Filter_Is_Disabled()
{
WithUnitOfWork(() =>
await WithUnitOfWorkAsync(() =>
{
List<Person> people;
@ -80,6 +83,8 @@ namespace Volo.Abp.TestApp.Testing
//Filter re-enabled automatically
people = _personRepository.ToList();
people.Count.ShouldBe(1);
return Task.CompletedTask;
});
}
}

12
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Basic_Tests_With_Int_Pk.cs

@ -1,4 +1,5 @@
using System.Linq;
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Modularity;
@ -18,22 +19,23 @@ namespace Volo.Abp.TestApp.Testing
}
[Fact]
public virtual void FirstOrDefault()
public virtual async Task FirstOrDefault()
{
WithUnitOfWork(() =>
await WithUnitOfWorkAsync(() =>
{
var entity = EntityWithIntPkRepository.FirstOrDefault(e => e.Name == "Entity1");
entity.ShouldNotBeNull();
entity.Name.ShouldBe("Entity1");
return Task.CompletedTask;
});
}
[Fact]
public virtual void Get()
public virtual async Task Get()
{
WithUnitOfWork(() =>
await WithUnitOfWorkAsync(async () =>
{
var entity = EntityWithIntPkRepository.Get(1);
var entity = await EntityWithIntPkRepository.GetAsync(1);
entity.ShouldNotBeNull();
entity.Name.ShouldBe("Entity1");
});

21
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Queryable_Tests.cs

@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Domain.Repositories;
@ -20,43 +21,47 @@ namespace Volo.Abp.TestApp.Testing
}
[Fact]
public void Any()
public async Task Any()
{
WithUnitOfWork(() =>
await WithUnitOfWorkAsync(() =>
{
PersonRepository.Any().ShouldBeTrue();
return Task.CompletedTask;
});
}
[Fact]
public void Single()
public async Task Single()
{
WithUnitOfWork(() =>
await WithUnitOfWorkAsync(() =>
{
var person = PersonRepository.Single(p => p.Id == TestDataBuilder.UserDouglasId);
person.Name.ShouldBe("Douglas");
return Task.CompletedTask;
});
}
[Fact]
public void WithDetails()
public async Task WithDetails()
{
WithUnitOfWork(() =>
await WithUnitOfWorkAsync(() =>
{
var person = PersonRepository.WithDetails().Single(p => p.Id == TestDataBuilder.UserDouglasId);
person.Name.ShouldBe("Douglas");
person.Phones.Count.ShouldBe(2);
return Task.CompletedTask;
});
}
[Fact]
public void WithDetails_Explicit()
public async Task WithDetails_Explicit()
{
WithUnitOfWork(() =>
await WithUnitOfWorkAsync(() =>
{
var person = PersonRepository.WithDetails(p => p.Phones).Single(p => p.Id == TestDataBuilder.UserDouglasId);
person.Name.ShouldBe("Douglas");
person.Phones.Count.ShouldBe(2);
return Task.CompletedTask;
});
}
}

6
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Specifications_Tests.cs

@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Modularity;
@ -21,11 +22,12 @@ namespace Volo.Abp.TestApp.Testing
}
[Fact]
public void SpecificationWithRepository_Test()
public async Task SpecificationWithRepository_Test()
{
WithUnitOfWork(() =>
await WithUnitOfWorkAsync(() =>
{
CityRepository.Count(new CitySpecification().ToExpression()).ShouldBe(1);
return Task.CompletedTask;
});
}
}

16
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/SoftDelete_Filter_Tests.cs

@ -23,12 +23,13 @@ namespace Volo.Abp.TestApp.Testing
}
[Fact]
public void Should_Not_Get_Deleted_Entities_Linq()
public async Task Should_Not_Get_Deleted_Entities_Linq()
{
WithUnitOfWork(() =>
await WithUnitOfWorkAsync(() =>
{
var person = PersonRepository.FirstOrDefault(p => p.Name == "John-Deleted");
person.ShouldBeNull();
return Task.CompletedTask;
});
}
@ -43,20 +44,21 @@ namespace Volo.Abp.TestApp.Testing
}
[Fact]
public void Should_Not_Get_Deleted_Entities_By_Default_ToList()
public async Task Should_Not_Get_Deleted_Entities_By_Default_ToList()
{
WithUnitOfWork(() =>
await WithUnitOfWorkAsync(() =>
{
var people = PersonRepository.ToList();
people.Count.ShouldBe(1);
people.Any(p => p.Name == "Douglas").ShouldBeTrue();
return Task.CompletedTask;
});
}
[Fact]
public void Should_Get_Deleted_Entities_When_Filter_Is_Disabled()
public async Task Should_Get_Deleted_Entities_When_Filter_Is_Disabled()
{
WithUnitOfWork(() =>
await WithUnitOfWorkAsync(() =>
{
//Soft delete is enabled by default
var people = PersonRepository.ToList();
@ -88,6 +90,8 @@ namespace Volo.Abp.TestApp.Testing
people = PersonRepository.ToList();
people.Any(p => !p.IsDeleted).ShouldBeTrue();
people.Any(p => p.IsDeleted).ShouldBeFalse();
return Task.CompletedTask;
});
}
}

40
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/TestAppTestBase.cs

@ -16,26 +16,6 @@ namespace Volo.Abp.TestApp.Testing
#region WithUnitOfWork
protected virtual void WithUnitOfWork(Action action)
{
WithUnitOfWork(new AbpUnitOfWorkOptions(), action);
}
protected virtual void WithUnitOfWork(AbpUnitOfWorkOptions options, Action action)
{
using (var scope = ServiceProvider.CreateScope())
{
var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
using (var uow = uowManager.Begin(options))
{
action();
uow.Complete();
}
}
}
protected virtual Task WithUnitOfWorkAsync(Func<Task> func)
{
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);
@ -56,26 +36,6 @@ namespace Volo.Abp.TestApp.Testing
}
}
protected virtual TResult WithUnitOfWork<TResult>(Func<TResult> func)
{
return WithUnitOfWork(new AbpUnitOfWorkOptions(), func);
}
protected virtual TResult WithUnitOfWork<TResult>(AbpUnitOfWorkOptions options, Func<TResult> func)
{
using (var scope = ServiceProvider.CreateScope())
{
var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
using (var uow = uowManager.Begin(options))
{
var result = func();
uow.Complete();
return result;
}
}
}
protected virtual Task<TResult> WithUnitOfWorkAsync<TResult>(Func<Task<TResult>> func)
{
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func);

17
framework/test/Volo.Abp.Uow.Tests/Volo/Abp/Uow/UnitOfWork_Events_Tests.cs

@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Xunit;
@ -15,7 +16,7 @@ namespace Volo.Abp.Uow
}
[Fact]
public void Should_Trigger_Complete_On_Success()
public async Task Should_Trigger_Complete_On_Success()
{
var completed = false;
var disposed = false;
@ -25,7 +26,7 @@ namespace Volo.Abp.Uow
uow.OnCompleted(async () => completed = true);
uow.Disposed += (sender, args) => disposed = true;
uow.Complete();
await uow.CompleteAsync();
completed.ShouldBeTrue();
}
@ -34,7 +35,7 @@ namespace Volo.Abp.Uow
}
[Fact]
public void Should_Trigger_Complete_On_Success_In_Child_Uow()
public async Task Should_Trigger_Complete_On_Success_In_Child_Uow()
{
var completed = false;
var disposed = false;
@ -46,7 +47,7 @@ namespace Volo.Abp.Uow
childUow.OnCompleted(async () => completed = true);
uow.Disposed += (sender, args) => disposed = true;
childUow.Complete();
await childUow.CompleteAsync();
completed.ShouldBeFalse(); //Parent has not been completed yet!
disposed.ShouldBeFalse();
@ -55,7 +56,7 @@ namespace Volo.Abp.Uow
completed.ShouldBeFalse(); //Parent has not been completed yet!
disposed.ShouldBeFalse();
uow.Complete();
await uow.CompleteAsync();
completed.ShouldBeTrue(); //It's completed now!
disposed.ShouldBeFalse(); //But not disposed yet!
@ -110,7 +111,7 @@ namespace Volo.Abp.Uow
[InlineData(true)]
[InlineData(false)]
[Theory]
public void Should_Trigger_Failed_If_Rolled_Back(bool callComplete)
public async Task Should_Trigger_Failed_If_Rolled_Back(bool callComplete)
{
var completed = false;
var failed = false;
@ -122,11 +123,11 @@ namespace Volo.Abp.Uow
uow.Failed += (sender, args) => { failed = true; args.IsRolledback.ShouldBeTrue(); };
uow.Disposed += (sender, args) => disposed = true;
uow.Rollback();
await uow.RollbackAsync();
if (callComplete)
{
uow.Complete();
await uow.CompleteAsync();
}
}

122
framework/test/Volo.Abp.Validation.Tests/Volo/Abp/Validation/ApplicationService_Validation_Tests.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Autofac;
@ -25,36 +26,37 @@ namespace Volo.Abp.Validation
}
[Fact]
public void Should_Work_Proper_With_Right_Inputs()
public async Task Should_Work_Proper_With_Right_Inputs()
{
var output = _myAppService.MyMethod(new MyMethodInput { MyStringValue = "test" });
var output = await _myAppService.MyMethod(new MyMethodInput { MyStringValue = "test" });
output.Result.ShouldBe(42);
}
[Fact]
public void Should_Not_Work_With_Wrong_Inputs()
public async Task Should_Not_Work_With_Wrong_Inputs()
{
Assert.Throws<AbpValidationException>(() => _myAppService.MyMethod(new MyMethodInput())); //MyStringValue is not supplied!
Assert.Throws<AbpValidationException>(() => _myAppService.MyMethod(new MyMethodInput { MyStringValue = "a" })); //MyStringValue's min length should be 3!
await Assert.ThrowsAsync<AbpValidationException>(async () => await _myAppService.MyMethod(new MyMethodInput())); //MyStringValue is not supplied!
await Assert.ThrowsAsync<AbpValidationException>(async () => await _myAppService.MyMethod(new MyMethodInput { MyStringValue = "a" })); //MyStringValue's min length should be 3!
}
[Fact]
public void Should_Work_With_Right_Nesned_Inputs()
public async Task Should_Work_With_Right_Nesned_Inputs()
{
var output = _myAppService.MyMethod2(new MyMethod2Input
var output = await _myAppService.MyMethod2(new MyMethod2Input
{
MyStringValue2 = "test 1",
Input1 = new MyMethodInput { MyStringValue = "test 2" },
DateTimeValue = DateTime.Now
});
output.Result.ShouldBe(42);
}
[Fact]
public void Should_Not_Work_With_Wrong_Nesned_Inputs_1()
public async Task Should_Not_Work_With_Wrong_Nesned_Inputs_1()
{
Assert.Throws<AbpValidationException>(() =>
_myAppService.MyMethod2(new MyMethod2Input
await Assert.ThrowsAsync<AbpValidationException>(async () =>
await _myAppService.MyMethod2(new MyMethod2Input
{
MyStringValue2 = "test 1",
Input1 = new MyMethodInput() //MyStringValue is not set
@ -62,20 +64,20 @@ namespace Volo.Abp.Validation
}
[Fact]
public void Should_Not_Work_With_Wrong_Nesned_Inputs_2()
public async Task Should_Not_Work_With_Wrong_Nesned_Inputs_2()
{
Assert.Throws<AbpValidationException>(() =>
_myAppService.MyMethod2(new MyMethod2Input //Input1 is not set
await Assert.ThrowsAsync<AbpValidationException>(async () =>
await _myAppService.MyMethod2(new MyMethod2Input //Input1 is not set
{
MyStringValue2 = "test 1"
}));
}
[Fact]
public void Should_Not_Work_With_Wrong_List_Input_1()
public async Task Should_Not_Work_With_Wrong_List_Input_1()
{
Assert.Throws<AbpValidationException>(() =>
_myAppService.MyMethod3(
await Assert.ThrowsAsync<AbpValidationException>(async () =>
await _myAppService.MyMethod3(
new MyMethod3Input
{
MyStringValue2 = "test 1",
@ -87,10 +89,10 @@ namespace Volo.Abp.Validation
}
[Fact]
public void Should_Not_Work_With_Wrong_Array_Input_1()
public async Task Should_Not_Work_With_Wrong_Array_Input_1()
{
Assert.Throws<AbpValidationException>(() =>
_myAppService.MyMethod3(
await Assert.ThrowsAsync<AbpValidationException>(async () =>
await _myAppService.MyMethod3(
new MyMethod3Input
{
MyStringValue2 = "test 1",
@ -102,31 +104,31 @@ namespace Volo.Abp.Validation
}
[Fact]
public void Should_Not_Work_If_Array_Is_Null()
public async Task Should_Not_Work_If_Array_Is_Null()
{
Assert.Throws<AbpValidationException>(() =>
_myAppService.MyMethod4(new MyMethod4Input()) //ArrayItems is null!
await Assert.ThrowsAsync<AbpValidationException>(async () =>
await _myAppService.MyMethod4(new MyMethod4Input()) //ArrayItems is null!
);
}
[Fact]
public void Should_Work_If_Array_Is_Null_But_DisabledValidation_For_Method()
public async Task Should_Work_If_Array_Is_Null_But_DisabledValidation_For_Method()
{
_myAppService.MyMethod4_2(new MyMethod4Input());
await _myAppService.MyMethod4_2(new MyMethod4Input());
}
[Fact]
public void Should_Work_If_Array_Is_Null_But_DisabledValidation_For_Property()
public async Task Should_Work_If_Array_Is_Null_But_DisabledValidation_For_Property()
{
_myAppService.MyMethod5(new MyMethod5Input());
await _myAppService.MyMethod5(new MyMethod5Input());
}
[Fact]
public void Should_Use_IValidatableObject()
public async Task Should_Use_IValidatableObject()
{
Assert.Throws<AbpValidationException>(() =>
await Assert.ThrowsAsync<AbpValidationException>(async () =>
{
_myAppService.MyMethod6(new MyMethod6Input
await _myAppService.MyMethod6(new MyMethod6Input
{
MyStringValue = "test value" //MyIntValue has not set!
});
@ -134,15 +136,15 @@ namespace Volo.Abp.Validation
}
[Fact]
public void Should_Stop_Recursive_Validation_In_A_Constant_Depth()
public async Task Should_Stop_Recursive_Validation_In_A_Constant_Depth()
{
_myAppService.MyMethod8(new MyClassWithRecursiveReference { Value = "42" }).Result.ShouldBe(42);
(await _myAppService.MyMethod8(new MyClassWithRecursiveReference { Value = "42" })).Result.ShouldBe(42);
}
[Fact]
public void Should_Allow_Null_For_Nullable_Enums()
public async Task Should_Allow_Null_For_Nullable_Enums()
{
_myAppService.MyMethodWithNullableEnum(null);
await _myAppService.MyMethodWithNullableEnum(null);
}
[Fact]
@ -184,63 +186,63 @@ namespace Volo.Abp.Validation
public interface IMyAppService
{
MyMethodOutput MyMethod(MyMethodInput input);
MyMethodOutput MyMethod2(MyMethod2Input input);
MyMethodOutput MyMethod3(MyMethod3Input input);
MyMethodOutput MyMethod4(MyMethod4Input input);
MyMethodOutput MyMethod4_2(MyMethod4Input input);
MyMethodOutput MyMethod5(MyMethod5Input input);
MyMethodOutput MyMethod6(MyMethod6Input input);
MyMethodOutput MyMethod8(MyClassWithRecursiveReference input);
void MyMethodWithNullableEnum(MyEnum? value);
Task<MyMethodOutput> MyMethod(MyMethodInput input);
Task<MyMethodOutput> MyMethod2(MyMethod2Input input);
Task<MyMethodOutput> MyMethod3(MyMethod3Input input);
Task<MyMethodOutput> MyMethod4(MyMethod4Input input);
Task<MyMethodOutput> MyMethod4_2(MyMethod4Input input);
Task<MyMethodOutput> MyMethod5(MyMethod5Input input);
Task<MyMethodOutput> MyMethod6(MyMethod6Input input);
Task<MyMethodOutput> MyMethod8(MyClassWithRecursiveReference input);
Task MyMethodWithNullableEnum(MyEnum? value);
}
public class MyAppService : IMyAppService, ITransientDependency
{
public MyMethodOutput MyMethod(MyMethodInput input)
public Task<MyMethodOutput> MyMethod(MyMethodInput input)
{
return new MyMethodOutput { Result = 42 };
return Task.FromResult(new MyMethodOutput { Result = 42 });
}
public MyMethodOutput MyMethod2(MyMethod2Input input)
public Task<MyMethodOutput> MyMethod2(MyMethod2Input input)
{
return new MyMethodOutput { Result = 42 };
return Task.FromResult(new MyMethodOutput { Result = 42 });
}
public MyMethodOutput MyMethod3(MyMethod3Input input)
public Task<MyMethodOutput> MyMethod3(MyMethod3Input input)
{
return new MyMethodOutput { Result = 42 };
return Task.FromResult(new MyMethodOutput { Result = 42 });
}
public MyMethodOutput MyMethod4(MyMethod4Input input)
public Task<MyMethodOutput> MyMethod4(MyMethod4Input input)
{
return new MyMethodOutput { Result = 42 };
return Task.FromResult(new MyMethodOutput { Result = 42 });
}
[DisableValidation]
public MyMethodOutput MyMethod4_2(MyMethod4Input input)
public Task<MyMethodOutput> MyMethod4_2(MyMethod4Input input)
{
return new MyMethodOutput { Result = 42 };
return Task.FromResult(new MyMethodOutput { Result = 42 });
}
public MyMethodOutput MyMethod5(MyMethod5Input input)
public Task<MyMethodOutput> MyMethod5(MyMethod5Input input)
{
return new MyMethodOutput { Result = 42 };
return Task.FromResult(new MyMethodOutput { Result = 42 });
}
public MyMethodOutput MyMethod6(MyMethod6Input input)
public Task<MyMethodOutput> MyMethod6(MyMethod6Input input)
{
return new MyMethodOutput { Result = 42 };
return Task.FromResult(new MyMethodOutput { Result = 42 });
}
public MyMethodOutput MyMethod8(MyClassWithRecursiveReference input)
public Task<MyMethodOutput> MyMethod8(MyClassWithRecursiveReference input)
{
return new MyMethodOutput { Result = 42 };
return Task.FromResult(new MyMethodOutput { Result = 42 });
}
public void MyMethodWithNullableEnum(MyEnum? value)
public Task MyMethodWithNullableEnum(MyEnum? value)
{
return Task.CompletedTask;
}
}

27
modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs

@ -33,33 +33,6 @@ namespace Volo.Abp.AuditLogging
Logger = NullLogger<AuditingStore>.Instance;
}
public void Save(AuditLogInfo auditInfo)
{
if (!Options.HideErrors)
{
SaveLog(auditInfo);
return;
}
try
{
SaveLog(auditInfo);
}
catch (Exception ex)
{
Logger.LogException(ex, LogLevel.Error);
}
}
protected virtual void SaveLog(AuditLogInfo auditInfo)
{
using (var uow = _unitOfWorkManager.Begin(true))
{
_auditLogRepository.Insert(new AuditLog(_guidGenerator, auditInfo));
uow.SaveChanges();
}
}
public async Task SaveAsync(AuditLogInfo auditInfo)
{
if (!Options.HideErrors)

6
modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AuditLogRepository_Tests.cs

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.Abp.AuditLogging.EntityFrameworkCore
namespace Volo.Abp.AuditLogging.EntityFrameworkCore
{
public class AuditLogRepository_Tests : AuditLogRepository_Tests<AbpAuditLoggingEntityFrameworkCoreTestModule>
{

12
modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditLogRepository_Tests.cs

@ -119,8 +119,8 @@ namespace Volo.Abp.AuditLogging
}
};
AuditLogRepository.Insert(new AuditLog(GuidGenerator, log1));
AuditLogRepository.Insert(new AuditLog(GuidGenerator, log2));
await AuditLogRepository.InsertAsync(new AuditLog(GuidGenerator, log1));
await AuditLogRepository.InsertAsync(new AuditLog(GuidGenerator, log2));
//Assert
var logs = await AuditLogRepository.GetListAsync();
@ -223,8 +223,8 @@ namespace Volo.Abp.AuditLogging
}
};
AuditLogRepository.Insert(new AuditLog(GuidGenerator, log1));
AuditLogRepository.Insert(new AuditLog(GuidGenerator, log2));
await AuditLogRepository.InsertAsync(new AuditLog(GuidGenerator, log1));
await AuditLogRepository.InsertAsync(new AuditLog(GuidGenerator, log2));
//Assert
var logs = await AuditLogRepository.GetCountAsync();
@ -325,8 +325,8 @@ namespace Volo.Abp.AuditLogging
}
};
AuditLogRepository.Insert(new AuditLog(GuidGenerator, log1));
AuditLogRepository.Insert(new AuditLog(GuidGenerator, log2));
await AuditLogRepository.InsertAsync(new AuditLog(GuidGenerator, log1));
await AuditLogRepository.InsertAsync(new AuditLog(GuidGenerator, log2));
//Assert
var date = DateTime.Parse("2020-01-01");

2
modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs

@ -68,7 +68,7 @@ namespace Volo.Abp.AuditLogging
//Assert
var insertedLog = _auditLogRepository.GetList(true)
var insertedLog = (await _auditLogRepository.GetListAsync(true))
.FirstOrDefault(al => al.UserId == userId);
insertedLog.ShouldNotBeNull();

31
modules/background-jobs/src/Volo.Abp.BackgroundJobs.Domain/Volo/Abp/BackgroundJobs/BackgroundJobStore.cs

@ -20,13 +20,6 @@ namespace Volo.Abp.BackgroundJobs
BackgroundJobRepository = backgroundJobRepository;
}
public BackgroundJobInfo Find(Guid jobId)
{
return ObjectMapper.Map<BackgroundJobRecord, BackgroundJobInfo>(
BackgroundJobRepository.Find(jobId)
);
}
public virtual async Task<BackgroundJobInfo> FindAsync(Guid jobId)
{
return ObjectMapper.Map<BackgroundJobRecord, BackgroundJobInfo>(
@ -34,13 +27,6 @@ namespace Volo.Abp.BackgroundJobs
);
}
public void Insert(BackgroundJobInfo jobInfo)
{
BackgroundJobRepository.Insert(
ObjectMapper.Map<BackgroundJobInfo, BackgroundJobRecord>(jobInfo)
);
}
public virtual async Task InsertAsync(BackgroundJobInfo jobInfo)
{
await BackgroundJobRepository.InsertAsync(
@ -62,28 +48,11 @@ namespace Volo.Abp.BackgroundJobs
);
}
public void Delete(Guid jobId)
{
BackgroundJobRepository.Delete(jobId);
}
public virtual async Task DeleteAsync(Guid jobId)
{
await BackgroundJobRepository.DeleteAsync(jobId);
}
public void Update(BackgroundJobInfo jobInfo)
{
var backgroundJobRecord = BackgroundJobRepository.Find(jobInfo.Id);
if (backgroundJobRecord == null)
{
return;
}
ObjectMapper.Map(jobInfo, backgroundJobRecord);
BackgroundJobRepository.Update(backgroundJobRecord);
}
public virtual async Task UpdateAsync(BackgroundJobInfo jobInfo)
{
var backgroundJobRecord = await BackgroundJobRepository.FindAsync(jobInfo.Id);

5
modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/AbpBackgroundJobsTestBaseModule.cs

@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
namespace Volo.Abp.BackgroundJobs
{
@ -28,9 +29,9 @@ namespace Volo.Abp.BackgroundJobs
{
using (var scope = context.ServiceProvider.CreateScope())
{
scope.ServiceProvider
AsyncHelper.RunSync(() => scope.ServiceProvider
.GetRequiredService<BackgroundJobsTestDataBuilder>()
.Build();
.BuildAsync());
}
}
}

9
modules/background-jobs/test/Volo.Abp.BackgroundJobs.TestBase/Volo/Abp/BackgroundJobs/BackgroundJobsTestDataBuilder.cs

@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Timing;
@ -20,9 +21,9 @@ namespace Volo.Abp.BackgroundJobs
_clock = clock;
}
public void Build()
public async Task BuildAsync()
{
_backgroundJobRepository.Insert(
await _backgroundJobRepository.InsertAsync(
new BackgroundJobRecord(_testData.JobId1)
{
JobName = "TestJobName",
@ -36,7 +37,7 @@ namespace Volo.Abp.BackgroundJobs
}
);
_backgroundJobRepository.Insert(
await _backgroundJobRepository.InsertAsync(
new BackgroundJobRecord(_testData.JobId2)
{
JobName = "TestJobName",
@ -50,7 +51,7 @@ namespace Volo.Abp.BackgroundJobs
}
);
_backgroundJobRepository.Insert(
await _backgroundJobRepository.InsertAsync(
new BackgroundJobRecord(_testData.JobId3)
{
JobName = "TestJobName",

2
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs

@ -118,7 +118,7 @@ namespace Volo.Blogging.Posts
await AuthorizationService.CheckAsync(post, CommonOperations.Delete);
var tags = await GetTagsOfPost(id);
_tagRepository.DecreaseUsageCountOfTags(tags.Select(t => t.Id).ToList());
await _tagRepository.DecreaseUsageCountOfTagsAsync(tags.Select(t => t.Id).ToList());
await _commentRepository.DeleteOfPost(id);
await _postRepository.DeleteAsync(id);

3
modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Tagging/ITagRepository.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
@ -15,6 +16,6 @@ namespace Volo.Blogging.Tagging
Task<List<Tag>> GetListAsync(IEnumerable<Guid> ids);
void DecreaseUsageCountOfTags(List<Guid> id);
Task DecreaseUsageCountOfTagsAsync(List<Guid> id, CancellationToken cancellationToken = default);
}
}

7
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -36,9 +37,11 @@ namespace Volo.Blogging.Tagging
return await DbSet.Where(t => ids.Contains(t.Id)).ToListAsync();
}
public void DecreaseUsageCountOfTags(List<Guid> ids)
public async Task DecreaseUsageCountOfTagsAsync(List<Guid> ids, CancellationToken cancellationToken = default)
{
var tags = DbSet.Where(t => ids.Any(id => id == t.Id));
var tags = await DbSet
.Where(t => ids.Any(id => id == t.Id))
.ToListAsync(GetCancellationToken(cancellationToken));
foreach (var tag in tags)
{

11
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
@ -19,7 +20,7 @@ namespace Volo.Blogging.Tagging
public async Task<List<Tag>> GetListAsync(Guid blogId)
{
return await GetMongoQueryable().Where(t=>t.BlogId == blogId).ToListAsync();
return await GetMongoQueryable().Where(t => t.BlogId == blogId).ToListAsync();
}
public async Task<Tag> GetByNameAsync(Guid blogId, string name)
@ -37,14 +38,16 @@ namespace Volo.Blogging.Tagging
return await GetMongoQueryable().Where(t => ids.Contains(t.Id)).ToListAsync();
}
public void DecreaseUsageCountOfTags(List<Guid> ids)
public async Task DecreaseUsageCountOfTagsAsync(List<Guid> ids, CancellationToken cancellationToken = default)
{
var tags = GetMongoQueryable().Where(t => ids.Contains(t.Id));
var tags = await GetMongoQueryable()
.Where(t => ids.Contains(t.Id))
.ToListAsync(GetCancellationToken(cancellationToken));
foreach (var tag in tags)
{
tag.DecreaseUsageCount();
Update(tag);
await UpdateAsync(tag, cancellationToken: GetCancellationToken(cancellationToken));
}
}
}

2
modules/blogging/test/Volo.Blogging.TestBase/Volo/Blogging/Tagging/TagRepository_Tests.cs

@ -60,7 +60,7 @@ namespace Volo.Blogging.Tagging
var tag = await TagRepository.FindByNameAsync(BloggingTestData.Blog1Id, BloggingTestData.Tag1Name);
var usageCount = tag.UsageCount;
TagRepository.DecreaseUsageCountOfTags(new List<Guid>()
await TagRepository.DecreaseUsageCountOfTagsAsync(new List<Guid>()
{
tag.Id
});

5
modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocsTestBaseModule.cs

@ -3,6 +3,7 @@ using Volo.Abp;
using Volo.Abp.Authorization;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
namespace Volo.Docs
{
@ -28,9 +29,9 @@ namespace Volo.Docs
{
using (var scope = context.ServiceProvider.CreateScope())
{
scope.ServiceProvider
AsyncHelper.RunSync(() => scope.ServiceProvider
.GetRequiredService<DocsTestDataBuilder>()
.Build();
.BuildAsync());
}
}
}

7
modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocsTestDataBuilder.cs

@ -1,4 +1,5 @@
using Volo.Abp.Data;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Docs.GitHub.Documents;
using Volo.Docs.Projects;
@ -18,7 +19,7 @@ namespace Volo.Docs
_projectRepository = projectRepository;
}
public void Build()
public async Task BuildAsync()
{
var project = new Project(
_testData.PorjectId,
@ -36,7 +37,7 @@ namespace Volo.Docs
.SetProperty("GitHubAccessToken", "123456")
.SetProperty("GitHubUserAgent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
_projectRepository.Insert(project);
await _projectRepository.InsertAsync(project);
}
}
}

5
modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementTestBaseModule.cs

@ -3,6 +3,7 @@ using Volo.Abp.Authorization;
using Volo.Abp.Autofac;
using Volo.Abp.Features;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
namespace Volo.Abp.FeatureManagement
{
@ -37,9 +38,9 @@ namespace Volo.Abp.FeatureManagement
{
using (var scope = context.ServiceProvider.CreateScope())
{
scope.ServiceProvider
AsyncHelper.RunSync(() => scope.ServiceProvider
.GetRequiredService<FeatureManagementTestDataBuilder>()
.Build();
.BuildAsync());
}
}
}

33
modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureManagementTestDataBuilder.cs

@ -1,4 +1,5 @@
using Volo.Abp.DependencyInjection;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Features;
using Volo.Abp.Guids;
@ -20,12 +21,12 @@ namespace Volo.Abp.FeatureManagement
_featureValueRepository = featureValueRepository;
}
public void Build()
public async Task BuildAsync()
{
#region "Regular" edition features
//SocialLogins
_featureValueRepository.Insert(
await _featureValueRepository.InsertAsync(
new FeatureValue(
_guidGenerator.Create(),
TestFeatureDefinitionProvider.SocialLogins,
@ -36,7 +37,7 @@ namespace Volo.Abp.FeatureManagement
);
//UserCount
_featureValueRepository.Insert(
await _featureValueRepository.InsertAsync(
new FeatureValue(
_guidGenerator.Create(),
TestFeatureDefinitionProvider.UserCount,
@ -47,7 +48,7 @@ namespace Volo.Abp.FeatureManagement
);
//ProjectCount
_featureValueRepository.Insert(
await _featureValueRepository.InsertAsync(
new FeatureValue(
_guidGenerator.Create(),
TestFeatureDefinitionProvider.ProjectCount,
@ -62,7 +63,7 @@ namespace Volo.Abp.FeatureManagement
#region "Enterprise" edition features
//SocialLogins
_featureValueRepository.Insert(
await _featureValueRepository.InsertAsync(
new FeatureValue(
_guidGenerator.Create(),
TestFeatureDefinitionProvider.SocialLogins,
@ -73,7 +74,7 @@ namespace Volo.Abp.FeatureManagement
);
//EmailSupport
_featureValueRepository.Insert(
await _featureValueRepository.InsertAsync(
new FeatureValue(
_guidGenerator.Create(),
TestFeatureDefinitionProvider.EmailSupport,
@ -84,7 +85,7 @@ namespace Volo.Abp.FeatureManagement
);
//UserCount
_featureValueRepository.Insert(
await _featureValueRepository.InsertAsync(
new FeatureValue(
_guidGenerator.Create(),
TestFeatureDefinitionProvider.UserCount,
@ -95,7 +96,7 @@ namespace Volo.Abp.FeatureManagement
);
//ProjectCount
_featureValueRepository.Insert(
await _featureValueRepository.InsertAsync(
new FeatureValue(
_guidGenerator.Create(),
TestFeatureDefinitionProvider.ProjectCount,
@ -106,7 +107,7 @@ namespace Volo.Abp.FeatureManagement
);
//BackupCount
_featureValueRepository.Insert(
await _featureValueRepository.InsertAsync(
new FeatureValue(
_guidGenerator.Create(),
TestFeatureDefinitionProvider.BackupCount,
@ -121,7 +122,7 @@ namespace Volo.Abp.FeatureManagement
#region "Ultimate" edition features
//SocialLogins
_featureValueRepository.Insert(
await _featureValueRepository.InsertAsync(
new FeatureValue(
_guidGenerator.Create(),
TestFeatureDefinitionProvider.SocialLogins,
@ -132,7 +133,7 @@ namespace Volo.Abp.FeatureManagement
);
//EmailSupport
_featureValueRepository.Insert(
await _featureValueRepository.InsertAsync(
new FeatureValue(
_guidGenerator.Create(),
TestFeatureDefinitionProvider.EmailSupport,
@ -143,7 +144,7 @@ namespace Volo.Abp.FeatureManagement
);
//EmailSupport
_featureValueRepository.Insert(
await _featureValueRepository.InsertAsync(
new FeatureValue(
_guidGenerator.Create(),
TestFeatureDefinitionProvider.DailyAnalysis,
@ -154,7 +155,7 @@ namespace Volo.Abp.FeatureManagement
);
//UserCount
_featureValueRepository.Insert(
await _featureValueRepository.InsertAsync(
new FeatureValue(
_guidGenerator.Create(),
TestFeatureDefinitionProvider.UserCount,
@ -165,7 +166,7 @@ namespace Volo.Abp.FeatureManagement
);
//ProjectCount
_featureValueRepository.Insert(
await _featureValueRepository.InsertAsync(
new FeatureValue(
_guidGenerator.Create(),
TestFeatureDefinitionProvider.ProjectCount,
@ -176,7 +177,7 @@ namespace Volo.Abp.FeatureManagement
);
//BackupCount
_featureValueRepository.Insert(
await _featureValueRepository.InsertAsync(
new FeatureValue(
_guidGenerator.Create(),
TestFeatureDefinitionProvider.BackupCount,

5
modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/AbpIdentityDomainTestModule.cs

@ -3,6 +3,7 @@ using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Identity.EntityFrameworkCore;
using Volo.Abp.Modularity;
using Volo.Abp.PermissionManagement.Identity;
using Volo.Abp.Threading;
namespace Volo.Abp.Identity
{
@ -22,9 +23,9 @@ namespace Volo.Abp.Identity
{
using (var scope = context.ServiceProvider.CreateScope())
{
scope.ServiceProvider
AsyncHelper.RunSync(() => scope.ServiceProvider
.GetRequiredService<TestPermissionDataBuilder>()
.Build();
.Build());
}
}
}

4
modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityClaimTypeManager_Tests.cs

@ -42,7 +42,7 @@ namespace Volo.Abp.Identity
[Fact]
public async Task UpdateAsync()
{
var ageClaim = _identityClaimTypeRepository.Find(_testData.AgeClaimId);
var ageClaim = await _identityClaimTypeRepository.FindAsync(_testData.AgeClaimId);
ageClaim.ShouldNotBeNull();
ageClaim.Description = "this is age";
@ -65,7 +65,7 @@ namespace Volo.Abp.Identity
public async Task Static_IdentityClaimType_Cant_Not_Update()
{
var phoneClaim = new IdentityClaimType(Guid.NewGuid(), "Phone", true, true);
_identityClaimTypeRepository.Insert(phoneClaim);
await _identityClaimTypeRepository.InsertAsync(phoneClaim);
await Assert.ThrowsAnyAsync<AbpException>(async () => await _claimTypeManager.UpdateAsync(phoneClaim));
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save