Exemplo n.º 1
0
        public void TryGetCurrentPupilWithUnknownUser(PupilDto pupil, bool success)
        {
            "Given that the pupil has the required claim"
            .x(()
               => _httpContextAccessor
               .Setup(_ => _.HttpContext.User.HasClaim(It.IsAny <Predicate <Claim> >()))
               .Returns(false));

            "And that the pupil 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 pupil"
            .x(()
               => success = _authenticationService.TryGetCurrentPupil(out pupil));

            "Then the system should not have been able to fetch the user"
            .x(() =>
            {
                pupil.Should().BeNull();
                success.Should().BeFalse();
            });
        }
Exemplo n.º 2
0
        public void TryGetCurrentPupilWithBadRole(PupilDto pupil, bool success)
        {
            "Given that the pupil 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 pupil"
            .x(()
               => success = _authenticationService.TryGetCurrentPupil(out pupil));

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

            "And that the pupil 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(() =>
            {
                _pupilService
                .Setup(_ => _.GetPupil(It.IsAny <int>()))
                .Returns(new PupilDto());

                success = _authenticationService.TryGetCurrentPupil(out pupil);
            });

            "Then the system should have successfully fetch the moderator"
            .x(() =>
            {
                pupil.Should().NotBeNull();
                success.Should().BeTrue();
            });
        }