Browse Source

Made unit test working.

pull/395/head
Halil ibrahim Kalkan 8 years ago
parent
commit
e56f7d52cf
  1. 3
      modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditingStore.cs
  2. 6
      modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/AbpAuditLoggingEfCoreQueryableExtensions.cs
  3. 2
      modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditLogsTestBase.cs
  4. 28
      modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditStore_Basic_Tests.cs

3
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)) 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(); await uow.SaveChangesAsync();
} }
} }

6
modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/AbpAuditLoggingEfCoreQueryableExtensions.cs

@ -1,7 +1,4 @@
using System; using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Volo.Abp.AuditLogging namespace Volo.Abp.AuditLogging
@ -21,6 +18,5 @@ namespace Volo.Abp.AuditLogging
.Include(x => x.Actions) .Include(x => x.Actions)
.Include(x => x.EntityChanges).ThenInclude(ec=>ec.PropertyChanges); .Include(x => x.EntityChanges).ThenInclude(ec=>ec.PropertyChanges);
} }
} }
} }

2
modules/audit-logging/test/Volo.Abp.AuditLogging.Tests/Volo/Abp/AuditLogging/AuditLogsTestBase.cs

@ -26,7 +26,7 @@ namespace Volo.Abp.AuditLogging
protected List<AuditLog> GetAuditLogsFromDbContext() protected List<AuditLog> GetAuditLogsFromDbContext()
{ {
return UsingDbContext(context => return UsingDbContext(context =>
context.AuditLogs.ToList() context.AuditLogs.IncludeDetails().ToList()
); );
} }
} }

28
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 var auditLog = new AuditLogInfo
{ {
TenantId = Guid.NewGuid(),
UserId = userId, UserId = userId,
ImpersonatorUserId = Guid.NewGuid(), ImpersonatorUserId = Guid.NewGuid(),
ImpersonatorTenantId = Guid.NewGuid(), ImpersonatorTenantId = Guid.NewGuid(),
@ -36,7 +35,27 @@ namespace Volo.Abp.AuditLogging
ClientIpAddress = ipAddress, ClientIpAddress = ipAddress,
ClientName = "MyDesktop", ClientName = "MyDesktop",
BrowserInfo = "Chrome", BrowserInfo = "Chrome",
Comments = new List<string> { firstComment, "Second Comment"} Comments = new List<string> { 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<EntityPropertyChangeInfo>
{
new EntityPropertyChangeInfo
{
PropertyTypeFullName = typeof(string).FullName,
PropertyName = "Name",
NewValue = "New value",
OriginalValue = null
}
}
}
}
}; };
//Act //Act
@ -44,11 +63,14 @@ namespace Volo.Abp.AuditLogging
//Assert //Assert
var insertedLog = GetAuditLogsFromDbContext().FirstOrDefault(al => al.UserId == userId); var insertedLog = GetAuditLogsFromDbContext()
.FirstOrDefault(al => al.UserId == userId);
insertedLog.ShouldNotBeNull(); insertedLog.ShouldNotBeNull();
insertedLog.ClientIpAddress.ShouldBe(ipAddress); insertedLog.ClientIpAddress.ShouldBe(ipAddress);
insertedLog.Comments.ShouldStartWith(firstComment); insertedLog.Comments.ShouldStartWith(firstComment);
insertedLog.EntityChanges.Count.ShouldBeGreaterThan(0);
insertedLog.EntityChanges.First().PropertyChanges.Count.ShouldBeGreaterThan(0);
} }
} }
} }

Loading…
Cancel
Save