|
|
|
@ -1,6 +1,10 @@ |
|
|
|
using System; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
|
|
using NSubstitute; |
|
|
|
using Shouldly; |
|
|
|
using Volo.Abp.Domain.Entities.Events; |
|
|
|
using Volo.Abp.TestApp; |
|
|
|
using Volo.Abp.TestApp.Testing; |
|
|
|
using Xunit; |
|
|
|
@ -9,6 +13,16 @@ namespace Volo.Abp.EntityFrameworkCore.Auditing; |
|
|
|
|
|
|
|
public class Auditing_Tests : Auditing_Tests<AbpEntityFrameworkCoreTestModule> |
|
|
|
{ |
|
|
|
protected IEntityChangeEventHelper EntityChangeEventHelper; |
|
|
|
|
|
|
|
protected override void AfterAddApplication(IServiceCollection services) |
|
|
|
{ |
|
|
|
EntityChangeEventHelper = Substitute.For<IEntityChangeEventHelper>(); |
|
|
|
services.Replace(ServiceDescriptor.Singleton(EntityChangeEventHelper)); |
|
|
|
|
|
|
|
base.AfterAddApplication(services); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_Not_Set_Modification_If_Properties_Generated_By_Database() |
|
|
|
{ |
|
|
|
@ -24,7 +38,6 @@ public class Auditing_Tests : Auditing_Tests<AbpEntityFrameworkCoreTestModule> |
|
|
|
|
|
|
|
douglas.ShouldNotBeNull(); |
|
|
|
douglas.LastModificationTime.ShouldBeNull(); |
|
|
|
douglas.LastModificationTime.ShouldBeNull(); |
|
|
|
douglas.LastModifierId.ShouldBeNull(); |
|
|
|
})); |
|
|
|
} |
|
|
|
@ -71,4 +84,66 @@ public class Auditing_Tests : Auditing_Tests<AbpEntityFrameworkCoreTestModule> |
|
|
|
douglas.LastModifierId.ShouldBe(CurrentUserId); |
|
|
|
})); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_Not_Set_Modification_If_Properties_HasDisableAuditing_UpdateModificationProps() |
|
|
|
{ |
|
|
|
await WithUnitOfWorkAsync((async () => |
|
|
|
{ |
|
|
|
var douglas = await PersonRepository.GetAsync(TestDataBuilder.UserDouglasId); |
|
|
|
douglas.DisableAuditingUpdateModificationPropsProperty = Guid.NewGuid().ToString(); |
|
|
|
})); |
|
|
|
|
|
|
|
await WithUnitOfWorkAsync((async () => |
|
|
|
{ |
|
|
|
var douglas = await PersonRepository.FindAsync(TestDataBuilder.UserDouglasId); |
|
|
|
|
|
|
|
douglas.ShouldNotBeNull(); |
|
|
|
douglas.LastModificationTime.ShouldBeNull(); |
|
|
|
douglas.LastModifierId.ShouldBeNull(); |
|
|
|
})); |
|
|
|
|
|
|
|
EntityChangeEventHelper.Received().PublishEntityUpdatedEvent(Arg.Any<object>()); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_Not_PublishEntityEvent_If_Properties_HasDisableAuditing_PublishEntityEventProperty() |
|
|
|
{ |
|
|
|
await WithUnitOfWorkAsync((async () => |
|
|
|
{ |
|
|
|
var douglas = await PersonRepository.GetAsync(TestDataBuilder.UserDouglasId); |
|
|
|
douglas.DisableAuditingPublishEntityEventProperty = Guid.NewGuid().ToString(); |
|
|
|
})); |
|
|
|
|
|
|
|
await WithUnitOfWorkAsync((async () => |
|
|
|
{ |
|
|
|
var douglas = await PersonRepository.FindAsync(TestDataBuilder.UserDouglasId); |
|
|
|
|
|
|
|
douglas.ShouldNotBeNull(); |
|
|
|
douglas.LastModificationTime.ShouldNotBeNull(); |
|
|
|
})); |
|
|
|
|
|
|
|
EntityChangeEventHelper.DidNotReceive().PublishEntityUpdatedEvent(Arg.Any<object>()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Should_Set_Modification_And_PublishEntityEvent_If_Properties_HasDisableAuditing() |
|
|
|
{ |
|
|
|
await WithUnitOfWorkAsync((async () => |
|
|
|
{ |
|
|
|
var douglas = await PersonRepository.GetAsync(TestDataBuilder.UserDouglasId); |
|
|
|
douglas.DisableAuditingProperty = Guid.NewGuid().ToString(); |
|
|
|
})); |
|
|
|
|
|
|
|
await WithUnitOfWorkAsync((async () => |
|
|
|
{ |
|
|
|
var douglas = await PersonRepository.FindAsync(TestDataBuilder.UserDouglasId); |
|
|
|
|
|
|
|
douglas.ShouldNotBeNull(); |
|
|
|
douglas.LastModificationTime.ShouldNotBeNull(); |
|
|
|
})); |
|
|
|
|
|
|
|
EntityChangeEventHelper.Received().PublishEntityUpdatedEvent(Arg.Any<object>()); |
|
|
|
} |
|
|
|
} |
|
|
|
|