mirror of https://github.com/abpframework/abp.git
committed by
GitHub
14 changed files with 241 additions and 12 deletions
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Volo.Abp.Domain.Repositories |
|||
{ |
|||
public class UnitOfWorkExtensionDataTypes |
|||
{ |
|||
public static string HardDelete { get; } = "HardDelete"; |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.Uow |
|||
{ |
|||
public interface IUnitOfWorkManagerAccessor |
|||
{ |
|||
IUnitOfWorkManager UnitOfWorkManager { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using Volo.Abp.TestApp.Testing; |
|||
|
|||
namespace Volo.Abp.EntityFrameworkCore.DataFiltering |
|||
{ |
|||
public class HardDelete_Tests : HardDelete_Tests<AbpEntityFrameworkCoreTestModule> |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Volo.Abp.TestApp.Testing; |
|||
|
|||
namespace Volo.Abp.MongoDB.DataFiltering |
|||
{ |
|||
public class HardDelete_Tests : HardDelete_Tests<AbpMongoDbTestModule> |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,72 @@ |
|||
using Shouldly; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.TestApp.Domain; |
|||
using Volo.Abp.Uow; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.TestApp.Testing |
|||
{ |
|||
public abstract class HardDelete_Tests<TStartupModule> : TestAppTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
protected readonly IRepository<Person, Guid> _personRepository; |
|||
protected readonly IDataFilter DataFilter; |
|||
protected readonly IUnitOfWorkManager _unitOfWorkManager; |
|||
public HardDelete_Tests() |
|||
{ |
|||
_personRepository = GetRequiredService<IRepository<Person, Guid>>(); |
|||
DataFilter = GetRequiredService<IDataFilter>(); |
|||
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>(); |
|||
} |
|||
[Fact] |
|||
public async Task Should_HardDelete_Entity_With_Collection() |
|||
{ |
|||
using (var uow = _unitOfWorkManager.Begin()) |
|||
{ |
|||
using (DataFilter.Disable<ISoftDelete>()) |
|||
{ |
|||
var douglas = await _personRepository.FindAsync(TestDataBuilder.UserDouglasId); |
|||
await _personRepository.HardDeleteAsync(x => x.Id == TestDataBuilder.UserDouglasId); |
|||
await uow.CompleteAsync(); |
|||
} |
|||
|
|||
var deletedDougles = await _personRepository.FindAsync(TestDataBuilder.UserDouglasId); |
|||
deletedDougles.ShouldBeNull(); |
|||
} |
|||
} |
|||
[Fact] |
|||
public async Task Should_HardDelete_Soft_Deleted_Entities() |
|||
{ |
|||
var douglas = await _personRepository.GetAsync(TestDataBuilder.UserDouglasId); |
|||
await _personRepository.DeleteAsync(douglas); |
|||
|
|||
douglas = await _personRepository.FindAsync(TestDataBuilder.UserDouglasId); |
|||
douglas.ShouldBeNull(); |
|||
|
|||
using (DataFilter.Disable<ISoftDelete>()) |
|||
{ |
|||
douglas = await _personRepository.FindAsync(TestDataBuilder.UserDouglasId); |
|||
douglas.ShouldNotBeNull(); |
|||
douglas.IsDeleted.ShouldBeTrue(); |
|||
douglas.DeletionTime.ShouldNotBeNull(); |
|||
} |
|||
using (var uow = _unitOfWorkManager.Begin()) |
|||
{ |
|||
using (DataFilter.Disable<ISoftDelete>()) |
|||
{ |
|||
douglas = await _personRepository.GetAsync(TestDataBuilder.UserDouglasId); |
|||
await _personRepository.HardDeleteAsync(douglas); |
|||
await uow.CompleteAsync(); |
|||
var deletedDougles = await _personRepository.FindAsync(TestDataBuilder.UserDouglasId); |
|||
deletedDougles.ShouldBeNull(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue