diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EntityHistory/EntityHistoryHelper.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EntityHistory/EntityHistoryHelper.cs index 89734566cd..155e639bff 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EntityHistory/EntityHistoryHelper.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EntityHistory/EntityHistoryHelper.cs @@ -265,8 +265,7 @@ namespace Volo.Abp.EntityFrameworkCore.EntityHistory } } - var isModified = !(propertyEntry.OriginalValue?.Equals(propertyEntry.CurrentValue) ?? propertyEntry.CurrentValue == null); - if (isModified) + if (propertyEntry.IsModified) { return true; } diff --git a/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/AbpAuditingTestBase.cs b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/AbpAuditingTestBase.cs index 29e1f10d80..6d61ea10e5 100644 --- a/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/AbpAuditingTestBase.cs +++ b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/AbpAuditingTestBase.cs @@ -2,7 +2,6 @@ namespace Volo.Abp.Auditing { - public class AbpAuditingTestBase : AbpIntegratedTest { protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) diff --git a/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/App/Entities/AppEntityWithAuditedAndPropertyHasDisableAuditing.cs b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/App/Entities/AppEntityWithAuditedAndPropertyHasDisableAuditing.cs new file mode 100644 index 0000000000..c35372a688 --- /dev/null +++ b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/App/Entities/AppEntityWithAuditedAndPropertyHasDisableAuditing.cs @@ -0,0 +1,26 @@ +using System; +using Volo.Abp.Domain.Entities; + +namespace Volo.Abp.Auditing.App.Entities +{ + [Audited] + public class AppEntityWithAuditedAndPropertyHasDisableAuditing : AggregateRoot + { + protected AppEntityWithAuditedAndPropertyHasDisableAuditing() + { + + } + + public AppEntityWithAuditedAndPropertyHasDisableAuditing(Guid id, string name, string name2) + : base(id) + { + Name = name; + Name2 = name2; + } + + public string Name { get; set; } + + [DisableAuditing] + public string Name2 { get; set; } + } +} diff --git a/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/App/EntityFrameworkCore/AbpAuditingTestDbContext.cs b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/App/EntityFrameworkCore/AbpAuditingTestDbContext.cs index 46db7afa58..0968bf2cc2 100644 --- a/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/App/EntityFrameworkCore/AbpAuditingTestDbContext.cs +++ b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/App/EntityFrameworkCore/AbpAuditingTestDbContext.cs @@ -8,6 +8,8 @@ namespace Volo.Abp.Auditing.App.EntityFrameworkCore { public DbSet AppEntityWithAudited { get; set; } + public DbSet AppEntityWithAuditedAndPropertyHasDisableAuditing { get; set; } + public DbSet AppEntityWithDisableAuditing { get; set; } public DbSet AppEntityWithDisableAuditingAndPropertyHasAudited { get; set; } diff --git a/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/Auditing_Tests.cs b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/Auditing_Tests.cs index 524a1f359c..bc41f3bcde 100644 --- a/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/Auditing_Tests.cs +++ b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/Auditing_Tests.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -88,6 +89,24 @@ namespace Volo.Abp.Auditing #pragma warning restore 4014 } + [Fact] + public virtual async Task Should_Not_Write_AuditLog_For_Property_That_Has_DisableAuditing_Attribute() + { + using (var scope = _auditingManager.BeginScope()) + { + var repository = ServiceProvider.GetRequiredService>(); + await repository.InsertAsync(new AppEntityWithAuditedAndPropertyHasDisableAuditing(Guid.NewGuid(), "test name", "test name2")).ConfigureAwait(false); + await scope.SaveAsync().ConfigureAwait(false); + } + +#pragma warning disable 4014 + _auditingStore.Received().SaveAsync(Arg.Is(x => + x.EntityChanges.Count == 1 && + !(x.EntityChanges[0].PropertyChanges.Any(p => + p.PropertyName == nameof(AppEntityWithDisableAuditingAndPropertyHasAudited.Name2))))); +#pragma warning restore 4014 + } + [Fact] public virtual async Task Should_Not_Write_AuditLog_For_Entity_That_Has_DisableAuditing_Attribute() {