コード例 #1
0
        public void WhenGetSimpleEvent_ThenResult_ShouldBeExpected()
        {
            var options = new GraylogSinkOptions();
            var target  = new GelfMessageBuilder("localhost", options);

            var date = DateTimeOffset.Now;

            var expected = new
            {
                facility      = "GELF",
                full_message  = "abcdef\"zxc\"",
                host          = "localhost",
                level         = 2,
                short_message = "abcdef\"zxc\"",
                timestamp     = date.DateTime,
                version       = "1.1",
                _stringLevel  = "Information",
                _TestProp     = "\"zxc\"",
                _id_          = "\"asd\""
            };

            LogEvent logEvent = LogEventSource.GetSimpleLogEvent(date);

            string expectedString = JsonConvert.SerializeObject(expected, Newtonsoft.Json.Formatting.None);
            string actual         = target.Build(logEvent).ToString(Newtonsoft.Json.Formatting.None);
            //actual.ShouldBeEquivalentTo(expectedString);
        }
コード例 #2
0
        public void GetSimpleLogEvent_GraylogSinkOptionsContainsHost_ReturnsOptionsHost()
        {
            //arrange
            GraylogSinkOptions options = new GraylogSinkOptions()
            {
                Host = "my_host"
            };
            GelfMessageBuilder messageBuilder = new GelfMessageBuilder("localhost", options);
            DateTime           date           = DateTime.UtcNow;
            string             expectedHost   = "my_host";

            //act
            LogEvent logEvent   = LogEventSource.GetSimpleLogEvent(date);
            JObject  actual     = messageBuilder.Build(logEvent);
            string   actualHost = actual.Value <string>("host");

            //assert
            Assert.Equal(expectedHost, actualHost);
        }
コード例 #3
0
        public void WhenLogEvent_ThenMessageBuilderShouldBeCalled()
        {
            var errorBuilder   = new Mock <IMessageBuilder>();
            var messageBuilder = new Mock <IMessageBuilder>();

            var messageBuilders = new Dictionary <BuilderType, Lazy <IMessageBuilder> >
            {
                [BuilderType.Exception] = new Lazy <IMessageBuilder>(() => errorBuilder.Object),
                [BuilderType.Message]   = new Lazy <IMessageBuilder>(() => messageBuilder.Object)
            };

            GelfConverter target = new GelfConverter(messageBuilders);

            var simpleEvent = LogEventSource.GetSimpleLogEvent(DateTimeOffset.Now);

            target.GetGelfJson(simpleEvent);

            errorBuilder.Verify(c => c.Build(simpleEvent), Times.Never);
            messageBuilder.Verify(c => c.Build(simpleEvent), Times.Once);
        }