Esempio n. 1
0
        public void Test_SaveInstitutionEnrichment_should__argument_exception(string instCode, string email)
        {
            const string trainWithDisabilityText = "TrainWithDisabilily Text";
            const string trainWithUsText         = "TrainWithUs Text";
            const string instDesc = "school1 description enrichement";

            var enrichmentService = new EnrichmentService(Context);
            var model             = new UcasProviderEnrichmentPostModel
            {
                EnrichmentModel = new ProviderEnrichmentModel
                {
                    TrainWithDisability            = trainWithDisabilityText,
                    TrainWithUs                    = trainWithUsText,
                    AccreditingProviderEnrichments = new List <AccreditingProviderEnrichment>
                    {
                        new AccreditingProviderEnrichment
                        {
                            UcasProviderCode = AccreditingInstCode,
                            Description      = instDesc,
                        }
                    }
                }
            };

            Assert.Throws <ArgumentException>(() => enrichmentService.SaveProviderEnrichment(model, instCode, email));
        }
Esempio n. 2
0
        public void Test_PublishInstitutionEnrichment_should_return_false()
        {
            Context.ProviderEnrichments.RemoveRange(Context.ProviderEnrichments);
            Context.Save();

            var enrichmentService = new EnrichmentService(Context);
            var publishResults    = enrichmentService.PublishProviderEnrichment(ProviderInstCode.ToLower(), Email);

            publishResults.Should().BeFalse();
        }
        public void Test_SaveCourseEnrichment_should__argument_exception(string instCode, string email)
        {
            const string aboutCourseText = "About Course Text";

            var enrichmentService = new EnrichmentService(Context);
            var model             = new CourseEnrichmentModel
            {
                AboutCourse = aboutCourseText,
            };

            Assert.Throws <ArgumentException>(() => enrichmentService.SaveCourseEnrichment(model, instCode, UcasCourseCode, email));
        }
Esempio n. 4
0
        public void TestGetInstitutionEnrichmentWithDifferentUserFromSavedUser()
        {
            Context = ContextLoader.GetDbContext(Config);//refresh the context

            var enrichmentService = new EnrichmentService(Context);
            //test get the enrichment using user2
            var result = enrichmentService.GetProviderEnrichment(ProviderInstCode, Email2);

            result.Should().NotBeNull();
            result.EnrichmentModel.Should().NotBeNull();
            result.EnrichmentModel.TrainWithDisability.Should().BeEquivalentTo(TrainWithDisabilityText);
            result.EnrichmentModel.TrainWithUs.Should().BeEquivalentTo(TrainWithUsText);
            result.LastPublishedTimestampUtc.Should().BeNull();
            result.Status.Should().BeEquivalentTo(EnumStatus.Draft);
        }
        public void EnrichmentDataSurvivesDeleteAndRecreate()
        {
            const string aboutCourseText = "About Course Text";
            // Arrange
            var enrichmentService = new EnrichmentService(Context);
            var dataService       = new DataService(Context, enrichmentService, new Mock <ILogger <DataService> >().Object);
            var sourceModel       = new CourseEnrichmentModel
            {
                AboutCourse = aboutCourseText,
            };

            enrichmentService.SaveCourseEnrichment(sourceModel, _ucasInstitution.ProviderCode, UcasCourseCode, Email);

            // Act
            var ucasPayload = new UcasPayload
            {
                // todo: test with change of this institution: https://trello.com/c/e1FwXuYk/133-ucas-institutions-dont-get-updated-during-ucas-import
                Institutions = new List <UcasInstitution>
                {
                    new UcasInstitution
                    {
                        InstCode = _ucasInstitution.ProviderCode,
                        InstFull = "Rebranded Provider",
                    },
                    new UcasInstitution
                    {
                        InstCode = AccreditingInstCode,
                        InstFull = "Rebranded Accrediting Provider",
                    },
                },
                Courses = new List <UcasCourse>
                {
                    new UcasCourse
                    {
                        InstCode            = _ucasInstitution.ProviderCode,
                        CrseCode            = "CC11",
                        AccreditingProvider = AccreditingInstCode,
                    },
                },
            };

            new UcasDataMigrator(Context, new Mock <Serilog.ILogger>().Object, ucasPayload).UpdateUcasData();

            // Assert
            var res = enrichmentService.GetCourseEnrichment(_ucasInstitution.ProviderCode, UcasCourseCode, Email);

            res.EnrichmentModel.AboutCourse.Should().Be(sourceModel.AboutCourse);
        }
        public void Test_PublishCourseEnrichment_should_argument_exception(string instCode, string email)
        {
            var enrichmentService = new EnrichmentService(Context);

            Assert.Throws <ArgumentException>(() => enrichmentService.PublishCourseEnrichment(instCode, UcasCourseCode, email));
        }
        public void Test_CourseEnrichment_And_Publishing_Workflow()
        {
            var enrichmentService = new EnrichmentService(Context);

            var courseEnrichment = enrichmentService.GetCourseEnrichment(ProviderInstCode, UcasCourseCode.ToLower(), Email);

            courseEnrichment.CourseCode.Should().BeNull("we haven't enriched this course yet");
            var emptyMetadata = enrichmentService.GetCourseEnrichmentMetadata(ProviderInstCode, Email);

            emptyMetadata.Count.Should().Be(0, "we haven't enriched any courses yet");

            //test saving sparse model
            var sourceModel = new CourseEnrichmentModel
            {
                AboutCourse = "About Course Text",
            };

            enrichmentService.SaveCourseEnrichment(sourceModel, ProviderInstCode.ToLower(), UcasCourseCode.ToLower(), Email);

            //test saving full model
            sourceModel.InterviewProcess        = "eg InterviewProcess";
            sourceModel.HowSchoolPlacementsWork = "eg HowSchoolPlacementsWork";
            sourceModel.CourseLength            = "eg CourseLength";
            sourceModel.FeeUkEu           = 1.234m;
            sourceModel.FeeInternational  = 42000.24m;
            sourceModel.SalaryDetails     = "eg SalaryDetails";
            sourceModel.FeeDetails        = "eg FeeDetails";
            sourceModel.FinancialSupport  = "eg FinancialSupport";
            sourceModel.Qualifications    = "eg Qualifications";
            sourceModel.PersonalQualities = "eg PersonalQualities";
            sourceModel.OtherRequirements = "eg OtherRequirements";
            enrichmentService.SaveCourseEnrichment(sourceModel, ProviderInstCode.ToLower(), UcasCourseCode.ToLower(), Email);

            //test get
            var courseEnrichmentMetadata = enrichmentService.GetCourseEnrichmentMetadata(ProviderInstCode, Email);

            courseEnrichmentMetadata.Count.Should().Be(1, "we have enriched one course");
            courseEnrichmentMetadata.Single().Status.Should().Be(EnumStatus.Draft);
            var result = enrichmentService.GetCourseEnrichment(ProviderInstCode.ToLower(), UcasCourseCode.ToLower(), Email);

            result.Should().NotBeNull();
            result.EnrichmentModel.Should().NotBeNull();
            result.EnrichmentModel.AboutCourse.Should().BeEquivalentTo(sourceModel.AboutCourse);
            result.EnrichmentModel.InterviewProcess.Should().BeEquivalentTo(sourceModel.InterviewProcess);
            result.EnrichmentModel.HowSchoolPlacementsWork.Should().BeEquivalentTo(sourceModel.HowSchoolPlacementsWork);
            result.EnrichmentModel.CourseLength.Should().BeEquivalentTo(sourceModel.CourseLength);
            result.EnrichmentModel.FeeUkEu.Should().Be(sourceModel.FeeUkEu);
            result.EnrichmentModel.FeeInternational.Should().Be(sourceModel.FeeInternational);
            result.EnrichmentModel.SalaryDetails.Should().BeEquivalentTo(sourceModel.SalaryDetails);
            result.EnrichmentModel.FeeDetails.Should().BeEquivalentTo(sourceModel.FeeDetails);
            result.EnrichmentModel.FinancialSupport.Should().BeEquivalentTo(sourceModel.FinancialSupport);
            result.EnrichmentModel.Qualifications.Should().BeEquivalentTo(sourceModel.Qualifications);
            result.EnrichmentModel.PersonalQualities.Should().BeEquivalentTo(sourceModel.PersonalQualities);
            result.EnrichmentModel.OtherRequirements.Should().BeEquivalentTo(sourceModel.OtherRequirements);
            result.LastPublishedTimestampUtc.Should().BeNull();
            result.Status.Should().BeEquivalentTo(EnumStatus.Draft);

            //test update
            sourceModel.AboutCourse = "About Course Text updated";

            enrichmentService.SaveCourseEnrichment(sourceModel, ProviderInstCode.ToLower(), UcasCourseCode, Email);
            var updateResult = enrichmentService.GetCourseEnrichment(ProviderInstCode, UcasCourseCode, Email);

            updateResult.EnrichmentModel.AboutCourse.Should().BeEquivalentTo(sourceModel.AboutCourse);
            updateResult.LastPublishedTimestampUtc.Should().BeNull();

            //publish
            var publishResults = enrichmentService.PublishCourseEnrichment(ProviderInstCode.ToLower(), UcasCourseCode, Email);

            publishResults.Should().BeTrue();
            var publishedMetadata = enrichmentService.GetCourseEnrichmentMetadata(ProviderInstCode, Email);

            publishedMetadata.Count.Should().Be(1, "we have enriched one course");
            publishedMetadata.Single().Status.Should().Be(EnumStatus.Published);
            var publishRecord = enrichmentService.GetCourseEnrichment(ProviderInstCode.ToLower(), UcasCourseCode, Email);

            publishRecord.Status.Should().BeEquivalentTo(EnumStatus.Published);
            publishRecord.LastPublishedTimestampUtc.Should().NotBeNull();
            var publishedRecord = Context.Courses.Single(c => c.CourseCode == UcasCourseCode && c.Provider.ProviderCode == ProviderInstCode);

            publishedRecord.ChangedAt.Should().BeCloseTo(publishRecord.UpdatedTimestampUtc.Value, 5000);

            //test save again after publish
            enrichmentService.SaveCourseEnrichment(sourceModel, ProviderInstCode.ToLower(), UcasCourseCode, Email);
            var updateResult2 = enrichmentService.GetCourseEnrichment(ProviderInstCode, UcasCourseCode, Email);

            updateResult2.EnrichmentModel.AboutCourse.Should().BeEquivalentTo(sourceModel.AboutCourse);
            updateResult2.EnrichmentModel.OtherRequirements.Should().BeEquivalentTo(sourceModel.OtherRequirements);
            updateResult2.Status.Should().BeEquivalentTo(EnumStatus.Draft);
            updateResult2.LastPublishedTimestampUtc.ToString().Should().BeEquivalentTo(publishRecord.LastPublishedTimestampUtc.ToString());

            //check number of records generated from this
            var draftCount     = Context.CourseEnrichments.Count(x => x.Status == EnumStatus.Draft);
            var publishedCount = Context.CourseEnrichments.Count(x => x.Status == EnumStatus.Published);

            publishedCount.Should().Be(1);
            draftCount.Should().Be(1);

            // test saving & loading a different course in the same institution
            var nextCourseModel = new CourseEnrichmentModel
            {
                AboutCourse = "Some other course",
            };

            enrichmentService.SaveCourseEnrichment(nextCourseModel, ProviderInstCode.ToLower(), OtherCourseCode, Email);
            var twoCourseMetadata = enrichmentService.GetCourseEnrichmentMetadata(ProviderInstCode, Email);

            twoCourseMetadata.Count.Should().Be(2, "we have enriched two courses in this institution");
            var nextCourseGet = enrichmentService.GetCourseEnrichment(ProviderInstCode.ToLower(), OtherCourseCode, Email);

            nextCourseGet.Should().NotBeNull();
            nextCourseGet.EnrichmentModel.Should().NotBeNull();
            nextCourseGet.EnrichmentModel.AboutCourse.Should().BeEquivalentTo(nextCourseModel.AboutCourse);
        }
Esempio n. 8
0
        public void Test_InstitutionEnrichment_And_Publishing_Workflow()
        {
            const string trainWithDisabilityText        = "TrainWithDisabilily Text";
            const string trainWithUsText                = "TrainWithUs Text";
            const string trainWithDisabilityUpdatedText = "TrainWithDisabilily Text updated";
            const string trainWithUsUpdatedText         = "TrainWithUs Text updated";
            const string instDesc = "school1 description enrichement";

            var enrichmentService = new EnrichmentService(Context);
            var model             = new UcasProviderEnrichmentPostModel
            {
                EnrichmentModel = new ProviderEnrichmentModel
                {
                    TrainWithDisability            = trainWithDisabilityText,
                    TrainWithUs                    = trainWithUsText,
                    AccreditingProviderEnrichments = new List <AccreditingProviderEnrichment>
                    {
                        new AccreditingProviderEnrichment
                        {
                            UcasProviderCode = AccreditingInstCode,
                            Description      = instDesc,
                        }
                    }
                }
            };

            var emptyEnrichment = enrichmentService.GetProviderEnrichment(ProviderInstCode, Email);

            emptyEnrichment.Status.Should().Be(EnumStatus.Draft, "no enrichments saved yet");

            //test save
            enrichmentService.SaveProviderEnrichment(model, ProviderInstCode.ToLower(), Email);

            //test get
            var result = enrichmentService.GetProviderEnrichment(ProviderInstCode.ToLower(), Email);

            result.Should().NotBeNull();
            result.EnrichmentModel.Should().NotBeNull();
            result.EnrichmentModel.TrainWithDisability.Should().BeEquivalentTo(trainWithDisabilityText);
            result.EnrichmentModel.TrainWithUs.Should().BeEquivalentTo(trainWithUsText);
            result.LastPublishedTimestampUtc.Should().BeNull();
            result.Status.Should().BeEquivalentTo(EnumStatus.Draft);
            result.EnrichmentModel.RegionCode.Should().Be(RegionCode);

            //test update
            var updatedmodel = new UcasProviderEnrichmentPostModel
            {
                EnrichmentModel = new ProviderEnrichmentModel
                {
                    TrainWithDisability            = trainWithDisabilityUpdatedText,
                    TrainWithUs                    = trainWithUsUpdatedText,
                    AccreditingProviderEnrichments = new List <AccreditingProviderEnrichment>
                    {
                        new AccreditingProviderEnrichment
                        {
                            UcasProviderCode = AccreditingInstCode,
                            Description      = instDesc,
                        }
                    }
                }
            };

            enrichmentService.SaveProviderEnrichment(updatedmodel, ProviderInstCode.ToLower(), Email);
            var updateResult = enrichmentService.GetProviderEnrichment(ProviderInstCode, Email);

            updateResult.EnrichmentModel.TrainWithDisability.Should().BeEquivalentTo(trainWithDisabilityUpdatedText);
            updateResult.EnrichmentModel.TrainWithUs.Should().BeEquivalentTo(trainWithUsUpdatedText);
            updateResult.LastPublishedTimestampUtc.Should().BeNull();
            updateResult.EnrichmentModel.RegionCode.Should().Be(RegionCode);

            //publish
            var publishResults = enrichmentService.PublishProviderEnrichment(ProviderInstCode.ToLower(), Email);

            publishResults.Should().BeTrue();
            var publishRecord = enrichmentService.GetProviderEnrichment(ProviderInstCode.ToLower(), Email);

            publishRecord.Status.Should().BeEquivalentTo(EnumStatus.Published);
            publishRecord.LastPublishedTimestampUtc.Should().NotBeNull();
            publishRecord.EnrichmentModel.RegionCode.Should().Be(RegionCode);
            var publishedProvider = Context.Providers.Single(p => p.ProviderCode == ProviderInstCode);

            publishedProvider.LastPublishedAt.Should().BeCloseTo(publishRecord.UpdatedTimestampUtc.Value, 5000);
            publishedProvider.ChangedAt.Should().BeCloseTo(publishRecord.UpdatedTimestampUtc.Value, 5000);

            //test save again after publish

            var afterPublishedModel = new UcasProviderEnrichmentPostModel
            {
                EnrichmentModel = new ProviderEnrichmentModel
                {
                    TrainWithDisability            = trainWithDisabilityText,
                    TrainWithUs                    = trainWithUsText,
                    AccreditingProviderEnrichments = new List <AccreditingProviderEnrichment>
                    {
                        new AccreditingProviderEnrichment
                        {
                            UcasProviderCode = AccreditingInstCode,
                            Description      = instDesc,
                        }
                    },
                    RegionCode = 909
                }
            };

            enrichmentService.SaveProviderEnrichment(afterPublishedModel, ProviderInstCode.ToLower(), Email);
            var updateResult2 = enrichmentService.GetProviderEnrichment(ProviderInstCode, Email);

            updateResult2.EnrichmentModel.TrainWithDisability.Should().BeEquivalentTo(trainWithDisabilityText);
            updateResult2.EnrichmentModel.TrainWithUs.Should().BeEquivalentTo(trainWithUsText);
            updateResult2.Status.Should().BeEquivalentTo(EnumStatus.Draft);
            updateResult2.LastPublishedTimestampUtc.ToString().Should().BeEquivalentTo(publishRecord.LastPublishedTimestampUtc.ToString());
            updateResult2.EnrichmentModel.RegionCode.Should().NotBe(RegionCode);

            //check number of records generated from this
            var draftCount     = Context.ProviderEnrichments.Count(x => x.Status == EnumStatus.Draft);
            var publishedCount = Context.ProviderEnrichments.Count(x => x.Status == EnumStatus.Published);

            publishedCount.Should().Be(1);
            draftCount.Should().Be(1);
        }
Esempio n. 9
0
        public void EnrichmentDataSurvivesDeleteAndRecreate()
        {
            // Arrange
            var enrichmentService = new EnrichmentService(Context);
            var dataService       = new DataService(Context, enrichmentService, new Mock <ILogger <DataService> >().Object);
            var sourceModel       = new UcasProviderEnrichmentPostModel
            {
                EnrichmentModel = new ProviderEnrichmentModel
                {
                    TrainWithUs                    = "Oh the grand old Duke of York",
                    TrainWithDisability            = "He had 10,000 men",
                    AccreditingProviderEnrichments = new List <AccreditingProviderEnrichment>
                    {
                        new AccreditingProviderEnrichment
                        {
                            UcasProviderCode = AccreditingInstCode,
                            Description      = "He marched them up to the top of the hill"
                        }
                    }
                },
            };

            enrichmentService.SaveProviderEnrichment(sourceModel, _ucasInstitution.ProviderCode, Email);

            // Act
            var ucasPayload = new UcasPayload
            {
                // todo: test with change of this institution: https://trello.com/c/e1FwXuYk/133-ucas-institutions-dont-get-updated-during-ucas-import
                Institutions = new List <UcasInstitution>
                {
                    new UcasInstitution
                    {
                        InstCode = _ucasInstitution.ProviderCode,
                        InstName = "Rebranded Provider",
                    },
                    new UcasInstitution
                    {
                        InstCode = AccreditingInstCode,
                        InstName = "Rebranded Accrediting Provider",
                    },
                },
                Courses = new List <UcasCourse>
                {
                    new UcasCourse
                    {
                        InstCode            = _ucasInstitution.ProviderCode,
                        CrseCode            = "CC11",
                        AccreditingProvider = AccreditingInstCode,
                    },
                },
            };

            new UcasDataMigrator(Context, new Mock <Serilog.ILogger>().Object, ucasPayload).UpdateUcasData();

            // Assert
            var res = enrichmentService.GetProviderEnrichment(_ucasInstitution.ProviderCode, Email);

            res.EnrichmentModel.TrainWithUs.Should().Be(sourceModel.EnrichmentModel.TrainWithUs);
            res.EnrichmentModel.TrainWithDisability.Should().Be(sourceModel.EnrichmentModel.TrainWithDisability);
            res.EnrichmentModel.AccreditingProviderEnrichments.Should().HaveCount(1);
            res.EnrichmentModel.AccreditingProviderEnrichments.Should().HaveSameCount(sourceModel.EnrichmentModel.AccreditingProviderEnrichments);
            res.EnrichmentModel.AccreditingProviderEnrichments[0].Description.Should().Be(sourceModel.EnrichmentModel.AccreditingProviderEnrichments[0].Description);
            res.EnrichmentModel.AccreditingProviderEnrichments[0].UcasProviderCode.Should().Be(sourceModel.EnrichmentModel.AccreditingProviderEnrichments[0].UcasProviderCode);
        }
Esempio n. 10
0
        public void Test_PublishInstitutionEnrichment_should_argument_exception(string instCode, string email)
        {
            var enrichmentService = new EnrichmentService(Context);

            Assert.Throws <ArgumentException>(() => enrichmentService.PublishProviderEnrichment(instCode, email));
        }