@ -1,7 +1,5 @@
using Shouldly ;
using Shouldly ;
using System ;
using System ;
using System.Collections.Generic ;
using System.Text ;
using System.Threading.Tasks ;
using System.Threading.Tasks ;
using Volo.Abp.Data ;
using Volo.Abp.Data ;
using Volo.Abp.Domain.Repositories ;
using Volo.Abp.Domain.Repositories ;
@ -15,58 +13,57 @@ namespace Volo.Abp.TestApp.Testing
public abstract class HardDelete_Tests < TStartupModule > : TestAppTestBase < TStartupModule >
public abstract class HardDelete_Tests < TStartupModule > : TestAppTestBase < TStartupModule >
where TStartupModule : IAbpModule
where TStartupModule : IAbpModule
{
{
protected readonly IRepository < Person , Guid > _p ersonRepository;
protected readonly IRepository < Person , Guid > P ersonRepository;
protected readonly IDataFilter DataFilter ;
protected readonly IDataFilter DataFilter ;
protected readonly IUnitOfWorkManager _unitOfWorkManager ;
protected readonly IUnitOfWorkManager UnitOfWorkManager ;
public HardDelete_Tests ( )
protected HardDelete_Tests ( )
{
{
_p ersonRepository = GetRequiredService < IRepository < Person , Guid > > ( ) ;
P ersonRepository = GetRequiredService < IRepository < Person , Guid > > ( ) ;
DataFilter = GetRequiredService < IDataFilter > ( ) ;
DataFilter = GetRequiredService < IDataFilter > ( ) ;
_u nitOfWorkManager = GetRequiredService < IUnitOfWorkManager > ( ) ;
U nitOfWorkManager = GetRequiredService < IUnitOfWorkManager > ( ) ;
}
}
[Fact]
[Fact]
public async Task Should_HardDelete_Entity_With_Collection ( )
public async Task Should_HardDelete_Entities ( )
{
using ( var uow = _unitOfWorkManager . Begin ( ) )
{
using ( DataFilter . Disable < ISoftDelete > ( ) )
{
{
var douglas = await _personRepository . FindAsync ( TestDataBuilder . UserDouglasId ) ;
var douglas = await PersonRepository . GetAsync ( TestDataBuilder . UserDouglasId ) ;
await _personRepository . HardDeleteAsync ( x = > x . Id = = TestDataBuilder . UserDouglasId ) ;
await PersonRepository . HardDeleteAsync ( douglas ) ;
await uow . CompleteAsync ( ) ;
}
var deletedDougles = await _personRepository . FindAsync ( TestDataBuilder . UserDouglasId ) ;
douglas = await PersonRepository . FindAsync ( TestDataBuilder . UserDouglasId ) ;
deletedDougles . ShouldBeNull ( ) ;
douglas . ShouldBeNull ( ) ;
}
}
}
[Fact]
[Fact]
public async Task Should_HardDelete_Soft_Deleted_Entities ( )
public async Task Should_HardDelete_Soft_Deleted_Entities ( )
{
{
var douglas = await _p ersonRepository. GetAsync ( TestDataBuilder . UserDouglasId ) ;
var douglas = await P ersonRepository. GetAsync ( TestDataBuilder . UserDouglasId ) ;
await _p ersonRepository. DeleteAsync ( douglas ) ;
await P ersonRepository. DeleteAsync ( douglas ) ;
douglas = await _p ersonRepository. FindAsync ( TestDataBuilder . UserDouglasId ) ;
douglas = await P ersonRepository. FindAsync ( TestDataBuilder . UserDouglasId ) ;
douglas . ShouldBeNull ( ) ;
douglas . ShouldBeNull ( ) ;
using ( DataFilter . Disable < ISoftDelete > ( ) )
using ( DataFilter . Disable < ISoftDelete > ( ) )
{
{
douglas = await _p ersonRepository. FindAsync ( TestDataBuilder . UserDouglasId ) ;
douglas = await P ersonRepository. FindAsync ( TestDataBuilder . UserDouglasId ) ;
douglas . ShouldNotBeNull ( ) ;
douglas . ShouldNotBeNull ( ) ;
douglas . IsDeleted . ShouldBeTrue ( ) ;
douglas . IsDeleted . ShouldBeTrue ( ) ;
douglas . DeletionTime . ShouldNotBeNull ( ) ;
douglas . DeletionTime . ShouldNotBeNull ( ) ;
}
}
using ( var uow = _unitOfWorkManager . Begin ( ) )
using ( var uow = UnitOfWorkManager . Begin ( ) )
{
{
using ( DataFilter . Disable < ISoftDelete > ( ) )
using ( DataFilter . Disable < ISoftDelete > ( ) )
{
{
douglas = await _personRepository . GetAsync ( TestDataBuilder . UserDouglasId ) ;
douglas = await PersonRepository . GetAsync ( TestDataBuilder . UserDouglasId ) ;
await _personRepository . HardDeleteAsync ( douglas ) ;
await uow . CompleteAsync ( ) ;
var deletedDougles = await _personRepository . FindAsync ( TestDataBuilder . UserDouglasId ) ;
deletedDougles . ShouldBeNull ( ) ;
}
}
await PersonRepository . HardDeleteAsync ( douglas ) ;
await uow . CompleteAsync ( ) ;
}
}
douglas = await PersonRepository . FindAsync ( TestDataBuilder . UserDouglasId ) ;
douglas . ShouldBeNull ( ) ;
}
}
}
}
}
}