예제 #1
0
        public void NullHttpContextRendersEmptyString()
        {
            var renderer = new AspNetItemValueLayoutRenderer();

            string result = renderer.Render(new LogEventInfo());

            Assert.Empty(result);
        }
예제 #2
0
        public void VariableNotFoundRendersEmptyString()
        {
            var httpContext = Substitute.For <HttpContextBase>();

            var renderer = new AspNetItemValueLayoutRenderer();

            renderer.Variable            = "key";
            renderer.HttpContextAccessor = new FakeHttpContextAccessor(httpContext);

            string result = renderer.Render(new LogEventInfo());

            Assert.Empty(result);
        }
예제 #3
0
        public void NestedPropertyRendersValue(string itemKey, string variable, object data, object expectedValue)
        {
            var httpContext = Substitute.For <HttpContextBase>();

            httpContext.Items[itemKey].Returns(data);

            var renderer = new AspNetItemValueLayoutRenderer();

            renderer.Variable = variable;
            renderer.EvaluateAsNestedProperties = true;
            renderer.HttpContextAccessor        = new FakeHttpContextAccessor(httpContext);

            string result = renderer.Render(new LogEventInfo());

            Assert.Equal(Convert.ToString(expectedValue, CultureInfo.CurrentUICulture), result);
        }
예제 #4
0
        public void VariableFoundRendersValue(object expectedValue)
        {
            var httpContext = Substitute.For <HttpContextBase>();

#if NETSTANDARD_1plus
            httpContext.Items = new Dictionary <object, object>();
            httpContext.Items.Add("key", expectedValue);
#else
            httpContext.Items["key"].Returns(expectedValue);
#endif

            var renderer = new AspNetItemValueLayoutRenderer();
            renderer.Variable            = "key";
            renderer.HttpContextAccessor = new FakeHttpContextAccessor(httpContext);

            string result = renderer.Render(new LogEventInfo());

            Assert.Equal(Convert.ToString(expectedValue, CultureInfo.CurrentUICulture), result);
        }
예제 #5
0
        public void CulturedVariableFoundRendersValue(object expectedValue)
        {
            var httpContext = Substitute.For <HttpContextBase>();

#if ASP_NET_CORE
            httpContext.Items = new Dictionary <object, object>();
            httpContext.Items.Add("key", expectedValue);
#else
            httpContext.Items["key"].Returns(expectedValue);
#endif
            var cultureInfo = new CultureInfo("nl-NL");
            var renderer    = new AspNetItemValueLayoutRenderer();
            renderer.Variable            = "key";
            renderer.Culture             = cultureInfo;
            renderer.HttpContextAccessor = new FakeHttpContextAccessor(httpContext);

            string result = renderer.Render(new LogEventInfo());

            Assert.Equal(Convert.ToString(expectedValue, cultureInfo), result);
        }
        public void NestedPropertyRendersValue(string itemKey, string variable, object data, object expectedValue)
        {
            var httpContext = Substitute.For <HttpContextBase>();

#if ASP_NET_CORE
            httpContext.Items = new Dictionary <object, object>();
            httpContext.Items.Add(itemKey, data);
#else
            httpContext.Items.Count.Returns(1);
            httpContext.Items.Contains(itemKey).Returns(true);
            httpContext.Items[itemKey].Returns(data);
#endif

            var renderer = new AspNetItemValueLayoutRenderer();
            renderer.Variable = variable;
            renderer.EvaluateAsNestedProperties = true;
            renderer.HttpContextAccessor        = new FakeHttpContextAccessor(httpContext);

            string result = renderer.Render(new LogEventInfo());

            Assert.Equal(Convert.ToString(expectedValue, CultureInfo.CurrentUICulture), result);
        }