public void LogCallsObject_MediumDetail()
        {
            var proxy = Proxii.Proxy <ILogTester, LogTester>()
                        .LogCallsObject(LogDetailLevel.Medium)
                        .Create();

            proxy.Do("foo", 100);

            string pattern = $"{{\"methodName\":\"Do\",\"timestamp\":{ISODateTimePattern},\"className\":\"Proxii\\.NLog\\.Test\\.ILogTester\",\"methodSignature\":\"Do\\(String s, Int32 i\\)\",\"arguments\":\\[\"foo\",100\\]}}";

            Assert.That(Regex.IsMatch(InfoLogContents[0], pattern), Is.True);
        }
        public void LogCallsObject_UsesLogLevel()
        {
            var proxy = Proxii.Proxy <ILogTester, LogTester>()
                        .LogCallsObject(LogLevel.Trace)
                        .Create();

            proxy.Do();

            string pattern = $"{{\"methodName\":\"Do\",\"timestamp\":{ISODateTimePattern},\"className\":\"Proxii\\.NLog\\.Test\\.ILogTester\"}}";

            Assert.That(Regex.IsMatch(TraceLogContents[0], pattern), Is.True);
        }
Beispiel #3
0
        public void LogCalls_WarnsOnEmptyFormatString()
        {
            var proxy = Proxii.Proxy <ILogTester, LogTester>()
                        .LogCalls("")
                        .Create();

            proxy.Do("foo", 10);

            var logContents = InfoLogContents;

            Assert.That(logContents.Length, Is.EqualTo(1));
            Assert.That(logContents[0].Contains("WARN|Proxii.NLog.Test.ILogTester|LogCalls() provided with empty or null format string"), Is.True);
        }
Beispiel #4
0
        public void LogCalls_DefaultsToInfoLogLevel()
        {
            var proxy = Proxii.Proxy <ILogTester, LogTester>()
                        .LogCalls()
                        .Create();

            proxy.Do();

            var logContents = InfoLogContents;

            Assert.That(logContents.Length, Is.EqualTo(1));
            Assert.That(logContents[0].Contains("INFO"), Is.True);
        }
Beispiel #5
0
        public void LogCalls_ArgsDetailLevel()
        {
            var proxy = Proxii.Proxy <ILogTester, LogTester>()
                        .LogCalls(MethodCallDetailLevel.Args)
                        .Create();

            proxy.Do("foo", 10);

            var logContents = InfoLogContents;

            Assert.That(logContents.Length, Is.EqualTo(1));
            Assert.That(logContents[0].Contains("called method Do(String s, Int32 i) with arguments (foo, 10)"), Is.True);
        }
Beispiel #6
0
        public void LogBenchmark_FormatsCorrectly_LogLevelAndTimingFormat()
        {
            const string expectedPattern = @"TRACE\|.+method Do\(Int32 times\) took \d+\.\d{4} ms";

            var proxy = Proxii.Proxy <ILogBenchmarkTester, LogBenchmarkTester>()
                        .LogBenchmark(LogLevel.Trace, "F4")
                        .Create();

            proxy.Do(1000);

            var logContents = TraceLogContents;

            Assert.That(logContents.Length, Is.EqualTo(1));
            Assert.That(Regex.IsMatch(logContents[0], expectedPattern), Is.True);
        }
Beispiel #7
0
        public void LogBenchmark_FormatsCorrectly_LogLevelMessageAndTimingFormat()
        {
            const string expectedPattern = @"TRACE\|.+running Do\(Int32 times\) with arguments \(1000\) took \d+\.\d{4} milliseconds";

            var proxy = Proxii.Proxy <ILogBenchmarkTester, LogBenchmarkTester>()
                        .LogBenchmark(LogLevel.Trace, "running %method% with arguments (%args%) took %timing% milliseconds", "F4")
                        .Create();

            proxy.Do(1000);

            var logContents = TraceLogContents;

            Assert.That(logContents.Length, Is.EqualTo(1));
            Assert.That(Regex.IsMatch(logContents[0], expectedPattern), Is.True);
        }
Beispiel #8
0
        public void LogBenchmark_Default()
        {
            const string expectedPattern = @"INFO\|.+method Do\(Int32 times\) took \d+\.\d{2} ms";

            var proxy = Proxii.Proxy <ILogBenchmarkTester, LogBenchmarkTester>()
                        .LogBenchmark()
                        .Create();

            proxy.Do(1000);

            var logContents = InfoLogContents;

            Assert.That(logContents.Length, Is.EqualTo(1));
            Assert.That(Regex.IsMatch(logContents[0], expectedPattern), Is.True);
        }
Beispiel #9
0
        public void LogCalls_FormatString()
        {
            string format = "this formatted message was called when intercepting %method% with arguments (%args%)";

            var proxy = Proxii.Proxy <ILogTester, LogTester>()
                        .LogCalls(format)
                        .Create();

            proxy.Do("foo", 10);

            var logContents = InfoLogContents;

            Assert.That(logContents.Length, Is.EqualTo(1));
            Assert.That(logContents[0].Contains("this formatted message was called when intercepting Do(String s, Int32 i) with arguments (foo, 10)"), Is.True);
        }
Beispiel #10
0
        public void LogCalls_MethodSignatureDetailLevel()
        {
            var proxy = Proxii.Proxy <ILogTester, LogTester>()
                        .LogCalls()
                        .Create();

            proxy.Do();
            proxy.Do("foo", 10);

            var logContents = InfoLogContents;

            Assert.That(logContents.Length, Is.EqualTo(2));
            Assert.That(logContents[0].Contains("called method Do()"), Is.True);
            Assert.That(logContents[1].Contains("called method Do(String s, Int32 i)"), Is.True);
        }
Beispiel #11
0
        public void LogCalls_UsesLogLevel()
        {
            var traceProxy = Proxii.Proxy <ILogTester, LogTester>()
                             .LogCalls(LogLevel.Trace)
                             .Create();

            var infoProxy = Proxii.Proxy <ILogTester, LogTester>()
                            .LogCalls()
                            .Create();

            traceProxy.Do();
            infoProxy.Do();

            var traceLogContents = TraceLogContents;
            var infoLogContents  = InfoLogContents;

            Assert.That(traceLogContents.Length, Is.EqualTo(2));
            Assert.That(traceLogContents[0].Contains("TRACE"), Is.True);
            Assert.That(traceLogContents[1].Contains("INFO"), Is.True);

            Assert.That(infoLogContents.Length, Is.EqualTo(1));
            Assert.That(infoLogContents[0].Contains("INFO"), Is.True);
        }
Beispiel #12
0
        public void LogCalls_UsesCorrectLogger()
        {
            var normalProxy = Proxii.Proxy <ILogTester, LogTester>()
                              .LogCalls()
                              .Create();

            var limitedProxy = Proxii.Proxy <ILimitedLogTester, LimitedLogTester>()
                               .LogCalls()
                               .Create();

            normalProxy.Do();
            limitedProxy.Do();

            var normalLogContents  = InfoLogContents;
            var limitedLogContents = LimitedLogContents;

            Assert.That(normalLogContents.Length, Is.EqualTo(2));
            Assert.That(normalLogContents[0].Contains("Proxii.NLog.Test.ILogTester"));
            Assert.That(normalLogContents[1].Contains("Proxii.NLog.Test.ILimitedLogTester"));

            Assert.That(limitedLogContents.Length, Is.EqualTo(1));
            Assert.That(limitedLogContents[0].Contains("Proxii.NLog.Test.ILimitedLogTester"));
        }