Browse Source

Merge pull request #3259 from abpframework/maliming/mongodb-delete

MongoDbRepository needs to filter when deleting entity based on Id.
pull/3488/head
Halil İbrahim Kalkan 7 years ago
committed by GitHub
parent
commit
1e916d78bc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs
  2. 40
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/SoftDelete_Tests.cs

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

@ -369,10 +369,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
bool autoSave = false,
CancellationToken cancellationToken = default)
{
return Collection.DeleteOneAsync(
CreateEntityFilter(id),
GetCancellationToken(cancellationToken)
);
return DeleteAsync(x => x.Id.Equals(id), autoSave, cancellationToken);
}
protected override FilterDefinition<TEntity> CreateEntityFilter(TEntity entity, bool withConcurrencyStamp = false, string concurrencyStamp = null)

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

@ -39,6 +39,24 @@ namespace Volo.Abp.TestApp.Testing
}
}
[Fact]
public async Task Should_Cancel_Deletion_For_Soft_Delete_Entities_ById()
{
var douglas = await PersonRepository.GetAsync(TestDataBuilder.UserDouglasId);
await PersonRepository.DeleteAsync(douglas.Id);
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();
}
}
[Fact]
public async Task Should_Handle_Deletion_On_Update_For_Soft_Delete_Entities()
{
@ -82,5 +100,27 @@ namespace Volo.Abp.TestApp.Testing
douglas.Phones.ShouldNotBeEmpty();
}
}
[Fact]
public async Task Cascading_Entities_Should_Not_Be_Deleted_When_Soft_Deleting_Entities_ById()
{
var douglas = await PersonRepository.GetAsync(TestDataBuilder.UserDouglasId);
douglas.Phones.ShouldNotBeEmpty();
await PersonRepository.DeleteAsync(douglas.Id);
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();
douglas.Phones.ShouldNotBeEmpty();
}
}
}
}

Loading…
Cancel
Save