AuditLogging Repository is updated

pull/3428/head
Ahmet Çotur 6 years ago
parent fd781706e3
commit e389abd82f

@ -46,6 +46,8 @@ namespace Volo.Abp.AuditLogging
DateTime startDate,
DateTime endDate);
Task<EntityChange> GetEntityChange(Guid auditLogId, Guid entityChangeId, bool includeDetails = true);
Task<List<EntityChange>> GetEntityChangeListAsync(
string sorting = null,
int maxResultCount = 50,

@ -135,12 +135,18 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
return result.ToDictionary(element => element.Day.ClearTime(), element => element.avgExecutionTime);
}
public override IQueryable<AuditLog> WithDetails()
{
return GetQueryable().IncludeDetails();
}
public Task<EntityChange> GetEntityChange(Guid auditLogId, Guid entityChangeId, bool includeDetails = true)
{
return DbContext.Set<EntityChange>().AsNoTracking().IncludeDetails(includeDetails)
.Where(x => x.Id == entityChangeId && x.AuditLogId == auditLogId).FirstAsync();
}
public virtual async Task<List<EntityChange>> GetEntityChangeListAsync(
string sorting = null,
int maxResultCount = 50,

@ -140,6 +140,13 @@ namespace Volo.Abp.AuditLogging.MongoDB
return result.ToDictionary(element => element.Day.ClearTime(), element => element.avgExecutionTime);
}
public virtual async Task<EntityChange> GetEntityChange(Guid auditLogId, Guid entityChangeId, bool includeDetails = true)
{
return (await GetMongoQueryable()
.Where(x => x.Id == auditLogId && x.EntityChanges.Any(y => y.Id == entityChangeId)).FirstAsync())
.EntityChanges.First(x => x.Id == entityChangeId);
}
public virtual async Task<List<EntityChange>> GetEntityChangeListAsync(
string sorting = null,
int maxResultCount = 50,

@ -440,6 +440,109 @@ namespace Volo.Abp.AuditLogging
entityChanges.Single(x => x.ChangeType == EntityChangeType.Updated).ShouldNotBeNull();
}
[Fact]
public async Task GetEntityChangeAsync()
{
// 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,
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 entityChange =
await AuditLogRepository.GetEntityChange(entityChanges.First().AuditLogId, entityChanges.First().Id);
entityChange.ChangeTime.ShouldBe(entityChanges.First().ChangeTime);
}
[Fact]
public async Task GetOrderedEntityChangeListAsync()
{

Loading…
Cancel
Save