public void ServerVariablesAreCopied() { var value = KissLog.Tests.Common.CommonTestHelpers.GenerateList(5); var identity = new Mock <ClaimsIdentity>(); identity.Setup(p => p.Claims).Returns(Helpers.GenerateClaims(value)); var user = new Mock <ClaimsPrincipal>(); user.Setup(p => p.Identity).Returns(identity.Object); var httpContext = Helpers.MockHttpContext(); httpContext.Setup(p => p.User).Returns(user.Object); KissLogHttpModule module = new KissLogHttpModule(); module.OnPostAuthenticateRquest(httpContext.Object); var dictionary = httpContext.Object.Items[LoggerFactory.DictionaryKey] as IDictionary <string, Logger>; Logger logger = dictionary[Constants.DefaultLoggerCategoryName]; Assert.AreEqual(JsonSerializer.Serialize(value), JsonSerializer.Serialize(logger.DataContainer.HttpProperties.Request.Properties.Claims)); }
public void DoesNotThrowExceptionWhenUserIsNull() { var httpContext = Helpers.MockHttpContext(); httpContext.SetupProperty(p => p.User, null); KissLogHttpModule module = new KissLogHttpModule(); module.OnPostAuthenticateRquest(httpContext.Object); }
public void DoesNotThrowExceptionWhenUserIsNotClaimsPrincipal() { var user = new Mock <IPrincipal>(); var httpContext = Helpers.MockHttpContext(); httpContext.Setup(p => p.User).Returns(user.Object); KissLogHttpModule module = new KissLogHttpModule(); module.OnPostAuthenticateRquest(httpContext.Object); }
public void GetsOrAddsTheLoggerToHttpContext() { var user = new Mock <ClaimsPrincipal>(); user.Setup(p => p.Identity).Returns(new Mock <ClaimsIdentity>().Object); var httpContext = Helpers.MockHttpContext(); httpContext.Setup(p => p.User).Returns(user.Object); KissLogHttpModule module = new KissLogHttpModule(); module.OnPostAuthenticateRquest(httpContext.Object); var dictionary = httpContext.Object.Items[LoggerFactory.DictionaryKey] as IDictionary <string, Logger>; Assert.IsNotNull(dictionary); Assert.AreEqual(1, dictionary.Count); }
public void ThrowsExceptionForNullHttpContext() { KissLogHttpModule module = new KissLogHttpModule(); module.OnPostAuthenticateRquest(null); }