Exemplo n.º 1
0
        public async Task Test_HttpAction_CustomAuditScopeFactory()
        {
            var actions = new List <HttpAction>();

            Audit.Core.Configuration.DataProvider = null;

            var dp = new DynamicDataProvider();

            dp.AttachOnInsertAndReplace(ev =>
            {
                actions.Add(JsonAdapter.Deserialize <HttpAction>(JsonAdapter.Serialize(ev.GetHttpAction())));
            });

            var factory = new Mock <IAuditScopeFactory>();

            factory.Setup(_ => _.Create(It.IsAny <AuditScopeOptions>()))
            .Returns(new AuditScope(new AuditScopeOptions()
            {
                DataProvider = dp, AuditEvent = new AuditEventHttpClient()
            }));
            var url = "http://google.com/?q=test";

            using (var cli = new HttpClient(new AuditHttpClientHandler()
            {
                RequestFilter = _ => true, AuditScopeFactory = factory.Object
            }))
            {
                await cli.GetAsync(url);
            }

            Assert.AreEqual(1, actions.Count);
            Assert.AreEqual(url, actions[0].Url);
            Assert.AreEqual("GET", actions[0].Method);
        }
Exemplo n.º 2
0
        public void Test_Signalr_CustomAuditScopeFactory()
        {
            var evs = new List <AuditEvent>();

            Configuration.DataProvider = null;

            var dp = new DynamicDataProvider();

            dp.AttachOnInsertAndReplace(ev => { evs.Add(ev); });

            var factory = new Mock <IAuditScopeFactory>();

            factory.Setup(_ => _.Create(It.IsAny <AuditScopeOptions>()))
            .Returns(new AuditScope(new AuditScopeOptions()
            {
                DataProvider = dp, AuditEvent = new AuditEventSignalr()
            }));

            var module = new TestAuditPipelineModule()
            {
                AuditScopeFactory = factory.Object
            };

            SimulateIncomingError(module, new ArgumentNullException("SomeParameter", "message"), "cnn-Error", "err", new object[] { 0 });
            Task.Delay(50).Wait();

            Assert.AreEqual(1, evs.Count);
        }
Exemplo n.º 3
0
 public IDynamicDataProviderConfigurator OnInsertAndReplace(Action <object, AuditEvent> insertReplaceAction)
 {
     _dynamicDataProvider.AttachOnInsertAndReplace(insertReplaceAction);
     return(this);
 }