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()); }
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); }
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)); }
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); }
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)); }