Exemple #1
0
        public void TryGetCurrentModeratorWithUnknownUser(ModeratorDto moderator, bool success)
        {
            "Given that the moderator has the required claim"
            .x(()
               => _httpContextAccessor
               .Setup(_ => _.HttpContext.User.HasClaim(It.IsAny <Predicate <Claim> >()))
               .Returns(false));

            "And that the moderator identifier does not exists in its JWT"
            .x(() =>
            {
                var mockedClaimsPrincipal = new Mock <ClaimsPrincipal>();

                mockedClaimsPrincipal
                .Setup(_ => _.FindFirst(It.IsAny <string>()))
                .Returns((Claim)null);

                _httpContextAccessor
                .SetupGet(_ => _.HttpContext.User)
                .Returns(mockedClaimsPrincipal.Object);
            });

            "When the system attempts to retrieve the current moderator"
            .x(()
               => success = _authenticationService.TryGetCurrentModerator(out moderator));

            "Then the system should not have been able to fetch the user"
            .x(() =>
            {
                moderator.Should().BeNull();
                success.Should().BeFalse();
            });
        }
Exemple #2
0
        public void TryGetCurrentModeratorWithBadRole(ModeratorDto moderator, bool success)
        {
            "Given that the moderator does not have the required claim"
            .x(()
               => _httpContextAccessor
               .Setup(_ => _.HttpContext.User.HasClaim(It.IsAny <Predicate <Claim> >()))
               .Returns(true));

            "When the system attempts to retrieve the current moderator"
            .x(()
               => success = _authenticationService.TryGetCurrentModerator(out moderator));

            "Then the system should not have been able to fetch the user"
            .x(() =>
            {
                moderator.Should().BeNull();
                success.Should().BeFalse();
            });
        }
Exemple #3
0
        public void TryGetCurrentModerator(ModeratorDto moderator, bool success)
        {
            "Given that the moderator has the required claim"
            .x(()
               => _httpContextAccessor
               .Setup(_ => _.HttpContext.User.HasClaim(It.IsAny <Predicate <Claim> >()))
               .Returns(false));

            "And that the moderator has the NameIdentifier claim"
            .x(() =>
            {
                var mockedClaimsPrincipal = new Mock <ClaimsPrincipal>();

                mockedClaimsPrincipal
                .Setup(_ => _.FindFirst(It.IsAny <string>()))
                .Returns(
                    new Claim(ClaimTypes.NameIdentifier, _fixture.Create <int>().ToString()));

                _httpContextAccessor
                .SetupGet(_ => _.HttpContext.User)
                .Returns(mockedClaimsPrincipal.Object);
            });


            "When the system retrieves the current moderator"
            .x(() =>
            {
                _moderatorService
                .Setup(_ => _.GetModerator(It.IsAny <int>()))
                .Returns(new ModeratorDto());

                success = _authenticationService.TryGetCurrentModerator(out moderator);
            });

            "Then the system should not have been able to fetch the user"
            .x(() =>
            {
                moderator.Should().NotBeNull();
                success.Should().BeTrue();
            });
        }