@ -2,7 +2,6 @@
using System.Collections.Generic ;
using System.Linq ;
using System.Threading.Tasks ;
using Microsoft.EntityFrameworkCore ;
using Microsoft.Extensions.DependencyInjection ;
using Microsoft.Extensions.DependencyInjection.Extensions ;
using NSubstitute ;
@ -392,6 +391,7 @@ public class Auditing_Tests : AbpAuditingTestBase
x . EntityChanges [ 1 ] . EntityTypeFullName = = typeof ( AppEntityWithValueObject ) . FullName & &
x . EntityChanges [ 2 ] . ChangeType = = EntityChangeType . Deleted & &
x . EntityChanges [ 2 ] . EntityTypeFullName = = typeof ( AppEntityWithValueObjectAddress ) . FullName ) ) ;
AuditingStore . ClearReceivedCalls ( ) ;
#pragma warning restore 4014
using ( var scope = _ auditingManager . BeginScope ( ) )
@ -421,7 +421,7 @@ public class Auditing_Tests : AbpAuditingTestBase
x . EntityChanges [ 1 ] . EntityTypeFullName = = typeof ( AppEntityWithValueObject ) . FullName & &
x . EntityChanges [ 1 ] . PropertyChanges . Count = = 1 & &
x . EntityChanges [ 1 ] . PropertyChanges [ 0 ] . PropertyName = = nameof ( AppEntityWithValueObject . AppEntityWithValueObjectAddress ) ) ) ;
AuditingStore . ClearReceivedCalls ( ) ;
#pragma warning restore 4014
using ( var scope = _ auditingManager . BeginScope ( ) )
@ -439,22 +439,16 @@ public class Auditing_Tests : AbpAuditingTestBase
}
#pragma warning disable 4014
AuditingStore . Received ( ) . SaveAsync ( Arg . Is < AuditLogInfo > ( x = > x . EntityChanges . Count = = 2 & &
x . EntityChanges [ 0 ] . ChangeType = = EntityChangeType . Upda ted & &
AuditingStore . Received ( ) . SaveAsync ( Arg . Is < AuditLogInfo > ( x = > x . EntityChanges . Count = = 1 & &
x . EntityChanges [ 0 ] . ChangeType = = EntityChangeType . Dele ted & &
x . EntityChanges [ 0 ] . EntityTypeFullName = = typeof ( AppEntityWithValueObjectAddress ) . FullName & &
x . EntityChanges [ 0 ] . PropertyChanges . Count = = 1 & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . PropertyName = = nameof ( AppEntityWithValueObjectAddress . Country ) & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . OriginalValue = = "\"England\"" & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . NewValue = = "\"Germany\"" & &
x . EntityChanges [ 1 ] . ChangeType = = EntityChangeType . Updated & &
x . EntityChanges [ 1 ] . EntityTypeFullName = = typeof ( AppEntityWithValueObject ) . FullName ) ) ;
x . EntityChanges [ 0 ] . PropertyChanges . Count = = 2 & &
x . EntityChanges [ 0 ] . PropertyChanges . All ( p = > p . NewValue = = null ) ) ) ;
#pragma warning restore 4014
}
[Fact]
public virtual async Task Should_Write_AuditLog_For_Navigations _Changes ( )
public virtual async Task Should_Write_AuditLog_For_Navigation_Changes ( )
{
var entityId = Guid . NewGuid ( ) ;
var repository = ServiceProvider . GetRequiredService < IBasicRepository < AppEntityWithNavigations , Guid > > ( ) ;
@ -484,6 +478,7 @@ public class Auditing_Tests : AbpAuditingTestBase
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . NewValue = = "\"test full name\"" & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . PropertyName = = nameof ( AppEntityWithNavigations . FullName ) & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . PropertyTypeFullName = = typeof ( string ) . FullName ) ) ;
AuditingStore . ClearReceivedCalls ( ) ;
#pragma warning restore 4014
using ( var scope = _ auditingManager . BeginScope ( ) )
@ -513,6 +508,7 @@ public class Auditing_Tests : AbpAuditingTestBase
x . EntityChanges [ 1 ] . PropertyChanges . Count = = 1 & &
x . EntityChanges [ 1 ] . PropertyChanges [ 0 ] . PropertyName = = nameof ( AppEntityWithNavigations . OneToOne ) & &
x . EntityChanges [ 1 ] . PropertyChanges [ 0 ] . PropertyTypeFullName = = typeof ( AppEntityWithNavigationChildOneToOne ) . FullName ) ) ;
AuditingStore . ClearReceivedCalls ( ) ;
#pragma warning restore 4014
using ( var scope = _ auditingManager . BeginScope ( ) )
@ -545,7 +541,7 @@ public class Auditing_Tests : AbpAuditingTestBase
x . EntityChanges [ 1 ] . PropertyChanges . Count = = 1 & &
x . EntityChanges [ 1 ] . PropertyChanges [ 0 ] . PropertyName = = nameof ( AppEntityWithNavigations . OneToMany ) & &
x . EntityChanges [ 1 ] . PropertyChanges [ 0 ] . PropertyTypeFullName = = typeof ( List < AppEntityWithNavigationChildOneToMany > ) . FullName ) ) ;
AuditingStore . ClearReceivedCalls ( ) ;
#pragma warning restore 4014
using ( var scope = _ auditingManager . BeginScope ( ) )
@ -604,3 +600,234 @@ public class Auditing_DisableLogActionInfo_Tests : Auditing_Tests
await AuditingStore . Received ( ) . SaveAsync ( Arg . Is < AuditLogInfo > ( x = > x . Actions . IsNullOrEmpty ( ) ) ) ;
}
}
public class Auditing_SaveEntityHistoryWhenNavigationChanges_Tests : AbpAuditingTestBase
{
protected IAuditingStore AuditingStore ;
private IAuditingManager _ auditingManager ;
private IUnitOfWorkManager _ unitOfWorkManager ;
public Auditing_SaveEntityHistoryWhenNavigationChanges_Tests ( )
{
_ auditingManager = GetRequiredService < IAuditingManager > ( ) ;
_ unitOfWorkManager = GetRequiredService < IUnitOfWorkManager > ( ) ;
}
protected override void AfterAddApplication ( IServiceCollection services )
{
AuditingStore = Substitute . For < IAuditingStore > ( ) ;
services . Replace ( ServiceDescriptor . Singleton ( AuditingStore ) ) ;
services . Configure < AbpAuditingOptions > ( options = >
{
options . SaveEntityHistoryWhenNavigationChanges = false ;
} ) ;
}
[Fact]
public virtual async Task Should_Write_AuditLog_For_ValueObject_Entity ( )
{
var entityId = Guid . NewGuid ( ) ;
var repository = ServiceProvider . GetRequiredService < IBasicRepository < AppEntityWithValueObject , Guid > > ( ) ;
await repository . InsertAsync ( new AppEntityWithValueObject ( entityId , "test name" , new AppEntityWithValueObjectAddress ( "USA" ) ) ) ;
using ( var scope = _ auditingManager . BeginScope ( ) )
{
using ( var uow = _ unitOfWorkManager . Begin ( ) )
{
var entity = await repository . GetAsync ( entityId ) ;
entity . Name = "test name 2" ;
entity . AppEntityWithValueObjectAddress = new AppEntityWithValueObjectAddress ( "England" ) ;
await repository . UpdateAsync ( entity ) ;
await uow . CompleteAsync ( ) ;
await scope . SaveAsync ( ) ;
}
}
#pragma warning disable 4014
AuditingStore . Received ( ) . SaveAsync ( Arg . Is < AuditLogInfo > ( x = > x . EntityChanges . Count = = 3 & &
x . EntityChanges [ 0 ] . ChangeType = = EntityChangeType . Created & &
x . EntityChanges [ 0 ] . EntityTypeFullName = = typeof ( AppEntityWithValueObjectAddress ) . FullName & &
x . EntityChanges [ 1 ] . ChangeType = = EntityChangeType . Updated & &
x . EntityChanges [ 1 ] . EntityTypeFullName = = typeof ( AppEntityWithValueObject ) . FullName & &
x . EntityChanges [ 2 ] . ChangeType = = EntityChangeType . Deleted & &
x . EntityChanges [ 2 ] . EntityTypeFullName = = typeof ( AppEntityWithValueObjectAddress ) . FullName ) ) ;
AuditingStore . ClearReceivedCalls ( ) ;
#pragma warning restore 4014
using ( var scope = _ auditingManager . BeginScope ( ) )
{
using ( var uow = _ unitOfWorkManager . Begin ( ) )
{
var entity = await repository . GetAsync ( entityId ) ;
entity . AppEntityWithValueObjectAddress . Country = "Germany" ;
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 ] . ChangeType = = EntityChangeType . Updated & &
x . EntityChanges [ 0 ] . EntityTypeFullName = = typeof ( AppEntityWithValueObjectAddress ) . FullName & &
x . EntityChanges [ 0 ] . PropertyChanges . Count = = 1 & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . PropertyName = = nameof ( AppEntityWithValueObjectAddress . Country ) & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . OriginalValue = = "\"England\"" & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . NewValue = = "\"Germany\"" ) ) ;
AuditingStore . ClearReceivedCalls ( ) ;
#pragma warning restore 4014
using ( var scope = _ auditingManager . BeginScope ( ) )
{
using ( var uow = _ unitOfWorkManager . Begin ( ) )
{
var entity = await repository . GetAsync ( entityId ) ;
entity . AppEntityWithValueObjectAddress = null ;
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 ] . ChangeType = = EntityChangeType . Deleted & &
x . EntityChanges [ 0 ] . EntityTypeFullName = = typeof ( AppEntityWithValueObjectAddress ) . FullName & &
x . EntityChanges [ 0 ] . PropertyChanges . Count = = 2 & &
x . EntityChanges [ 0 ] . PropertyChanges . All ( p = > p . NewValue = = null ) ) ) ;
#pragma warning restore 4014
}
[Fact]
public virtual async Task Should_Not_Write_AuditLog_For_Navigation_Changes ( )
{
var entityId = Guid . NewGuid ( ) ;
var repository = ServiceProvider . GetRequiredService < IBasicRepository < AppEntityWithNavigations , Guid > > ( ) ;
await repository . InsertAsync ( new AppEntityWithNavigations ( entityId , "test name" ) ) ;
using ( var scope = _ auditingManager . BeginScope ( ) )
{
using ( var uow = _ unitOfWorkManager . Begin ( ) )
{
var entity = await repository . GetAsync ( entityId ) ;
entity . FullName = "test full name" ;
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 ] . ChangeType = = EntityChangeType . Updated & &
x . EntityChanges [ 0 ] . EntityTypeFullName = = typeof ( AppEntityWithNavigations ) . FullName & &
x . EntityChanges [ 0 ] . PropertyChanges . Count = = 1 & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . OriginalValue = = "\"test name\"" & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . NewValue = = "\"test full name\"" & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . PropertyName = = nameof ( AppEntityWithNavigations . FullName ) & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . PropertyTypeFullName = = typeof ( string ) . FullName ) ) ;
AuditingStore . ClearReceivedCalls ( ) ;
#pragma warning restore 4014
using ( var scope = _ auditingManager . BeginScope ( ) )
{
using ( var uow = _ unitOfWorkManager . Begin ( ) )
{
var entity = await repository . GetAsync ( entityId ) ;
entity . OneToOne = new AppEntityWithNavigationChildOneToOne
{
ChildName = "ChildName"
} ;
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 ] . ChangeType = = EntityChangeType . Created & &
x . EntityChanges [ 0 ] . EntityTypeFullName = = typeof ( AppEntityWithNavigationChildOneToOne ) . FullName & &
x . EntityChanges [ 0 ] . PropertyChanges . Count = = 1 & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . PropertyName = = nameof ( AppEntityWithNavigationChildOneToOne . ChildName ) & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . PropertyTypeFullName = = typeof ( string ) . FullName ) ) ;
AuditingStore . ClearReceivedCalls ( ) ;
#pragma warning restore 4014
using ( var scope = _ auditingManager . BeginScope ( ) )
{
using ( var uow = _ unitOfWorkManager . Begin ( ) )
{
var entity = await repository . GetAsync ( entityId ) ;
entity . OneToMany = new List < AppEntityWithNavigationChildOneToMany > ( )
{
new AppEntityWithNavigationChildOneToMany
{
AppEntityWithNavigationId = entity . Id ,
ChildName = "ChildName1"
}
} ;
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 ] . ChangeType = = EntityChangeType . Created & &
x . EntityChanges [ 0 ] . EntityTypeFullName = = typeof ( AppEntityWithNavigationChildOneToMany ) . FullName & &
x . EntityChanges [ 0 ] . PropertyChanges . Count = = 2 & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . PropertyName = = nameof ( AppEntityWithNavigationChildOneToMany . AppEntityWithNavigationId ) & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . PropertyTypeFullName = = typeof ( Guid ) . FullName & &
x . EntityChanges [ 0 ] . PropertyChanges [ 1 ] . PropertyName = = nameof ( AppEntityWithNavigationChildOneToMany . ChildName ) & &
x . EntityChanges [ 0 ] . PropertyChanges [ 1 ] . PropertyTypeFullName = = typeof ( string ) . FullName ) ) ;
AuditingStore . ClearReceivedCalls ( ) ;
#pragma warning restore 4014
using ( var scope = _ auditingManager . BeginScope ( ) )
{
using ( var uow = _ unitOfWorkManager . Begin ( ) )
{
var entity = await repository . GetAsync ( entityId ) ;
entity . ManyToMany = new List < AppEntityWithNavigationChildManyToMany > ( )
{
new AppEntityWithNavigationChildManyToMany
{
ChildName = "ChildName1"
}
} ;
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 ] . ChangeType = = EntityChangeType . Created & &
x . EntityChanges [ 0 ] . EntityTypeFullName = = typeof ( AppEntityWithNavigationChildManyToMany ) . FullName & &
x . EntityChanges [ 0 ] . PropertyChanges . Count = = 1 & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . PropertyName = = nameof ( AppEntityWithNavigationChildManyToMany . ChildName ) & &
x . EntityChanges [ 0 ] . PropertyChanges [ 0 ] . PropertyTypeFullName = = typeof ( string ) . FullName ) ) ;
#pragma warning restore 4014
}
}