diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs index 9df4620137..59f3ae5431 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs @@ -35,7 +35,8 @@ namespace Volo.Abp.AuditLogging { using (var uow = _unitOfWorkManager.Begin(requiresNew: true)) { - await _auditLogRepository.InsertAsync(new AuditLog(_guidGenerator, auditInfo)); + var auditLog = new AuditLog(_guidGenerator, auditInfo); + await _auditLogRepository.InsertAsync(auditLog); await uow.SaveChangesAsync(); } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/AbpAuditLoggingEfCoreQueryableExtensions.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/AbpAuditLoggingEfCoreQueryableExtensions.cs index 5025b8aa3c..27445045e7 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/AbpAuditLoggingEfCoreQueryableExtensions.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/AbpAuditLoggingEfCoreQueryableExtensions.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Linq; using Microsoft.EntityFrameworkCore; namespace Volo.Abp.AuditLogging @@ -21,6 +18,5 @@ namespace Volo.Abp.AuditLogging .Include(x => x.Actions) .Include(x => x.EntityChanges).ThenInclude(ec=>ec.PropertyChanges); } - } } diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditLogsTestBase.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditLogsTestBase.cs index 43a3061cdb..d505e838d7 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditLogsTestBase.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditLogsTestBase.cs @@ -26,7 +26,7 @@ namespace Volo.Abp.AuditLogging protected List GetAuditLogsFromDbContext() { return UsingDbContext(context => - context.AuditLogs.ToList() + context.AuditLogs.IncludeDetails().ToList() ); } } diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs index 13ddb37b64..bd8891fe17 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs @@ -27,7 +27,6 @@ namespace Volo.Abp.AuditLogging var auditLog = new AuditLogInfo { - TenantId = Guid.NewGuid(), UserId = userId, ImpersonatorUserId = Guid.NewGuid(), ImpersonatorTenantId = Guid.NewGuid(), @@ -36,7 +35,27 @@ namespace Volo.Abp.AuditLogging ClientIpAddress = ipAddress, ClientName = "MyDesktop", BrowserInfo = "Chrome", - Comments = new List { firstComment, "Second Comment"} + Comments = new List { firstComment, "Second Comment"}, + EntityChanges = + { + new EntityChangeInfo + { + EntityId = Guid.NewGuid().ToString(), + EntityTypeFullName = typeof(AuditStore_Basic_Tests).FullName, + ChangeType = EntityChangeType.Created, + ChangeTime = DateTime.Now, + PropertyChanges = new List + { + new EntityPropertyChangeInfo + { + PropertyTypeFullName = typeof(string).FullName, + PropertyName = "Name", + NewValue = "New value", + OriginalValue = null + } + } + } + } }; //Act @@ -44,11 +63,14 @@ namespace Volo.Abp.AuditLogging //Assert - var insertedLog = GetAuditLogsFromDbContext().FirstOrDefault(al => al.UserId == userId); + var insertedLog = GetAuditLogsFromDbContext() + .FirstOrDefault(al => al.UserId == userId); insertedLog.ShouldNotBeNull(); insertedLog.ClientIpAddress.ShouldBe(ipAddress); insertedLog.Comments.ShouldStartWith(firstComment); + insertedLog.EntityChanges.Count.ShouldBeGreaterThan(0); + insertedLog.EntityChanges.First().PropertyChanges.Count.ShouldBeGreaterThan(0); } } }