GetUserIdAsync() public method

public GetUserIdAsync ( IPrincipal user ) : Task
user IPrincipal
return Task
Esempio n. 1
0
        public async Task GetUserIdAsync_Throws_IfInvalidUser()
        {
            WebHookUser user = new WebHookUser();
            Mock<IPrincipal> principalMock = new Mock<IPrincipal>();

            // Act
            InvalidOperationException ex = await Assert.ThrowsAsync<InvalidOperationException>(() => user.GetUserIdAsync(principalMock.Object));

            // Assert
            Assert.Equal("Could not determine the user ID from the given principal.", ex.Message);
        }
Esempio n. 2
0
        public async Task GetUserIdAsync_Succeeds_IfValidNameIdentifierClaim()
        {
            // Arrange
            WebHookUser user = new WebHookUser();
            ClaimsIdentity identity = new ClaimsIdentity();
            identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "TestUser"));
            ClaimsPrincipal principal = new ClaimsPrincipal(identity);

            // Act
            string actual = await user.GetUserIdAsync(principal);

            // Assert
            Assert.Equal("TestUser", actual);
        }
Esempio n. 3
0
        public async Task GetUserIdAsync_Succeeds_IfValidNameProperty()
        {
            // Arrange
            WebHookUser user = new WebHookUser();
            Mock<IPrincipal> principalMock = new Mock<IPrincipal>();
            principalMock.Setup(p => p.Identity.Name)
                .Returns("TestUser")
                .Verifiable();

            // Act
            string actual = await user.GetUserIdAsync(principalMock.Object);

            // Assert
            Assert.Equal("TestUser", actual);
        }
        public async Task GetUserIdAsync_Succeeds_IfValidNameIdentifierClaim()
        {
            // Arrange
            WebHookUser    user     = new WebHookUser();
            ClaimsIdentity identity = new ClaimsIdentity();

            identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "TestUser"));
            ClaimsPrincipal principal = new ClaimsPrincipal(identity);

            // Act
            string actual = await user.GetUserIdAsync(principal);

            // Assert
            Assert.Equal("TestUser", actual);
        }
        public async Task GetUserIdAsync_Succeeds_IfValidNameProperty()
        {
            // Arrange
            WebHookUser       user          = new WebHookUser();
            Mock <IPrincipal> principalMock = new Mock <IPrincipal>();

            principalMock.Setup(p => p.Identity.Name)
            .Returns("TestUser")
            .Verifiable();

            // Act
            string actual = await user.GetUserIdAsync(principalMock.Object);

            // Assert
            Assert.Equal("TestUser", actual);
        }
        public async Task GetUserIdAsync_Throws_IfInvalidUser()
        {
            WebHookUser       user          = new WebHookUser();
            Mock <IPrincipal> principalMock = new Mock <IPrincipal>();

            // Act
            InvalidOperationException ex = await Assert.ThrowsAsync <InvalidOperationException>(() => user.GetUserIdAsync(principalMock.Object));

            // Assert
            Assert.Equal("Could not determine the user ID from the given principal.", ex.Message);
        }