public void AddsUserNameLabelWithUserNameFromClaim(string claimType) { // Arrange var mockHttpContext = new Mock <HttpContext>(); mockHttpContext.Setup(x => x.User.Identity).Returns(new ClaimsIdentity(new[] { new Claim(claimType, "Foo") }, "Cookies")); var mockHttpContextAccessor = new Mock <IHttpContextAccessor>(); mockHttpContextAccessor.Setup(x => x.HttpContext).Returns(mockHttpContext.Object); var instance = new UserLogEntryLabelProvider(mockHttpContextAccessor.Object); var labels = new Dictionary <string, string>(); // Act instance.Invoke(labels); // Assert var expected = new Dictionary <string, string> { { "user_authenticated", true.ToString() }, { "user_name", "Foo" } }; Assert.Equal(expected, labels); }
public void AddsUserNameLabelWithUserName() { // Arrange var mockHttpContext = new Mock <HttpContext>(); mockHttpContext.Setup(x => x.User.Identity.IsAuthenticated).Returns(true); mockHttpContext.Setup(x => x.User.Identity.Name).Returns("Foo"); var mockHttpContextAccessor = new Mock <IHttpContextAccessor>(); mockHttpContextAccessor.Setup(x => x.HttpContext).Returns(mockHttpContext.Object); var instance = new UserLogEntryLabelProvider(mockHttpContextAccessor.Object); var labels = new Dictionary <string, string>(); // Act instance.Invoke(labels); // Assert var expected = new Dictionary <string, string> { { "user_authenticated", true.ToString() }, { "user_name", "Foo" } }; Assert.Equal(expected, labels); }
private static void AssertLabelsEmpty(Mock <HttpContext> mockHttpContext) { // Arrange var mockHttpContextAccessor = new Mock <IHttpContextAccessor>(); mockHttpContextAccessor.Setup(x => x.HttpContext).Returns(mockHttpContext.Object); // Act var instance = new UserLogEntryLabelProvider(mockHttpContextAccessor.Object); var labels = new Dictionary <string, string>(); instance.Invoke(labels); // Assert Assert.Empty(labels); }
public void AddsUserAuthenticatedLabel(bool authenticated) { // Arrange var mockHttpContext = new Mock <HttpContext>(); mockHttpContext.Setup(x => x.User.Identity.IsAuthenticated).Returns(authenticated); var mockHttpContextAccessor = new Mock <IHttpContextAccessor>(); mockHttpContextAccessor.Setup(x => x.HttpContext).Returns(mockHttpContext.Object); var instance = new UserLogEntryLabelProvider(mockHttpContextAccessor.Object); var labels = new Dictionary <string, string>(); // Act instance.Invoke(labels); // Assert Assert.Single(labels); var label = labels.Single(); Assert.Equal("user_authenticated", label.Key); Assert.Equal(authenticated.ToString(), label.Value); }