public void NullHttpContextRendersEmptyString()
        {
            var renderer = new AspNetItemValueLayoutRenderer();

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

            Assert.Empty(result);
        }
        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);
        }
        public void VariableFoundRendersValue(object expectedValue)
        {
            var httpContext = Substitute.For<HttpContextBase>();
            httpContext.Items["key"].Returns(expectedValue);

            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);
        }
        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);
        }