Provides a default implementation of IWebHookUser for getting information about a user.
Inheritance: IWebHookUser
        public ApiControllerExtensionsTests()
        {
            HttpConfiguration config = new HttpConfiguration();
            IWebHookUser user = new WebHookUser();

            _managerMock = new Mock<IWebHookManager>();
            _resolverMock = new Mock<IDependencyResolver>();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookManager)))
                .Returns(_managerMock.Object)
                .Verifiable();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
                .Returns(user)
                .Verifiable();

            config.DependencyResolver = _resolverMock.Object;

            ClaimsIdentity identity = new ClaimsIdentity();
            Claim claim = new Claim(ClaimTypes.Name, "TestUser");
            identity.AddClaim(claim);
            _principal = new ClaimsPrincipal(identity);

            _context = new HttpRequestContext()
            {
                Configuration = config,
                Principal = _principal
            };
            _controller = new TestController()
            {
                RequestContext = _context
            };
        }
        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);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
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 void Dispose()
 {
     WebHookUser.Reset();
 }