From 8aa48e7644da3e811569033ad73f50caa76fd703 Mon Sep 17 00:00:00 2001 From: enisn Date: Wed, 27 Jan 2021 13:17:55 +0300 Subject: [PATCH] Framework - Add DeleteMany Tests to HardDelete_Tests --- .../Abp/TestApp/Testing/HardDelete_Tests.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/HardDelete_Tests.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/HardDelete_Tests.cs index 3d9b324da8..e31b64f6e4 100644 --- a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/HardDelete_Tests.cs +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/HardDelete_Tests.cs @@ -1,7 +1,9 @@ using Shouldly; using System; +using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp.Data; +using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; using Volo.Abp.Modularity; using Volo.Abp.TestApp.Domain; @@ -119,5 +121,40 @@ namespace Volo.Abp.TestApp.Testing john.ShouldBeNull(); } } + + [Fact] + public async Task Should_HardDelete_WithDeleteMany() + { + var persons = await PersonRepository.GetListAsync(); + + await WithUnitOfWorkAsync(async () => + { + var hardDeleteEntities = (HashSet)UnitOfWorkManager.Current.Items.GetOrAdd( + UnitOfWorkItemNames.HardDeletedEntities, + () => new HashSet() + ); + hardDeleteEntities.UnionWith(persons); + await PersonRepository.DeleteManyAsync(persons); + }); + + var personsCount = await PersonRepository.GetCountAsync(); + + personsCount.ShouldBe(0); + } + + [Fact] + public async Task Should_HardDelete_WithDeleteMany_WithPredicate() + { + await WithUnitOfWorkAsync(async () => + { + await PersonRepository.HardDeleteAsync(x => x.Id == TestDataBuilder.UserDouglasId); + + await PersonRepository.DeleteManyAsync(new[] { TestDataBuilder.UserDouglasId }); + }); + + var douglas = await PersonRepository.FindAsync(TestDataBuilder.UserDouglasId); + + douglas.ShouldBeNull(); + } } }