Ejemplo n.º 1
0
        public async Task Should_Save_An_Audit_Log()
        {
            //Arrange
            var userId       = new Guid("4456fb0d-74cc-4807-9eee-23e551e6cb06");
            var ipAddress    = "153.1.7.61";
            var firstComment = "first Comment";

            var auditLog = 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"
                },
                EntityChanges =
                {
                    new EntityChangeInfo
                    {
                        EntityId           = Guid.NewGuid().ToString(),
                        EntityTypeFullName = "Volo.Abp.AuditLogging.TestEntity",
                        ChangeType         = EntityChangeType.Created,
                        ChangeTime         = DateTime.Now,
                        PropertyChanges    = new List <EntityPropertyChangeInfo>
                        {
                            new EntityPropertyChangeInfo
                            {
                                PropertyTypeFullName = typeof(string).FullName,
                                PropertyName         = "Name",
                                NewValue             = "New value",
                                OriginalValue        = null
                            }
                        }
                    }
                }
            };

            //Act
            await _auditingStore.SaveAsync(auditLog);

            //Assert

            var insertedLog = _auditLogRepository.GetList(true)
                              .FirstOrDefault(al => al.UserId == userId);

            insertedLog.ShouldNotBeNull();
            insertedLog.ClientIpAddress.ShouldBe(ipAddress);
            insertedLog.Comments.ShouldStartWith(firstComment);
            insertedLog.EntityChanges.Count.ShouldBeGreaterThan(0);
            insertedLog.EntityChanges.First().PropertyChanges.Count.ShouldBeGreaterThan(0);
        }