public void GetValueShouldReuseResolvedValue()
 {
     loggerMock.Setup(l => l.IsInfoEnabled).Returns(true);
     var resolver = new ValueResolverAlways<bool>(() => loggerMock.Object.IsInfoEnabled);
     Assert.That(resolver.Value, Is.True);
     Assert.That(resolver.Value, Is.True);
     Assert.That(resolver.Value, Is.True);
     loggerMock.Verify(l => l.IsInfoEnabled, Times.Exactly(3));
 }
        public void GetValueShouldReuseResolvedValue()
        {
            loggerMock.Setup(l => l.IsInfoEnabled).Returns(true);
            var resolver = new ValueResolverAlways <bool>(() => loggerMock.Object.IsInfoEnabled);

            Assert.That(resolver.Value, Is.True);
            Assert.That(resolver.Value, Is.True);
            Assert.That(resolver.Value, Is.True);
            loggerMock.Verify(l => l.IsInfoEnabled, Times.Exactly(3));
        }
Ejemplo n.º 3
0
        private void SetupLoggerEnabledValueResolvers(IGrinderContext grinderContext)
        {
            long loggerEnableCacheTtl = long.Parse(grinderContext.GetProperty(Constants.LoggerEnabledCacheTtlKey, "-1"));
            if (loggerEnableCacheTtl < 0)
            {
                IsErrorEnabledResolver = new ValueResolverOnce<bool>(() => underlying.IsErrorEnabled);
                IsWarnEnabledResolver = new ValueResolverOnce<bool>(() => underlying.IsWarnEnabled);
                IsInfoEnabledResolver = new ValueResolverOnce<bool>(() => underlying.IsInfoEnabled);
                IsDebugEnabledResolver = new ValueResolverOnce<bool>(() => underlying.IsDebugEnabled);
                IsTraceEnabledResolver = new ValueResolverOnce<bool>(() => underlying.IsTraceEnabled);
            }
            else if ((loggerEnableCacheTtl == 0))
            {
                IsErrorEnabledResolver = new ValueResolverAlways<bool>(() => underlying.IsErrorEnabled);
                IsWarnEnabledResolver = new ValueResolverAlways<bool>(() => underlying.IsWarnEnabled);
                IsInfoEnabledResolver = new ValueResolverAlways<bool>(() => underlying.IsInfoEnabled);
                IsDebugEnabledResolver = new ValueResolverAlways<bool>(() => underlying.IsDebugEnabled);
                IsTraceEnabledResolver = new ValueResolverAlways<bool>(() => underlying.IsTraceEnabled);
            }
            else
            {
                IsErrorEnabledResolver = new ValueResolverTimed<bool>(() => underlying.IsErrorEnabled, loggerEnableCacheTtl);
                IsWarnEnabledResolver = new ValueResolverTimed<bool>(() => underlying.IsWarnEnabled, loggerEnableCacheTtl);
                IsInfoEnabledResolver = new ValueResolverTimed<bool>(() => underlying.IsInfoEnabled, loggerEnableCacheTtl);
                IsDebugEnabledResolver = new ValueResolverTimed<bool>(() => underlying.IsDebugEnabled, loggerEnableCacheTtl);
                IsTraceEnabledResolver = new ValueResolverTimed<bool>(() => underlying.IsTraceEnabled, loggerEnableCacheTtl);
            }

            this.Info(x => x("SetupLoggerEnabledValueResolvers: loggerEnableCacheTtl = '{0}'", loggerEnableCacheTtl));
        }