Пример #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 async Task ViewResource_returns_redirect_to_login_result_when_user_linked()
        {
            // Given
            var authId          = 1;
            var resourceUrl     = "De/Humani/Corporis/Fabrica";
            var resourceDetails = new ResourceReferenceWithResourceDetails {
                Link = resourceUrl
            };

            A.CallTo(() => userService.GetDelegateUserLearningHubAuthId(A <int> ._)).Returns(authId);
            A.CallTo(() => learningHubResourceService.GetResourceByReferenceId(5))
            .Returns((resourceDetails, false));
            A.CallTo(() => learningHubLinkService.GetLoginUrlForDelegateAuthIdAndResourceUrl(resourceUrl, authId))
            .Returns("www.example.com/login");

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

            // Then
            result.Should().BeRedirectResult().WithUrl(
                "www.example.com/login"
                );
        }
Пример #3
0
        public async Task LaunchLearningResource_skips_warning_if_already_dismissed_and_redirects_to_resource()
        {
            // Given
            A.CallTo(() => userService.GetDelegateUserById(DelegateId))
            .Returns(UserTestHelper.GetDefaultDelegateUser(DelegateId, hasDismissedLhLoginWarning: true));

            // When
            var result = await controller.LaunchLearningResource(ResourceReferenceId);

            // Then
            result.Should().BeRedirectToActionResult().WithActionName("ViewResource").WithControllerName("SignpostingSso")
            .WithRouteValue("resourceReferenceId", ResourceReferenceId);
            A.CallTo(() => userService.DelegateUserLearningHubAccountIsLinked(A <int> ._)).MustNotHaveHappened();
            A.CallTo(() => learningHubResourceService.GetResourceByReferenceId(A <int> ._)).MustNotHaveHappened();
        }
Пример #4
0
        public void SetUp()
        {
            userService = A.Fake <IUserService>();
            learningHubResourceService = A.Fake <ILearningHubResourceService>();
            actionPlanService          = A.Fake <IActionPlanService>();

            A.CallTo(() => actionPlanService.UpdateActionPlanResourcesLastAccessedDateIfPresent(A <int> ._, A <int> ._))
            .DoesNothing();
            A.CallTo(() => userService.GetDelegateUserById(DelegateId))
            .Returns(UserTestHelper.GetDefaultDelegateUser(DelegateId));
            A.CallTo(() => userService.DelegateUserLearningHubAccountIsLinked(DelegateId)).Returns(false);
            A.CallTo(() => learningHubResourceService.GetResourceByReferenceId(ResourceReferenceId))
            .Returns((new ResourceReferenceWithResourceDetails(), false));

            controller = new SignpostingController(
                userService,
                learningHubResourceService,
                actionPlanService
                ).WithDefaultContext().WithMockUser(true, delegateId: DelegateId);
        }
Пример #5
0
        public void AddResourceToActionPlan_calls_expected_insert_data_service_methods()
        {
            // Given
            const int    learningResourceReferenceId = 1;
            const int    delegateId            = 2;
            const int    selfAssessmentId      = 3;
            const int    candidateAssessmentId = 4;
            const string resourceName          = "Activity";
            const string resourceLink          = "www.test.com";
            const int    learningLogId         = 4;
            const int    learningHubResourceId = 6;

            var addedDate = new DateTime(2021, 11, 1);

            A.CallTo(() => clockService.UtcNow).Returns(addedDate);

            A.CallTo(
                () => learningResourceReferenceDataService.GetLearningHubResourceReferenceById(
                    learningResourceReferenceId
                    )
                ).Returns(learningHubResourceId);

            var resource = new ResourceReferenceWithResourceDetails {
                Title = resourceName, Link = resourceLink
            };

            A.CallTo(() => learningHubResourceService.GetResourceByReferenceId(learningHubResourceId))
            .Returns((resource, true));

            var resourceCompetencies = new[] { 1, 2, 3, 4, 5, 6, 7, 8 };

            A.CallTo(
                () => competencyLearningResourcesDataService.GetCompetencyIdsLinkedToResource(
                    learningResourceReferenceId
                    )
                ).Returns(resourceCompetencies);

            var assessmentCompetencies = new[] { 2, 3, 5, 6, 8, 9, 10 };

            A.CallTo(() => selfAssessmentDataService.GetCompetencyIdsForSelfAssessment(selfAssessmentId))
            .Returns(assessmentCompetencies);

            A.CallTo(() => selfAssessmentDataService.GetCandidateAssessments(delegateId, selfAssessmentId))
            .Returns(
                new[] { Builder <CandidateAssessment> .CreateNew().With(ca => ca.Id = candidateAssessmentId).Build() }
                );

            A.CallTo(
                () => learningLogItemsDataService.InsertLearningLogItem(
                    A <int> ._,
                    A <DateTime> ._,
                    A <string> ._,
                    A <string> ._,
                    A <int> ._
                    )
                ).Returns(learningLogId);

            var expectedMatchingCompetencies = new[] { 2, 3, 5, 6, 8 };

            // When
            actionPlanService.AddResourceToActionPlan(learningResourceReferenceId, delegateId, selfAssessmentId);

            // Then
            A.CallTo(
                () => learningLogItemsDataService.InsertLearningLogItem(
                    delegateId,
                    addedDate,
                    resourceName,
                    resourceLink,
                    learningResourceReferenceId
                    )
                ).MustHaveHappenedOnceExactly();
            A.CallTo(
                () => learningLogItemsDataService.InsertCandidateAssessmentLearningLogItem(
                    candidateAssessmentId,
                    learningLogId
                    )
                ).MustHaveHappenedOnceExactly();

            foreach (var competencyId in expectedMatchingCompetencies)
            {
                A.CallTo(
                    () => learningLogItemsDataService.InsertLearningLogItemCompetencies(
                        learningLogId,
                        competencyId,
                        addedDate
                        )
                    ).MustHaveHappenedOnceExactly();
            }

            A.CallTo(
                () => learningLogItemsDataService.InsertLearningLogItemCompetencies(learningLogId, A <int> ._, addedDate)
                ).MustHaveHappened(5, Times.Exactly);
        }