public void AppenderPropertiesSetConfigurationValues()
        {
            var config   = new Config();
            var appender = new LogdnaAppender(config, Mock.Of <ILogdnaFormatter>(), Mock.Of <ILogdnaAsyncBuffer>());

            appender.RootUrl                 = "root-url";
            appender.BufferSize              = 123;
            appender.CustomerToken           = "test-token";
            appender.NumberOfInnerExceptions = 123;
            appender.Tag              = "test-tag";
            appender.App              = "CustomApp";
            appender.Env              = "prod";
            appender.SendInterval     = TimeSpan.FromSeconds(123);
            appender.TimeoutInSeconds = 123;
            appender.UserAgent        = "user-agent";

            config.Should().BeEquivalentTo(new
            {
                RootUrl                 = "root-url",
                BufferSize              = 123,
                CustomerToken           = "test-token",
                NumberOfInnerExceptions = 123,
                Tag              = "test-tag",
                App              = "CustomApp",
                Env              = "prod",
                SendInterval     = TimeSpan.FromSeconds(123),
                TimeoutInSeconds = 123,
                UserAgent        = "user-agent"
            });
        }
        public void Flush_FlushesBuffer()
        {
            var bufferMock = new Mock <ILogdnaAsyncBuffer>();

            bufferMock.Setup(x => x.Flush(It.IsAny <TimeSpan>())).Returns(true);

            var appender = new LogdnaAppender(new Config(), Mock.Of <ILogdnaFormatter>(), bufferMock.Object);

            var result = appender.Flush(100);

            result.Should().BeTrue("flush should be successful");
            bufferMock.Verify(x => x.Flush(TimeSpan.FromMilliseconds(100)));
        }
        public void Append_BuffersMessageToBeSent()
        {
            var formatterMock = new Mock <ILogdnaFormatter>();

            formatterMock.Setup(x => x.ToJson(It.IsAny <LoggingEvent>(), It.IsAny <string>()))
            .Returns <LoggingEvent, string>((e, m) => $"Formatted: {e.RenderedMessage}");
            var bufferMock = new Mock <ILogdnaAsyncBuffer>();

            var appender = new LogdnaAppender(new Config(), formatterMock.Object, bufferMock.Object);

            var evt = new LoggingEvent(new LoggingEventData
            {
                Message = "test log"
            });

            appender.DoAppend(evt);

            bufferMock.Verify(x => x.BufferForSend("Formatted: test log"), "message wasn't enqueued to be sent");
        }
        protected IntegrationTest()
        {
            // setup HTTP client mock so that we can wait for sent message and inspect it
            _messageSent = new ManualResetEvent(false);

            _messageStream = new MemoryStream();
            var webRequestMock = new Mock <WebRequest>();

            webRequestMock.Setup(x => x.GetRequestStream()).Returns(_messageStream);
            webRequestMock.Setup(x => x.GetResponse())
            .Returns(() =>
            {
                _messageSent.Set();
                return(Mock.Of <WebResponse>());
            });

            // use mocked web request
            LogdnaClient.WebRequestFactory = (config, url) => webRequestMock.Object;

            var logRepository   = LogManager.GetRepository(Assembly.GetEntryAssembly());
            var currentFileName = Path.GetFileName(Assembly.GetExecutingAssembly().Location);

            log4net.Config.XmlConfigurator.Configure(logRepository, new FileInfo(currentFileName + ".config"));

            _log = LogManager.GetLogger(GetType());

            var appenders = logRepository.GetAppenders();

            _logglyAppender = (LogdnaAppender)appenders[0];

            ThreadContext.Properties.Clear();
            LogicalThreadContext.Properties.Clear();
            GlobalContext.Properties.Clear();

            // thread name can be set just once so we need this safeguard
            if (string.IsNullOrEmpty(Thread.CurrentThread.Name))
            {
                Thread.CurrentThread.Name = TestThreadName;
            }
        }