|
|
|
@ -764,7 +764,7 @@ namespace Volo.Abp.AuditLogging
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetEntityHistoryAsync()
|
|
|
|
|
public async Task GetEntityChangesWithUsernameAsync()
|
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06");
|
|
|
|
@ -868,7 +868,7 @@ namespace Volo.Abp.AuditLogging
|
|
|
|
|
await AuditLogRepository.InsertAsync(new AuditLog(GuidGenerator, log2));
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
var entityHistory = await AuditLogRepository.GetEntityHistoriesAsync(entityId, entityType);
|
|
|
|
|
var entityHistory = await AuditLogRepository.GetEntityChangesWithUsernameAsync(entityId, entityType);
|
|
|
|
|
|
|
|
|
|
entityHistory.Count.ShouldBe(2);
|
|
|
|
|
var firstUserChange = entityHistory.First(x => x.UserName == firstUser);
|
|
|
|
@ -881,5 +881,110 @@ namespace Volo.Abp.AuditLogging
|
|
|
|
|
secondUserChange.EntityChange.ShouldNotBeNull();
|
|
|
|
|
secondUserChange.EntityChange.ChangeType.ShouldBe(EntityChangeType.Updated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetEntityChangeWithUsernameAsync()
|
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
var userId = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06");
|
|
|
|
|
var userId2 = 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<string> { firstComment, "Second Comment" },
|
|
|
|
|
UserName = "Douglas",
|
|
|
|
|
EntityChanges = {
|
|
|
|
|
new EntityChangeInfo
|
|
|
|
|
{
|
|
|
|
|
EntityId = Guid.NewGuid().ToString(),
|
|
|
|
|
EntityTypeFullName = "Volo.Abp.AuditLogging.TestEntity_Deleted",
|
|
|
|
|
ChangeType = EntityChangeType.Deleted,
|
|
|
|
|
ChangeTime = new DateTime(1995, 3, 27),
|
|
|
|
|
PropertyChanges = new List<EntityPropertyChangeInfo>
|
|
|
|
|
{
|
|
|
|
|
new EntityPropertyChangeInfo
|
|
|
|
|
{
|
|
|
|
|
PropertyTypeFullName = typeof(string).FullName,
|
|
|
|
|
PropertyName = "Name",
|
|
|
|
|
NewValue = "New value",
|
|
|
|
|
OriginalValue = null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new EntityChangeInfo
|
|
|
|
|
{
|
|
|
|
|
EntityId = Guid.NewGuid().ToString(),
|
|
|
|
|
EntityTypeFullName = "Volo.Abp.AuditLogging.TestEntity_Created",
|
|
|
|
|
ChangeType = EntityChangeType.Created,
|
|
|
|
|
ChangeTime = DateTime.Now,
|
|
|
|
|
PropertyChanges = new List<EntityPropertyChangeInfo>
|
|
|
|
|
{
|
|
|
|
|
new EntityPropertyChangeInfo
|
|
|
|
|
{
|
|
|
|
|
PropertyTypeFullName = typeof(string).FullName,
|
|
|
|
|
PropertyName = "Name",
|
|
|
|
|
NewValue = "New value",
|
|
|
|
|
OriginalValue = null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var log2 = new AuditLogInfo
|
|
|
|
|
{
|
|
|
|
|
UserId = userId2,
|
|
|
|
|
ImpersonatorUserId = Guid.NewGuid(),
|
|
|
|
|
ImpersonatorTenantId = Guid.NewGuid(),
|
|
|
|
|
ExecutionTime = DateTime.Today,
|
|
|
|
|
ExecutionDuration = 42,
|
|
|
|
|
ClientIpAddress = ipAddress,
|
|
|
|
|
ClientName = "MyDesktop",
|
|
|
|
|
BrowserInfo = "Chrome",
|
|
|
|
|
Comments = new List<string> { firstComment, "Second Comment" },
|
|
|
|
|
HttpStatusCode = (int?)HttpStatusCode.BadGateway,
|
|
|
|
|
UserName = "John Doe",
|
|
|
|
|
EntityChanges = {
|
|
|
|
|
new EntityChangeInfo
|
|
|
|
|
{
|
|
|
|
|
EntityId = Guid.NewGuid().ToString(),
|
|
|
|
|
EntityTypeFullName = "Volo.Abp.AuditLogging.TestEntity_Updated",
|
|
|
|
|
ChangeType = EntityChangeType.Updated,
|
|
|
|
|
ChangeTime = DateTime.Now,
|
|
|
|
|
PropertyChanges = new List<EntityPropertyChangeInfo>
|
|
|
|
|
{
|
|
|
|
|
new EntityPropertyChangeInfo
|
|
|
|
|
{
|
|
|
|
|
PropertyTypeFullName = typeof(string).FullName,
|
|
|
|
|
PropertyName = "Name",
|
|
|
|
|
NewValue = "New value",
|
|
|
|
|
OriginalValue = null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await AuditLogRepository.InsertAsync(new AuditLog(GuidGenerator, log1));
|
|
|
|
|
await AuditLogRepository.InsertAsync(new AuditLog(GuidGenerator, log2));
|
|
|
|
|
|
|
|
|
|
var entityChanges = await AuditLogRepository.GetEntityChangeListAsync();
|
|
|
|
|
var entityHistory =
|
|
|
|
|
await AuditLogRepository.GetEntityChangeWithUsernameAsync(entityChanges.First().Id);
|
|
|
|
|
|
|
|
|
|
entityHistory.EntityChange.ChangeTime.ShouldBe(entityChanges.First().ChangeTime);
|
|
|
|
|
entityHistory.UserName.ShouldNotBeNull();;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|