public void IsLearningHubAccountLinked_returns_true_when_user_has_authid()
        {
            // Given
            const int delegateId        = 3;
            const int learningHubAuthId = 1;

            A.CallTo(() => userDataService.GetDelegateUserLearningHubAuthId(delegateId))
            .Returns(learningHubAuthId);

            // When
            var result = learningHubLinkService.IsLearningHubAccountLinked(delegateId);

            // Then
            result.Should().BeTrue();
        }
        public void LinkLearningHubSso_invalid_state_throws_exception()
        {
            // Given
            controller.ModelState.AddModelError("Hash", "Required.");

            // When
            Action a = () => controller.LinkLearningHubSso(new LinkLearningHubRequest());

            // Then
            using (new AssertionScope())
            {
                a.Should().Throw <LearningHubLinkingRequestException>();
                A.CallTo(
                    () => learningHubLinkService.ValidateLinkingRequestAndExtractDestinationResourceId(
                        A <LinkLearningHubRequest> ._,
                        A <string> ._
                        )
                    )
                .MustNotHaveHappened();
                A.CallTo(() => learningHubLinkService.IsLearningHubAccountLinked(A <int> ._)).MustNotHaveHappened();
                A.CallTo(() => learningHubLinkService.LinkLearningHubAccountIfNotLinked(A <int> ._, A <int> ._))
                .MustNotHaveHappened();
            }
        }
        public void Setup()
        {
            learningHubLinkService     = A.Fake <ILearningHubLinkService>();
            learningHubResourceService = A.Fake <ILearningHubResourceService>();
            userService = A.Fake <IUserService>();

            controller = new SignpostingSsoController(
                learningHubLinkService,
                learningHubResourceService,
                userService
                )
                         .WithDefaultContext()
                         .WithMockSessionData(new Dictionary <string, string>())
                         .WithMockUser(true);

            A.CallTo(() => learningHubLinkService.IsLearningHubAccountLinked(A <int> ._)).Returns(true);
        }
Example #4
0
        public IActionResult LinkLearningHubSso([FromQuery] LinkLearningHubRequest linkLearningHubRequest)
        {
            if (!ModelState.IsValid)
            {
                throw new LearningHubLinkingRequestException("Invalid Learning Hub request.");
            }

            var learningHubResourcedId = learningHubLinkService.ValidateLinkingRequestAndExtractDestinationResourceId(
                linkLearningHubRequest,
                HttpContext.Session.GetString(LinkLearningHubRequest.SessionIdentifierKey)
                );

            var delegateId             = User.GetCandidateIdKnownNotNull();
            var isAccountAlreadyLinked = learningHubLinkService.IsLearningHubAccountLinked(delegateId);

            learningHubLinkService.LinkLearningHubAccountIfNotLinked(delegateId, linkLearningHubRequest.UserId);

            var model = new LinkLearningHubViewModel(isAccountAlreadyLinked, learningHubResourcedId);

            return(View("../LinkLearningHubSso", model));
        }