Пример #1
0
        public async Task <IActionResult> AddResourceToActionPlan(
            int selfAssessmentId,
            int resourceReferenceId,
            ReturnPageQuery returnPageQuery
            )
        {
            var delegateId = User.GetCandidateIdKnownNotNull();

            if (!actionPlanService.ResourceCanBeAddedToActionPlan(resourceReferenceId, delegateId))
            {
                return(NotFound());
            }

            try
            {
                await actionPlanService.AddResourceToActionPlan(resourceReferenceId, delegateId, selfAssessmentId);
            }
            catch (ResourceNotFoundException e)
            {
                if (!e.ApiIsAccessible)
                {
                    return(NotFound());
                }

                var assessment = selfAssessmentService.GetSelfAssessmentForCandidateById(delegateId, selfAssessmentId);
                var model      = new ResourceRemovedViewModel(assessment !);
                return(View("ResourceRemovedErrorPage", model));
            }

            var routeData = returnPageQuery.ToRouteDataDictionary();

            routeData.Add("selfAssessmentId", selfAssessmentId.ToString());
            return(RedirectToAction("RecommendedLearning", "RecommendedLearning", routeData, returnPageQuery.ItemIdToReturnTo));
        }
Пример #2
0
        public async Task AddResourceToActionPlan_returns_not_found_when_resource_already_in_action_plan()
        {
            // Given
            const int resourceReferenceId = 1;

            A.CallTo(() => actionPlanService.ResourceCanBeAddedToActionPlan(resourceReferenceId, DelegateId))
            .Returns(false);

            // When
            var result = await controller.AddResourceToActionPlan(SelfAssessmentId, resourceReferenceId);

            // Then
            result.Should().BeNotFoundResult();
            A.CallTo(() => actionPlanService.AddResourceToActionPlan(A <int> ._, A <int> ._, A <int> ._))
            .MustNotHaveHappened();
        }
Пример #3
0
        public async Task <IActionResult> AddResourceToActionPlan(int selfAssessmentId, int resourceReferenceId)
        {
            var delegateId = User.GetCandidateIdKnownNotNull();

            if (!actionPlanService.ResourceCanBeAddedToActionPlan(resourceReferenceId, delegateId))
            {
                return(NotFound());
            }

            await actionPlanService.AddResourceToActionPlan(resourceReferenceId, delegateId, selfAssessmentId);

            return(RedirectToAction("RecommendedLearning", new { selfAssessmentId }));
        }
Пример #4
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);
        }