Beispiel #1
0
        public void Test_ExtraFields()
        {
            Core.Configuration.DataProvider = new FileDataProvider();
            var scope = new AuditScopeFactory().Create(new AuditScopeOptions("SomeEvent", null, new { @class = "class value", DATA = 123 }, null, EventCreationPolicy.Manual));

            scope.Comment("test");
            var ev = scope.Event;

            scope.Discard();
            Assert.AreEqual("123", ev.CustomFields["DATA"].ToString());
            Assert.AreEqual("class value", ev.CustomFields["class"].ToString());
        }
Beispiel #2
0
        public void Test_EventCreationPolicy_Manual()
        {
            var provider = new Mock <AuditDataProvider>();

            provider.Setup(p => p.InsertEvent(It.IsAny <AuditEvent>())).Returns(() => Guid.NewGuid());
            Core.Configuration.DataProvider = provider.Object;
            using (var scope = new AuditScopeFactory().Create("SomeEvent", () => "target", EventCreationPolicy.Manual, null))
            {
                scope.Comment("test");
            }
            provider.Verify(p => p.InsertEvent(It.IsAny <AuditEvent>()), Times.Never);

            using (var scope = new AuditScopeFactory().Create("SomeEvent", () => "target", EventCreationPolicy.Manual, null))
            {
                scope.Comment("test");
                scope.Save();
                scope.Comment("test2");
                scope.Save();
            }
            provider.Verify(p => p.InsertEvent(It.IsAny <AuditEvent>()), Times.Once);
            provider.Verify(p => p.ReplaceEvent(It.IsAny <object>(), It.IsAny <AuditEvent>()), Times.Once);
        }
Beispiel #3
0
        public void Test_EventCreationPolicy_InsertOnEnd()
        {
            var provider = new Mock <AuditDataProvider>();

            Core.Configuration.DataProvider = provider.Object;
            using (var scope = new AuditScopeFactory().Create("SomeEvent", () => "target", EventCreationPolicy.InsertOnEnd, null))
            {
                scope.Comment("test");
                scope.Save(); // this should do nothing because of the creation policy (this is no more true, since v 4.6.2)
            }
            provider.Verify(p => p.ReplaceEvent(It.IsAny <object>(), It.IsAny <AuditEvent>()), Times.Never);
            provider.Verify(p => p.InsertEvent(It.IsAny <AuditEvent>()), Times.Exactly(2));
        }
Beispiel #4
0
        public void TestDiscard()
        {
            var provider = new Mock <AuditDataProvider>();

            provider.Setup(p => p.Serialize(It.IsAny <string>())).CallBase();
            Core.Configuration.DataProvider = provider.Object;
            var        target    = "initial";
            var        eventType = "SomeEvent";
            AuditEvent ev;

            using (var scope = new AuditScopeFactory().Create(eventType, () => target, EventCreationPolicy.InsertOnEnd, null))
            {
                ev = scope.Event;
                scope.Comment("test");
                scope.SetCustomField <string>("custom", "value");
                target = "final";
                scope.Discard();
            }
            Assert.AreEqual(eventType, ev.EventType);
            Assert.True(ev.Comments.Contains("test"));
            Assert.Null(ev.Target.New);
            provider.Verify(p => p.InsertEvent(It.IsAny <AuditEvent>()), Times.Never);
        }
Beispiel #5
0
        public void TestSave()
        {
            var provider = new Mock <AuditDataProvider>();

            provider.Setup(p => p.Serialize(It.IsAny <string>())).CallBase();
            Core.Configuration.DataProvider = provider.Object;
            var        target    = "initial";
            var        eventType = "SomeEvent";
            AuditEvent ev;

            using (var scope = new AuditScopeFactory().Create(eventType, () => target, EventCreationPolicy.InsertOnEnd, null))
            {
                ev = scope.Event;
                scope.Comment("test");
                scope.SetCustomField <string>("custom", "value");
                target = "final";
                scope.Save(); // this should do nothing because of the creation policy (this no more true since v4.6.2)
                provider.Verify(p => p.InsertEvent(It.IsAny <AuditEvent>()), Times.Once);
            }
            Assert.AreEqual(eventType, ev.EventType);
            Assert.True(ev.Comments.Contains("test"));
            provider.Verify(p => p.InsertEvent(It.IsAny <AuditEvent>()), Times.Exactly(2));
        }