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