From bd7177ca36c1f9c75af2d1c770ad4cbede383fef Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 19 Jul 2018 10:38:37 +0300 Subject: [PATCH] Added Should_Get_List_Of_Audit_Logs Test --- .../AuditLogging/AuditStore_Basic_Tests.cs | 121 +++++++++++++++++- 1 file changed, 118 insertions(+), 3 deletions(-) diff --git a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs index 7b77349b85..b21df0b025 100644 --- a/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs +++ b/modules/audit-logging/test/Volo.Abp.AuditLogging.TestBase/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Threading.Tasks; using Shouldly; using Volo.Abp.Auditing; @@ -9,7 +10,7 @@ using Xunit; namespace Volo.Abp.AuditLogging { - public abstract class AuditStore_Basic_Tests : AuditLoggingTestBase + public abstract class AuditStore_Basic_Tests : AuditLoggingTestBase where TStartupModule : IAbpModule { private readonly IAuditingStore _auditingStore; @@ -22,7 +23,7 @@ namespace Volo.Abp.AuditLogging } [Fact] - public async Task Should_Save_A_Audit_Log() + public async Task Should_Save_An_Audit_Log() { //Arrange var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); @@ -39,7 +40,7 @@ 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 @@ -76,5 +77,119 @@ namespace Volo.Abp.AuditLogging insertedLog.EntityChanges.Count.ShouldBeGreaterThan(0); insertedLog.EntityChanges.First().PropertyChanges.Count.ShouldBeGreaterThan(0); } + + + [Fact] + public async Task Should_Get_List_Of_Audit_Logs() + { + var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var ipAddress = "153.1.7.61"; + var firstComment = "first Comment"; + + var log1 = new AuditLogInfo + { + UserId = userId, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + UserName = "Douglas", + EntityChanges = { + new EntityChangeInfo + { + EntityId = Guid.NewGuid().ToString(), + EntityTypeFullName = "Volo.Abp.AuditLogging.TestEntity", + ChangeType = EntityChangeType.Created, + ChangeTime = DateTime.Now, + PropertyChanges = new List + { + new EntityPropertyChangeInfo + { + PropertyTypeFullName = typeof(string).FullName, + PropertyName = "Name", + NewValue = "New value", + OriginalValue = null + } + } + }, + new EntityChangeInfo + { + EntityId = Guid.NewGuid().ToString(), + EntityTypeFullName = "Volo.Abp.AuditLogging.TestEntity", + ChangeType = EntityChangeType.Created, + ChangeTime = DateTime.Now, + PropertyChanges = new List + { + new EntityPropertyChangeInfo + { + PropertyTypeFullName = typeof(string).FullName, + PropertyName = "Name", + NewValue = "New value", + OriginalValue = null + } + } + } + + } + }; + + var log2 = new AuditLogInfo + { + UserId = userId, + ImpersonatorUserId = Guid.NewGuid(), + ImpersonatorTenantId = Guid.NewGuid(), + ExecutionTime = DateTime.Today, + ExecutionDuration = 42, + ClientIpAddress = ipAddress, + ClientName = "MyDesktop", + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment" }, + HttpStatusCode = (int?)HttpStatusCode.BadGateway, + EntityChanges = { + new EntityChangeInfo + { + EntityId = Guid.NewGuid().ToString(), + EntityTypeFullName = "Volo.Abp.AuditLogging.TestEntity", + ChangeType = EntityChangeType.Created, + ChangeTime = DateTime.Now, + PropertyChanges = new List + { + new EntityPropertyChangeInfo + { + PropertyTypeFullName = typeof(string).FullName, + PropertyName = "Name", + NewValue = "New value", + OriginalValue = null + } + } + } + + } + }; + + await _auditingStore.SaveAsync(log1); + await _auditingStore.SaveAsync(log2); + + var allLogsCount = await _auditLogRepository.GetCountAsync(); + + var onlyLog1QueryResult = await _auditLogRepository.GetListAsync(includeDetails: true, userName: "Douglas"); + + var onlyLog2QueryResult = await _auditLogRepository.GetListAsync(includeDetails: true, httpStatusCode: HttpStatusCode.BadGateway); + + + allLogsCount.ShouldBe(2); + + onlyLog1QueryResult.Count.ShouldBe(1); + onlyLog1QueryResult.FirstOrDefault().UserName.ShouldBe("Douglas"); + onlyLog1QueryResult.FirstOrDefault().EntityChanges.Count.ShouldBe(2); + + onlyLog2QueryResult.Count.ShouldBe(1); + onlyLog2QueryResult.FirstOrDefault().HttpStatusCode.ShouldBe((int?)HttpStatusCode.BadGateway); + onlyLog2QueryResult.FirstOrDefault().EntityChanges.Count.ShouldBe(1); + } } }