public void When_TimingLevel_Is_None_Log_Message_Contains_No_Level()
 {
     var log = new FakeLog("mylogger", LogLevel.Info, true, true, true, "yyyy/MM/dd HH:mm:ss:fff");
     var op = new Get<string>("key", null, _transcoder, OperationLifespan);
     using (new OperationTimer(TimingLevel.None, op, new CommonLogStore(log)))
     {
         Thread.Sleep(100);
     }
     var loggedString = log.LogStore.ToString();
     Assert.IsFalse(loggedString.Contains("Level"));
 }
        public void When_EnableQueryTiming_Is_True_And_LogLevel_Is_Not_Configured_Nothing_Is_Logged()
        {
            var queryRequest = new QueryRequest(Statement);
            var log = new FakeLog("mylogger", LogLevel.Off, true, true, true, LogDateFormat);
            using (var timer = new QueryTimer(queryRequest, new CommonLogStore(log), true))
            {
                Thread.Sleep(TimeSpan.FromSeconds(1));
                timer.ClusterElapsedTime = ServerElapsedTime;
            }

            var logOutput = log.LogStore.ToString();
            Assert.IsEmpty(logOutput);
        }
        public void ServerExecutionTime_Defaults_To_NotRecorded()
        {
            var queryRequest = new QueryRequest(Statement);
            var log = new FakeLog("mylogger", LogLevel.Debug, true, true, true, LogDateFormat);
            using (new QueryTimer(queryRequest, new CommonLogStore(log), true))
            {
                Thread.Sleep(TimeSpan.FromSeconds(1));
            }

            var logOutput = log.LogStore.ToString();
            Assert.IsTrue(logOutput.Contains("[INFO]"));
            Assert.IsTrue(logOutput.Contains("Query Timing"));
            Assert.IsTrue(logOutput.Contains(QueryTimer.NotRecorded));
            Assert.IsTrue(logOutput.Contains(Statement));
        }
        public void When_EnableQueryTiming_Is_True_And_LogLevel_Configured_QueryTiming_Is_Logged()
        {
            var queryRequest = new QueryRequest(Statement);
            var log = new FakeLog("mylogger", LogLevel.Debug, true, true, true, LogDateFormat);
            using (var timer = new QueryTimer(queryRequest, new CommonLogStore(log), true))
            {
                Thread.Sleep(TimeSpan.FromMilliseconds(25));
                timer.ClusterElapsedTime = ServerElapsedTime;
            }

            var logOutput = log.LogStore.ToString();
            Assert.IsTrue(logOutput.Contains("[INFO]"));
            Assert.IsTrue(logOutput.Contains("Query Timing"));
            Assert.IsTrue(logOutput.Contains(ServerElapsedTime));
            Assert.IsTrue(logOutput.Contains(Statement));
        }
 public void When_LogLevel_Is_Off_Nothing_Is_Logged()
 {
     var log = new FakeLog("mylogger", LogLevel.Off, true, true, true, "yyyy/MM/dd HH:mm:ss:fff");
     var op = new Get<string>("key", null, _transcoder, OperationLifespan);
     using (new OperationTimer(TimingLevel.None, op, new CommonLogStore(log)))
     {
         Thread.Sleep(100);
     }
     var loggedString = log.LogStore.ToString();
     Assert.IsEmpty(loggedString);
 }
        public void Throws_ArgumentException_When_QueryRequest_Is_Null()
        {
            var log = new FakeLog("mylogger", LogLevel.Debug, true, true, true, LogDateFormat);

            Assert.Throws<ArgumentException>(() => new QueryTimer(null, new CommonLogStore(log), true),
                QueryTimer.QueryMustBeProvided);
        }
        public void Throws_ArgumentException_When_QueryRequest_Statement_Is_Null_Or_Empty()
        {
            QueryRequest queryRequest;
            var log = new FakeLog("mylogger", LogLevel.Debug, true, true, true, LogDateFormat);

            queryRequest = new QueryRequest(null);
            Assert.Throws<ArgumentException>(() => new QueryTimer(queryRequest, new CommonLogStore(log), true),
                QueryTimer.QueryStatementMustBeProvided);


            queryRequest = new QueryRequest(string.Empty);
            Assert.Throws<ArgumentException>(() => new QueryTimer(queryRequest, new CommonLogStore(log), true),
                QueryTimer.QueryStatementMustBeProvided);
        }