From 6e3f53b1a1846cdcd9fca76389a170a5f997fd7e Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Tue, 10 Jul 2018 16:49:46 +0300 Subject: [PATCH] audit logging module unit-test (bugged atm) --- .../Abp/AuditLogging/AuditLogsTestBase.cs | 2 +- .../AuditLogging/AuditStore_Basic_Tests.cs | 23 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) 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 5757dafabe..43a3061cdb 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 @@ -23,7 +23,7 @@ namespace Volo.Abp.AuditLogging } } - protected List GetSAuditLogsFromDbContext() + protected List GetAuditLogsFromDbContext() { return UsingDbContext(context => context.AuditLogs.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 76bc51d00b..13ddb37b64 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 @@ -1,5 +1,8 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; +using Shouldly; using Volo.Abp.Auditing; using Xunit; @@ -18,24 +21,34 @@ namespace Volo.Abp.AuditLogging public async Task Should_Save_A_Audit_Log() { //Arrange - var auditLog = new AuditLogInfo() + var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06"); + var ipAddress = "153.1.7.61"; + var firstComment = "first Comment"; + + var auditLog = new AuditLogInfo { TenantId = Guid.NewGuid(), - UserId = Guid.NewGuid(), + UserId = userId, ImpersonatorUserId = Guid.NewGuid(), ImpersonatorTenantId = Guid.NewGuid(), ExecutionTime = DateTime.Today, ExecutionDuration = 42, - ClientIpAddress = "153.1.7.61", + ClientIpAddress = ipAddress, ClientName = "MyDesktop", - BrowserInfo = "Chrome" + BrowserInfo = "Chrome", + Comments = new List { firstComment, "Second Comment"} }; //Act await _auditingStore.SaveAsync(auditLog); //Assert - //TODO:... + + var insertedLog = GetAuditLogsFromDbContext().FirstOrDefault(al => al.UserId == userId); + + insertedLog.ShouldNotBeNull(); + insertedLog.ClientIpAddress.ShouldBe(ipAddress); + insertedLog.Comments.ShouldStartWith(firstComment); } } }