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); }