Esempio n. 1
0
        public async Task <IActionResult> ViewResource(int resourceReferenceId)
        {
            var delegateId        = User.GetCandidateIdKnownNotNull();
            var learningHubAuthId = userService.GetDelegateUserLearningHubAuthId(delegateId);

            if (!learningHubAuthId.HasValue)
            {
                var sessionLinkingId = Guid.NewGuid().ToString();
                HttpContext.Session.SetString(LinkLearningHubRequest.SessionIdentifierKey, sessionLinkingId);

                var linkingUrl = learningHubLinkService.GetLinkingUrlForResource(resourceReferenceId, sessionLinkingId);
                return(Redirect(linkingUrl));
            }

            var(resource, _) = await learningHubResourceService.GetResourceByReferenceId(resourceReferenceId);

            var resourceUrl = resource?.Link;

            if (string.IsNullOrEmpty(resourceUrl))
            {
                return(NotFound());
            }

            var loginUrl =
                learningHubLinkService.GetLoginUrlForDelegateAuthIdAndResourceUrl(
                    resourceUrl,
                    learningHubAuthId !.Value
                    );

            return(Redirect(loginUrl));
        }
        public void GetLinkingUrlForResource_returns_expected_value()
        {
            // Given
            const int    referenceId        = 5;
            const string sessionReferenceId = "abcdefghijklmnopqrstuvwxyz";

            // When
            var url = learningHubLinkService.GetLinkingUrlForResource(referenceId, sessionReferenceId);

            // Then
            url.Should().Be(
                $"www.example.com/to-the-past?clientCode=test&state={sessionReferenceId}_refId%3a{referenceId}&hash=hash_brown"
                );
        }
        public async Task ViewResource_returns_redirect_result_to_create_user_when_user_not_linked()
        {
            // Given
            A.CallTo(() => userService.GetDelegateUserLearningHubAuthId(A <int> ._)).Returns(null);
            A.CallTo(() => learningHubLinkService.GetLinkingUrlForResource(5, A <string> ._))
            .Returns("www.example.com/link");

            // When
            var result = await controller.ViewResource(5);

            // Then
            result.Should().BeRedirectResult().WithUrl(
                "www.example.com/link"
                );
            A.CallTo(() => controller.HttpContext.Session.Set(LinkLearningHubRequest.SessionIdentifierKey, A <byte[]> ._))
            .MustHaveHappenedOnceExactly();
        }