Exemplo n.º 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());
        }
Exemplo n.º 2
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);
        }