Example #1
0
        public static void AddLogPipelines_Should_Throws_Exception_When_Container_Is_Null()
        {
            // arrange
            IPipelines       pipelines = new Pipelines();
            TinyIoCContainer container = null;

            // act
            var exception = Assert.Throws <ArgumentNullException>(() =>
                                                                  pipelines.AddLogPipelines(container));

            // assert
            Assert.Equal("Value cannot be null.Parameter name: container", exception.Message.Replace("\r", "").Replace("\n", ""));
        }
Example #2
0
        public void LogData_Should_Work_With_Blacklist_And_Information()
        {
            // arrange
            var originIp        = "127.0.0.1";
            var protocolVersion = "1.1";

            var requestMethod  = "POST";
            var requestBody    = "{ \"test\" : \"123\", \"test2\" : \"123\" }";
            var requestUrl     = "http://localhost/test?query1=xpto1&query1=xpto2&query2=1&query3=";
            var requestHeaders = new Dictionary <string, IEnumerable <string> >
            {
                { "Content-Type", new string[] { "application/json" } },
                { "Accept", new string[] { "application/json", "text/xml" } }
            };

            var responseHeaders = new Dictionary <string, string>
            {
                { "Content-Type", "application/json" },
            };
            var responseStatusCode = HttpStatusCode.BadRequest;
            var Content            = "{ \"xpto\" : \"test\" }";

            var context = NancyContextMock.Create(
                requestMethod, requestUrl, requestBody, requestHeaders,
                responseStatusCode, Content, responseHeaders,
                originIp, protocolVersion);

            context.Items["test"] = "test";

            var config = new NancySerilogConfiguration
            {
                InformationTitle = "{Method} | {Host} | {Path} | {Ip} | {IsSuccessful} | {ProtocolVersion} | {StatusCode} | {StatusDescription} | {StatusCodeFamily} | {ElapsedMilliseconds}",
                Blacklist        = new string[] { "test" },
                Logger           = Log.Logger
            };

            var              logger    = new CommunicationLogger(config);
            IPipelines       pipelines = new Pipelines();
            TinyIoCContainer container = new TinyIoCContainer();

            container.Register <ICommunicationLogger>(logger);
            container.Register(PackUtils.JsonUtility.CamelCaseJsonSerializerSettings);

            pipelines.AddLogPipelines(container);

            // act
            logger.LogData(context);

            // assert
            Assert.Contains("[Information] \"POST\" | \"localhost\" | \"/test\" | \"127.0.0.1\" | False | \"1.1\" | 400 | \"BadRequest\" | \"4XX\" | -1", this.TestOutputHelper.Output);
        }
Example #3
0
        public static void AddLogPipelines_Should_Add_Pipelines()
        {
            // arrange
            IPipelines       pipelines = new Pipelines();
            TinyIoCContainer container = new TinyIoCContainer();

            container.Register <ICommunicationLogger, CommunicationLoggerMock>();
            container.Register(JsonUtility.CamelCaseJsonSerializerSettings);

            // act
            pipelines.AddLogPipelines(container);

            // assert
            Assert.Single(pipelines.BeforeRequest.PipelineItems);
            Assert.Equal(2, pipelines.AfterRequest.PipelineItems.ToList().Count);
            Assert.Equal(2, pipelines.OnError.PipelineItems.ToList().Count);
        }