コード例 #1
0
        public void TestProjectAuditLogging()
        {
            // This test can become sluggish and fail when the table is very full, which suggests the table likely needs to be trimmed regularly.
            AuditLog.ClearAuditLogTable();

            // Get an arbitrary real-word person to do these actions
            var firmaUser = HttpRequestStorage.DatabaseEntities.People.First();

            // Create audit logging
            // --------------------

            // Make a test object and save it
            var dbContext = HttpRequestStorage.DatabaseEntities;

            var testProject = TestFramework.TestProject.Create(dbContext);

            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);

            // Check that the audit log mentions this object
            System.Diagnostics.Trace.WriteLine($"Looking for {FieldDefinition.Project.GetFieldDefinitionLabel()} named \"{testProject.ProjectName}\" in Audit Log database entries.");
            Check.Assert(HttpRequestStorage.DatabaseEntities.AuditLogs.Any(al => al.OriginalValue.Contains(testProject.ProjectName)));

            // Change audit logging
            // --------------------

            // Make changes to the original object
            var newProjectName = TestFramework.MakeTestName($"New {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} Name", Project.FieldLengths.ProjectName);

            testProject.ProjectName = newProjectName;
            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);

            // Check that the audit log mentions this NEW name
            Check.Assert(HttpRequestStorage.DatabaseEntities.AuditLogs.Any(al => al.NewValue.Contains(newProjectName)));

            // Delete audit logging
            // --------------------

            // Stash for later; we'll need to clean these up
            var testRegion    = testProject.FocusArea.DNRUplandRegion;
            var testFocusArea = testProject.FocusArea;

            testProject.DeleteFull(dbContext);
            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);
            // Check that the audit log mentions this Project name as deleted
            Check.Assert(
                HttpRequestStorage.DatabaseEntities.AuditLogs.SingleOrDefault(
                    al => al.TableName == "Project" && al.AuditLogEventTypeID == AuditLogEventType.Deleted.AuditLogEventTypeID && al.RecordID == testProject.ProjectID) != null,
                $"Could not find deleted {Models.FieldDefinition.Project.GetFieldDefinitionLabel()} record");

            // Cleanup
            testRegion.DeleteFull(dbContext);
            testFocusArea.DeleteFull(dbContext);
            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);
        }
コード例 #2
0
        public void TestClassificationAuditLogging()
        {
            // This test can become sluggish and fail when the table is very full, which suggests the table likely needs to be trimmed regularly.
            AuditLog.ClearAuditLogTable();

            // Get an arbitrary real-word person to do these actions
            var firmaUser = HttpRequestStorage.DatabaseEntities.People.First();

            // Create audit logging
            // --------------------

            // Make a test object and save it
            var dbContext = HttpRequestStorage.DatabaseEntities;

            var testClassification = TestFramework.TestClassification.Create(dbContext);

            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);

            // Check that the audit log mentions this object
            System.Diagnostics.Trace.WriteLine($"Looking for Classification \"{testClassification.DisplayName}\" in Audit Log database entries.");
            Check.Assert(HttpRequestStorage.DatabaseEntities.AuditLogs.Any(al => al.OriginalValue.Contains(testClassification.DisplayName)));

            // Change audit logging
            // --------------------

            // Make changes to the original object
            var newClassificationName        = TestFramework.MakeTestName("New Classification", Classification.FieldLengths.DisplayName);
            var newClassificationDescription = TestFramework.MakeTestName("New ClassificationDescription");

            testClassification.DisplayName = newClassificationName;
            testClassification.ClassificationDescription = newClassificationDescription;
            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);

            // Check that the audit log mentions this NEW name
            Check.Assert(HttpRequestStorage.DatabaseEntities.AuditLogs.Any(al => al.NewValue.Contains(newClassificationName)));

            // Delete audit logging
            // --------------------

            testClassification.DeleteFull(dbContext);
            HttpRequestStorage.DatabaseEntities.SaveChanges(firmaUser);
            // Check that the audit log mentions this Classification name as deleted
            Check.Assert(
                HttpRequestStorage.DatabaseEntities.AuditLogs.SingleOrDefault(
                    al => al.TableName == "Classification" && al.AuditLogEventTypeID == AuditLogEventType.Deleted.AuditLogEventTypeID && al.RecordID == testClassification.ClassificationID) !=
                null,
                "Could not find deleted Classification record");
        }