string MailSenderAddress) GetMailConfig()
        {
            var mailServerUsername = configDataService.GetConfigValue(ConfigDataService.MailUsername)
                                     ?? throw new ConfigValueMissingException
                                           (
                                               configDataService.GetConfigValueMissingExceptionMessage("MailServerUsername")
                                           );
            var mailServerPassword = configDataService.GetConfigValue(ConfigDataService.MailPassword)
                                     ?? throw new ConfigValueMissingException
                                           (
                                               configDataService.GetConfigValueMissingExceptionMessage("MailServerPassword")
                                           );
            var mailServerAddress = configDataService.GetConfigValue(ConfigDataService.MailServer)
                                    ?? throw new ConfigValueMissingException
                                          (
                                              configDataService.GetConfigValueMissingExceptionMessage("MailServerAddress")
                                          );
            var mailServerPortString = configDataService.GetConfigValue(ConfigDataService.MailPort)
                                       ?? throw new ConfigValueMissingException
                                             (
                                                 configDataService.GetConfigValueMissingExceptionMessage("MailServerPortString")
                                             );
            var mailSenderAddress = configDataService.GetConfigValue(ConfigDataService.MailFromAddress)
                                    ?? throw new ConfigValueMissingException
                                          (
                                              configDataService.GetConfigValueMissingExceptionMessage("MailFromAddress")
                                          );

            var mailServerPort = int.Parse(mailServerPortString);

            return(mailServerUsername, mailServerPassword, mailServerAddress, mailServerPort, mailSenderAddress);
        }
예제 #2
0
        public IActionResult AccessibilityHelp()
        {
            var accessibilityText = configDataService.GetConfigValue(ConfigDataService.AccessibilityHelpText);

            if (accessibilityText == null)
            {
                logger.LogError("Accessibility text from Config table is null");
                return(StatusCode(500));
            }

            var model = new AccessibilityHelpViewModel(accessibilityText);

            return(View(model));
        }
예제 #3
0
        public void Trying_to_send_mail_with_null_config_values_should_throw_an_exception(string configKey)
        {
            // Given
            A.CallTo(() => configDataService.GetConfigValue(configKey)).Returns(null);

            // Then
            Assert.Throws <ConfigValueMissingException>(() => emailService.SendEmail(EmailTestHelper.GetDefaultEmail()));
        }
        public UriBuilder GetDLSUriBuilder()
        {
            var trackingSystemBaseUrl = configDataService.GetConfigValue(ConfigDataService.AppBaseUrl) ??
                                        throw new ConfigValueMissingException(configDataService.GetConfigValueMissingExceptionMessage("AppBaseUrl"));

            ;
            return(new UriBuilder(trackingSystemBaseUrl));
        }
예제 #5
0
        GetRecommendedLearningForSelfAssessment_calls_learning_hub_resource_service_with_only_the_first_MaxSignpostedResources_ids_ordered_by_descending_recommendation_score()
        {
            // Given
            var competencyLearningResources = Builder <CompetencyLearningResource> .CreateListOfSize(50).Build();

            var resourceReferences =
                Builder <ResourceReferenceWithResourceDetails> .CreateListOfSize(50)
                .All()
                .With(rr => rr.Catalogue = new Catalogue {
                Name = ResourceCatalogue
            })
                .Build()
                .ToList();

            var clientResponse = new BulkResourceReferences
            {
                ResourceReferences            = resourceReferences,
                UnmatchedResourceReferenceIds = new List <int>(),
            };

            A.CallTo(() => configDataService.GetConfigValue("MaxSignpostedResources")).Returns("3");

            A.CallTo(() => learningHubResourceService.GetResourceReferenceDetailsByReferenceIds(A <List <int> > ._))
            .Returns(resourceReferences);

            A.CallTo(() => learningHubResourceService.GetBulkResourcesByReferenceIds(A <List <int> > ._))
            .Returns((clientResponse, false));

            A.CallTo(() => selfAssessmentDataService.GetCompetencyIdsForSelfAssessment(SelfAssessmentId))
            .Returns(new[] { CompetencyId });

            A.CallTo(
                () => competencyLearningResourcesDataService.GetActiveCompetencyLearningResourcesByCompetencyId(
                    CompetencyId
                    )
                ).Returns(competencyLearningResources);

            // When
            await recommendedLearningService.GetRecommendedLearningForSelfAssessment(SelfAssessmentId, DelegateId);

            // Then
            A.CallTo(
                () => learningHubResourceService.GetResourceReferenceDetailsByReferenceIds(
                    A <List <int> > .That.IsSameSequenceAs(Enumerable.Range(1, 50).ToList())
                    )
                )
            .MustHaveHappenedOnceExactly();

            A.CallTo(
                () => learningHubResourceService.GetBulkResourcesByReferenceIds(
                    A <List <int> > .That.IsSameSequenceAs(new List <int> {
                50, 49, 48
            })
                    )
                ).MustHaveHappenedOnceExactly();
        }
예제 #6
0
        public void Setup()
        {
            emailDataService  = A.Fake <IEmailDataService>();
            configDataService = A.Fake <IConfigDataService>();
            var smtpClientFactory = A.Fake <ISmtpClientFactory>();

            smtpClient = A.Fake <ISmtpClient>();
            A.CallTo(() => smtpClientFactory.GetSmtpClient()).Returns(smtpClient);

            A.CallTo(() => configDataService.GetConfigValue(ConfigDataService.MailPort)).Returns("25");
            A.CallTo(() => configDataService.GetConfigValue(ConfigDataService.MailUsername)).Returns("username");
            A.CallTo(() => configDataService.GetConfigValue(ConfigDataService.MailPassword)).Returns("password");
            A.CallTo(() => configDataService.GetConfigValue(ConfigDataService.MailServer)).Returns("smtp.example.com");
            A.CallTo(() => configDataService.GetConfigValue(ConfigDataService.MailFromAddress)).Returns("*****@*****.**");

            var logger = A.Fake <ILogger <EmailService> >();

            emailService = new EmailService(emailDataService, configDataService, smtpClientFactory, logger);
        }
예제 #7
0
        GetRecommendedLearningForSelfAssessment(
            int selfAssessmentId,
            int delegateId
            )
        {
            var hasMaxSignpostedResources = Int32.TryParse(
                configDataService.GetConfigValue(ConfigDataService.MaxSignpostedResources),
                out var maxSignpostedResources
                );

            var competencyIds = selfAssessmentDataService.GetCompetencyIdsForSelfAssessment(selfAssessmentId);
            var competencyLearningResources = new List <CompetencyLearningResource>();

            foreach (var competencyId in competencyIds)
            {
                var learningHubResourceReferencesForCompetency =
                    competencyLearningResourcesDataService.GetActiveCompetencyLearningResourcesByCompetencyId(
                        competencyId
                        );

                competencyLearningResources.AddRange(learningHubResourceReferencesForCompetency);
            }

            var resourceReferences = competencyLearningResources.Select(
                clr => (clr.LearningHubResourceReferenceId, clr.LearningResourceReferenceId)
                ).Distinct().ToDictionary(
                x => x.LearningHubResourceReferenceId,
                x => x.LearningResourceReferenceId
                );

            var uniqueLearningHubReferenceIds = competencyLearningResources.Select(
                clr => clr.LearningHubResourceReferenceId
                ).Distinct().ToList();

            var resources =
                learningHubResourceService.GetResourceReferenceDetailsByReferenceIds(uniqueLearningHubReferenceIds);

            var delegateLearningLogItems = learningLogItemsDataService.GetLearningLogItems(delegateId);

            var recommendedResources = resources.Select(
                rr => GetPopulatedRecommendedResource(
                    selfAssessmentId,
                    delegateId,
                    resourceReferences[rr.RefId],
                    delegateLearningLogItems,
                    rr,
                    competencyLearningResources
                    )
                )
                                       .WhereNotNull()
                                       .OrderByDescending(resource => resource.RecommendationScore);

            var bestRecommendedResources = hasMaxSignpostedResources
                ? recommendedResources.Take(maxSignpostedResources).ToList()
                : recommendedResources.ToList();

            var apiResources =
                await learningHubResourceService.GetBulkResourcesByReferenceIds(
                    bestRecommendedResources.Select(resource => resource.LearningHubReferenceId).ToList()
                    );

            var recommendedResourcesPresentInApi = bestRecommendedResources.Where(
                resource => !apiResources.bulkResourceReferences.UnmatchedResourceReferenceIds.Contains(
                    resource.LearningHubReferenceId
                    )
                ).ToList();

            return(recommendedResourcesPresentInApi, apiResources.apiIsAccessible);
        }