Browse Source

Merge pull request #3794 from abpframework/maliming/audit-revert

Compare the value of the property to determine whether it is changed.
pull/3809/head
Halil İbrahim Kalkan 7 years ago
committed by GitHub
parent
commit
2ac4ab108c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EntityHistory/EntityHistoryHelper.cs
  2. 6
      framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/App/Entities/AppEntityWithDisableAuditingAndPropertyHasAudited.cs
  3. 39
      framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/Auditing_Tests.cs

5
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/EntityHistory/EntityHistoryHelper.cs

@ -32,7 +32,7 @@ namespace Volo.Abp.EntityFrameworkCore.EntityHistory
IAuditingStore auditingStore, IAuditingStore auditingStore,
IOptions<AbpAuditingOptions> options, IOptions<AbpAuditingOptions> options,
IClock clock, IClock clock,
IJsonSerializer jsonSerializer, IJsonSerializer jsonSerializer,
IAuditingHelper auditingHelper) IAuditingHelper auditingHelper)
{ {
_clock = clock; _clock = clock;
@ -241,7 +241,8 @@ namespace Volo.Abp.EntityFrameworkCore.EntityHistory
} }
} }
if (propertyEntry.IsModified) var isModified = !(propertyEntry.OriginalValue?.Equals(propertyEntry.CurrentValue) ?? propertyEntry.CurrentValue == null);
if (isModified)
{ {
return true; return true;
} }

6
framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/App/Entities/AppEntityWithDisableAuditingAndPropertyHasAudited.cs

@ -11,16 +11,20 @@ namespace Volo.Abp.Auditing.App.Entities
} }
public AppEntityWithDisableAuditingAndPropertyHasAudited(Guid id, string name, string name2) public AppEntityWithDisableAuditingAndPropertyHasAudited(Guid id, string name, string name2, string name3)
: base(id) : base(id)
{ {
Name = name; Name = name;
Name2 = name2; Name2 = name2;
Name3 = name3;
} }
[Audited] [Audited]
public string Name { get; set; } public string Name { get; set; }
public string Name2 { get; set; } public string Name2 { get; set; }
[Audited]
public string Name3 { get; set; }
} }
} }

39
framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/Auditing_Tests.cs

@ -7,6 +7,7 @@ using NSubstitute;
using Volo.Abp.Auditing.App.Entities; using Volo.Abp.Auditing.App.Entities;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
using Volo.Abp.Uow;
using Xunit; using Xunit;
namespace Volo.Abp.Auditing namespace Volo.Abp.Auditing
@ -15,10 +16,12 @@ namespace Volo.Abp.Auditing
{ {
private IAuditingStore _auditingStore; private IAuditingStore _auditingStore;
private IAuditingManager _auditingManager; private IAuditingManager _auditingManager;
private IUnitOfWorkManager _unitOfWorkManager;
public Auditing_Tests() public Auditing_Tests()
{ {
_auditingManager = GetRequiredService<IAuditingManager>(); _auditingManager = GetRequiredService<IAuditingManager>();
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
} }
protected override void AfterAddApplication(IServiceCollection services) protected override void AfterAddApplication(IServiceCollection services)
@ -158,18 +161,46 @@ namespace Volo.Abp.Auditing
using (var scope = _auditingManager.BeginScope()) using (var scope = _auditingManager.BeginScope())
{ {
var repository = ServiceProvider.GetRequiredService<IBasicRepository<AppEntityWithDisableAuditingAndPropertyHasAudited, Guid>>(); var repository = ServiceProvider.GetRequiredService<IBasicRepository<AppEntityWithDisableAuditingAndPropertyHasAudited, Guid>>();
await repository.InsertAsync(new AppEntityWithDisableAuditingAndPropertyHasAudited(Guid.NewGuid(), "test name", "test name2")); await repository.InsertAsync(new AppEntityWithDisableAuditingAndPropertyHasAudited(Guid.NewGuid(), "test name", "test name2", "test name3"));
await scope.SaveAsync(); await scope.SaveAsync();
} }
#pragma warning disable 4014 #pragma warning disable 4014
_auditingStore.Received().SaveAsync(Arg.Is<AuditLogInfo>(x => _auditingStore.Received().SaveAsync(Arg.Is<AuditLogInfo>(x =>
x.EntityChanges.Count == 1 && x.EntityChanges[0].PropertyChanges.Count == 1 && x.EntityChanges.Count == 1 && x.EntityChanges[0].PropertyChanges.Count == 2 &&
x.EntityChanges[0].PropertyChanges[0].PropertyName == x.EntityChanges[0].PropertyChanges[0].PropertyName == nameof(AppEntityWithDisableAuditingAndPropertyHasAudited.Name) &&
nameof(AppEntityWithDisableAuditingAndPropertyHasAudited.Name))); x.EntityChanges[0].PropertyChanges[1].PropertyName == nameof(AppEntityWithDisableAuditingAndPropertyHasAudited.Name3)));
#pragma warning restore 4014 #pragma warning restore 4014
} }
[Fact]
public virtual async Task Should_Write_AuditLog_For_Entity_That_Property_Has_Audited_Attribute_And_Has_Changed_Even_Entity_Has_DisableAuditing_Attribute()
{
var entityId = Guid.NewGuid();
var repository = ServiceProvider.GetRequiredService<IBasicRepository<AppEntityWithDisableAuditingAndPropertyHasAudited, Guid>>();
await repository.InsertAsync(new AppEntityWithDisableAuditingAndPropertyHasAudited(entityId, "test name", "test name2", "test name3"));
using (var scope = _auditingManager.BeginScope())
{
using (var uow = _unitOfWorkManager.Begin())
{
var entity = await repository.GetAsync(entityId);
entity.Name = "new name1";
await repository.UpdateAsync(entity);
await uow.CompleteAsync();
}
await scope.SaveAsync();
}
#pragma warning disable 4014
_auditingStore.Received().SaveAsync(Arg.Is<AuditLogInfo>(x =>
x.EntityChanges.Count == 1 && x.EntityChanges[0].PropertyChanges.Count == 1 &&
x.EntityChanges[0].PropertyChanges[0].PropertyName == nameof(AppEntityWithDisableAuditingAndPropertyHasAudited.Name)));
#pragma warning restore 4014
}
[Fact] [Fact]
public virtual async Task Should_Write_AuditLog_If_There_No_Action_And_No_EntityChanges() public virtual async Task Should_Write_AuditLog_If_There_No_Action_And_No_EntityChanges()

Loading…
Cancel
Save