Skip to content

Commit

Permalink
Merge branch 'rel-8.3' of https://github.com/abpframework/abp into re…
Browse files Browse the repository at this point in the history
…l-8.3
  • Loading branch information
voloagent committed Sep 5, 2024
2 parents 0960a48 + 72e9d43 commit 2693956
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,19 @@ protected virtual void ApplyAbpConceptsForDeletedEntity(EntityEntry entry)
return;
}

ExtraPropertyDictionary? originalExtraProperties = null;
if (entry.Entity is IHasExtraProperties)
{
originalExtraProperties = entry.OriginalValues.GetValue<ExtraPropertyDictionary>(nameof(IHasExtraProperties.ExtraProperties));
}

entry.Reload();

if (entry.Entity is IHasExtraProperties)
{
ObjectHelper.TrySetProperty(entry.Entity.As<IHasExtraProperties>(), x => x.ExtraProperties, () => originalExtraProperties);
}

ObjectHelper.TrySetProperty(entry.Entity.As<ISoftDelete>(), x => x.IsDeleted, () => true);
SetDeletionAuditProperties(entry);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Data;
using Volo.Abp.Domain.Repositories;
Expand Down Expand Up @@ -59,6 +60,27 @@ await WithUnitOfWorkAsync(async () =>
});
}

[Fact]
public async Task Should_Get_An_Extra_Property_After_Soft_Deletion()
{
var london = await CityRepository.FindByNameAsync("London");
london.HasProperty("PhoneCode").ShouldBeTrue();
london.GetProperty<string>("PhoneCode").ShouldBe("42");

await CityRepository.DeleteAsync(london);

london = await CityRepository.FindByNameAsync("London");
london.ShouldBeNull();

using (var uow = ServiceProvider.GetRequiredService<IDataFilter>().Disable<ISoftDelete>())
{
london = await CityRepository.FindByNameAsync("London");
london.IsDeleted.ShouldBeTrue();
london.HasProperty("PhoneCode").ShouldBeTrue();
london.GetProperty<string>("PhoneCode").ShouldBe("42");
}
}

public enum Color
{
Red = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

namespace Volo.Abp.TestApp.Domain;

public class City : AggregateRoot<Guid>
public class City : AggregateRoot<Guid>, ISoftDelete
{
public string Name { get; set; }

public ICollection<District> Districts { get; set; }

public bool IsDeleted { get; set; }

private City()
{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Modularity;
using Volo.Abp.TestApp.Domain;
using Xunit;
Expand Down Expand Up @@ -49,7 +50,7 @@ public async Task Should_Not_Allow_To_Delete_If_The_Entity_Has_Changed()
//And deleting my old entity throws exception!
await Assert.ThrowsAsync<AbpDbConcurrencyException>(async () =>
{
await CityRepository.DeleteAsync(london1);
await CityRepository.HardDeleteAsync(london1);
});
}
}

0 comments on commit 2693956

Please sign in to comment.