Exemple #1
0
        public Model_Tests()
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters["param"] = "paramvalue";

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers["header"] = "headervalue";


            List <StatisticalDocument> stat = new List <StatisticalDocument>();

            stat.Add(new StatisticalDocument()
            {
                Call           = "testcall",
                Comment        = "testcomment",
                ElapsedSeconds = 23
            });

            _basedoc = new ElasticsearchBaseDocument("id", "logname", "appname", message: "message", path: "path"
                                                     , controllerName: "controller", actionName: "action"
                                                     , elapsedSeconds: 0.1, parameters: parameters, resultCode: 200);

            _accesslogdoc = new ElasticsearchAccessLogDocument("id", "logname", "appname", message: "message", path: "path"
                                                               , controllerName: "controller", actionName: "action"
                                                               , elapsedSeconds: 0.1, parameters: parameters, resultCode: 200, stat: stat, headers: headers);

            _errorlogdoc = new ElasticsearchErrorDocument("id", new Exception("extest"), "logname", "appname", message: "message", path: "path"
                                                          , controllerName: "controller", actionName: "action"
                                                          , elapsedSeconds: 0.1, parameters: parameters, resultCode: 200, inputData: Encoding.UTF8.GetBytes("input\x0001data\x0002"));
        }
Exemple #2
0
        public void AccesslogDocumentTest02()
        {
            var d = new ElasticsearchAccessLogDocument();

            _accesslogdoc.CloneTo(d);
            check_accesslogdoc(d);
        }
Exemple #3
0
        private void check_accesslogdoc(ElasticsearchAccessLogDocument d)
        {
            check_basedoc(d);
            Assert.Single(d.Stat);
            Assert.Equal("testcall", d.Stat[0].Call);

            Assert.Single(d.Headers);
            Assert.Equal("headervalue", d.Headers["header"]);
        }
Exemple #4
0
        public async void AcessLogDocumentTest(bool IndexExists_Exists)
        {
            var cli = CreateCli <ElasticsearchAccessLogDocument>(IndexExists_Exists: IndexExists_Exists);
            ElasticsearchReporter r = new ElasticsearchReporter(cli.Object);
            var d = new ElasticsearchAccessLogDocument("mockid", appName: "mockapp", message: "mock msg", path: "mock path", controllerName: "mock_controller", actionName: "mockAction"
                                                       , elapsedSeconds: 2, parameters: new Dictionary <string, string>()
            {
                { "mockparam1", "mockvalue1" }
            }, resultCode: 200, stat: new List <StatisticalDocument>()
            {
                new StatisticalDocument()
                {
                    Call             = "mockcall"
                    , Comment        = "mockcomment"
                    , ElapsedSeconds = 5
                }
            }, headers: new Dictionary <string, string>()
            {
                { "mockheader1", "mockheadervalue1" }
            });
            await r.Post(d, "testindex");

            cli.Verify(e => e.IndexExistsAsync(It.Is <Nest.Indices>(i =>
                                                                    i.Match(all => false, many => many.Indices.Contains("testindex")))
                                               , It.IsAny <Func <IndexExistsDescriptor, IIndexExistsRequest> >()
                                               , It.IsAny <CancellationToken>()), Times.Once);
            if (false == IndexExists_Exists)
            {
                cli.Verify(e => e.IndexCreateAsync(It.Is <Nest.IndexName>(i =>
                                                                          i.Name == "testindex")
                                                   , It.IsAny <Func <CreateIndexDescriptor, ICreateIndexRequest> >()
                                                   , It.IsAny <CancellationToken>()), Times.Once);
            }

            cli.Verify(e => e.IndexAsync(It.Is <ElasticsearchAccessLogDocument>(d =>
                                                                                d.LogName == "access_log" && d.Timestamp <DateTime.Now && d.Timestamp> DateTime.Now.AddSeconds(-1) &&
                                                                                d.Id == "mockid" && d.AppName == "mockapp" &&
                                                                                d.RequestParameters.ContainsKey("mockparam1") && d.RequestParameters["mockparam1"] == "mockvalue1" &&
                                                                                d.Headers.ContainsKey("mockheader1") && d.Headers["mockheader1"] == "mockheadervalue1" &&
                                                                                d.Stat.Count == 1 && d.Stat[0].Call == "mockcall" && d.Stat[0].Comment == "mockcomment" && d.Stat[0].ElapsedSeconds == 5
                                                                                )
                                         , It.IsAny <Func <IndexDescriptor <ElasticsearchAccessLogDocument>, IIndexRequest <ElasticsearchAccessLogDocument> > >()
                                         , It.IsAny <CancellationToken>()), Times.Once);
        }
Exemple #5
0
 public async void IndexDocumentExpectedExceptionTest()
 {
     ElasticsearchReporter r = new ElasticsearchReporter(CreateCli <ElasticsearchAccessLogDocument>(IndexResponse_IsValid: false).Object);
     var d = new ElasticsearchAccessLogDocument();
     await Assert.ThrowsAsync <ElasticsearchException>(() => r.Post(d, "testindex", false));
 }
 public async Task ReportAccessLog(ElasticsearchAccessLogDocument doc) => await Report(accessLogReporter, doc);
Exemple #7
0
        public void AccesslogDocumentTestDefault()
        {
            var d = new ElasticsearchAccessLogDocument();

            Assert.Equal("access_log", d.LogName);
        }