Browse Source

Removed sync interception and sync repository methods.

pull/2464/head
Halil İbrahim Kalkan 7 years ago
parent
commit
676a5c61ac
  1. 27
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingInterceptor.cs
  2. 7
      framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AuthorizationInterceptor.cs
  3. 7
      framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpInterceptorAdapter.cs
  4. 14
      framework/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpMethodInvocationAdapter.cs
  5. 12
      framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/AbpInterceptor.cs
  6. 2
      framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/IAbpInterceptor.cs
  7. 2
      framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/IAbpMethodInvocation.cs
  8. 70
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/BasicRepositoryBase.cs
  9. 42
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IBasicRepository.cs
  10. 31
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IReadOnlyBasicRepository.cs
  11. 13
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IRepository.cs
  12. 55
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs
  13. 73
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs
  14. 13
      framework/src/Volo.Abp.Features/Volo/Abp/Features/FeatureInterceptor.cs
  15. 25
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/DynamicHttpProxyInterceptor.cs
  16. 79
      framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs
  17. 120
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs
  18. 15
      framework/src/Volo.Abp.Uow/Volo/Abp/Uow/UnitOfWorkInterceptor.cs
  19. 6
      framework/src/Volo.Abp.Validation/Volo/Abp/Validation/ValidationInterceptor.cs
  20. 18
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PeopleAppService_Tests.cs
  21. 1
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/Uow/UnitOfWorkTestController.cs
  22. 3
      framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/v1/ITodoAppService.cs
  23. 7
      framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/v1/TodoAppService.cs
  24. 3
      framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/v2/ITodoAppService.cs
  25. 7
      framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/v2/TodoAppService.cs
  26. 7
      framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Test/v1/TodoAppService_Tests.cs
  27. 7
      framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/Test/v2/TodoAppService_Tests.cs
  28. 10
      framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/Authorization_Tests.cs
  29. 4
      framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/TestServices/IMyAuthorizedService1.cs
  30. 8
      framework/test/Volo.Abp.Authorization.Tests/Volo/Abp/Authorization/TestServices/MyAuthorizedService1.cs
  31. 94
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/AbpInterceptionTestBase.cs
  32. 9
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/SimpleAsyncInterceptor.cs
  33. 11
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/SimpleResultCacheTestInterceptor.cs
  34. 14
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/SimpleSyncInterceptor.cs
  35. 34
      framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Repositories/RepositoryRegistration_Tests.cs
  36. 5
      framework/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/AbpEfCoreTestSecondContextModule.cs
  37. 5
      framework/test/Volo.Abp.EntityFrameworkCore.Tests.SecondContext/Volo/Abp/EntityFrameworkCore/TestApp/SecondContext/SecondContextTestDataBuilder.cs
  38. 15
      framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/DbContext_Replace_Tests.cs
  39. 11
      framework/test/Volo.Abp.Features.Tests/Volo/Abp/Features/ClassFeatureTestService.cs
  40. 12
      framework/test/Volo.Abp.Features.Tests/Volo/Abp/Features/FeatureInterceptor_Tests.cs
  41. 45
      framework/test/Volo.Abp.FluentValidation.Tests/Volo/Abp/FluentValidation/ApplicationService_FluentValidation_Tests.cs
  42. 2
      framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/IRegularTestController.cs
  43. 12
      framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/PersonAppServiceClientProxy_Tests.cs
  44. 7
      framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestController.cs
  45. 6
      framework/test/Volo.Abp.Http.Client.Tests/Volo/Abp/Http/DynamicProxying/RegularTestControllerClientProxy_Tests.cs
  46. 8
      framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests.cs
  47. 7
      framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests_With_Int_Pk.cs
  48. 6
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/PeopleAppService.cs
  49. 5
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestAppModule.cs
  50. 47
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs
  51. 6
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs
  52. 7
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Basic_Tests_With_Int_Pk.cs
  53. 122
      framework/test/Volo.Abp.Validation.Tests/Volo/Abp/Validation/ApplicationService_Validation_Tests.cs

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))

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);

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

@ -42,15 +42,10 @@ namespace Volo.Abp.Castle.DynamicProxy
}
else
{
InterceptSyncMethod(invocation, proceedInfo);
proceedInfo.Invoke();
}
}
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))

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

@ -40,25 +40,13 @@ namespace Volo.Abp.Castle.DynamicProxy
_lazyArgumentsDictionary = new Lazy<IReadOnlyDictionary<string, object>>(GetArgumentsDictionary);
}
public void Proceed()
{
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);
return (Task) _actualReturnValue;
}
private IReadOnlyDictionary<string, object> GetArgumentsDictionary()

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;

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))

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

@ -74,31 +74,6 @@ namespace Volo.Abp.Http.Client.DynamicProxying
Logger = NullLogger<DynamicHttpProxyInterceptor<TService>>.Instance;
}
public override void Intercept(IAbpMethodInvocation invocation)
{
if (invocation.Method.ReturnType == typeof(void))
{
AsyncHelper.RunSync(() => MakeRequestAsync(invocation));
}
else
{
var responseAsString = AsyncHelper.RunSync(() => MakeRequestAsync(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
);
}
}
}
public override Task InterceptAsync(IAbpMethodInvocation invocation)
{
if (invocation.Method.ReturnType.GenericTypeArguments.IsNullOrEmpty())

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/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();
}
}

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();
}
}
}
}

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()
{

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

@ -14,9 +14,11 @@ namespace Volo.Abp.MongoDB.Repositories
[Fact]
public void Linq_Queries()
{
PersonRepository.FirstOrDefault(p => p.Name == "Douglas").ShouldNotBeNull();
PersonRepository.Count().ShouldBeGreaterThan(0);
WithUnitOfWork(() =>
{
PersonRepository.FirstOrDefault(p => p.Name == "Douglas").ShouldNotBeNull();
PersonRepository.Count().ShouldBeGreaterThan(0);
});
}
[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();

7
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;
@ -29,11 +30,11 @@ namespace Volo.Abp.TestApp.Testing
}
[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");
});

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;
}
}

Loading…
Cancel
Save