public void GetUsername_ReturnsEmptyStringIfPrincipalIsNull() { // Act string username = AntiForgeryData.GetUsername(null); // Assert Assert.AreEqual("", username); }
public void GetUsername_ReturnsEmptyStringIfIdentityIsNull() { // Arrange Mock <IPrincipal> mockPrincipal = new Mock <IPrincipal>(); mockPrincipal.Setup(o => o.Identity).Returns((IIdentity)null); // Act string username = AntiForgeryData.GetUsername(mockPrincipal.Object); // Assert Assert.AreEqual("", username); }
public void GetUsername_ReturnsUsernameIfUserIsAuthenticated() { // Arrange Mock <IPrincipal> mockPrincipal = new Mock <IPrincipal>(); mockPrincipal.Setup(o => o.Identity.IsAuthenticated).Returns(true); mockPrincipal.Setup(o => o.Identity.Name).Returns("SampleName"); // Act string username = AntiForgeryData.GetUsername(mockPrincipal.Object); // Assert Assert.AreEqual("SampleName", username); }
public void GetUsername_ReturnsEmptyStringIfUserNotAuthenticated() { // Arrange Mock <IPrincipal> mockPrincipal = new Mock <IPrincipal>(); mockPrincipal.Expect(o => o.Identity.IsAuthenticated).Returns(false); mockPrincipal.Expect(o => o.Identity.Name).Returns("SampleName"); // Act string username = AntiForgeryData.GetUsername(mockPrincipal.Object); // Assert Assert.AreEqual("", username); }