Example #1
0
        public void NullHttpContextRendersEmptyString()
        {
            var renderer = new AspNetUserAuthTypeLayoutRenderer();

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

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

            httpContext.User.Identity.Returns(null as IIdentity);

            var renderer = new AspNetUserAuthTypeLayoutRenderer();

            renderer.HttpContextAccessor = new FakeHttpContextAccessor(httpContext);

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

            Assert.Empty(result);
        }
Example #3
0
        public void UnauthenticatedUserRendersEmptyString()
        {
            var httpContext = Substitute.For <HttpContextBase>();
            var identity    = Substitute.For <IIdentity>();

            identity.IsAuthenticated.Returns(false);
            httpContext.User.Identity.Returns(identity);

            var renderer = new AspNetUserAuthTypeLayoutRenderer();

            renderer.HttpContextAccessor = new FakeHttpContextAccessor(httpContext);

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

            Assert.Empty(result);
        }
Example #4
0
        public void AuthenticatedUserRendersAuthenticationType()
        {
            var expectedResult = "value";
            var httpContext    = Substitute.For <HttpContextBase>();
            var identity       = Substitute.For <IIdentity>();

            identity.IsAuthenticated.Returns(true);
            identity.AuthenticationType.Returns(expectedResult);
            httpContext.User.Identity.Returns(identity);

            var renderer = new AspNetUserAuthTypeLayoutRenderer();

            renderer.HttpContextAccessor = new FakeHttpContextAccessor(httpContext);

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

            Assert.Equal(expectedResult, result);
        }