public async Task CorrectlyFiltersReadAndPrintAuditLogs()
        {
            // Arrange
            _context.AuditLogs.AddRange(new List <AuditLog>
            {
                new AuditLog {
                    RootEntity = RootEntities.Notification, RootId = "32", EventType = AuditEventType.READ_EVENT, AuditData = "Read a book"
                },
                new AuditLog {
                    RootEntity = RootEntities.Notification, RootId = "32", EventType = AuditEventType.PRINT_EVENT, AuditData = "Printed a book"
                },
                new AuditLog {
                    RootEntity = RootEntities.Notification, RootId = "32", EventType = AuditEventType.MATCH_EVENT, AuditData = "Used matches"
                },
                new AuditLog {
                    RootEntity = RootEntities.Notification, RootId = "32", EventType = AuditEventType.UNMATCH_EVENT, AuditData = "Put down matches"
                }
            });
            _context.SaveChanges();

            // Act
            var notificationLogs = await _auditService.GetWriteAuditsForNotification(32);

            // Assert
            Assert.Equal(2, notificationLogs.Count);
            Assert.Empty(notificationLogs.Where(log => log.EventType == AuditEventType.PRINT_EVENT));
            Assert.Empty(notificationLogs.Where(log => log.EventType == AuditEventType.READ_EVENT));
            Assert.Contains("Used matches", notificationLogs.Select(log => log.AuditData));
            Assert.Contains("Put down matches", notificationLogs.Select(log => log.AuditData));
        }
예제 #2
0
        private List <AuditEntity> WriteAuditRecords(string source, string action, DateTime from, int number, TimeSpan frequency,
                                                     bool success    = true, string subject = "andy", string subjectIdentifier = "3232-232198", string description = "",
                                                     string resource = "Some Resource", string resourceType = "client", string resourceIdentifier = "342432-3256-4624")
        {
            var      auditEntries = new List <AuditEntity>();
            DateTime when         = from;

            using (var context = new AuditDatabaseContext(dbContextOptions))
            {
                for (int nAuditRecordIndex = 0; nAuditRecordIndex < number; nAuditRecordIndex++)
                {
                    var nextAuditEntry = new AuditEntity()
                    {
                        When               = when.ToUniversalTime(),
                        Succeeded          = success,
                        Subject            = subject,
                        SubjectIdentifier  = subjectIdentifier,
                        SubjectType        = "User",
                        Source             = source,
                        Description        = description,
                        Action             = action,
                        Resource           = resource,
                        ResourceType       = resourceType,
                        ResourceIdentifier = resourceIdentifier
                    };

                    auditEntries.Add(nextAuditEntry);

                    when = when.Add(frequency);
                }

                context.AuditEntries.AddRange(auditEntries);

                context.SaveChanges();
            }

            return(auditEntries);
        }