Exemple #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));
        }
        private async Task <ActionResult> SaveValidatedOrgansation(ProviderEnrichmentModel enrichmentModel, string providerCode)
        {
            var postModel = new UcasProviderEnrichmentPostModel {
                EnrichmentModel = enrichmentModel
            };

            await _manageApi.SaveProviderEnrichment(providerCode, postModel);

            TempData["MessageType"]     = "success";
            TempData["MessageTitle"]    = "Your changes have been saved";
            TempData["MessageBodyHtml"] = "<p class=\"govuk-body\">Preview any course to see how it will look to applicants.</p>";
            return(RedirectToAction("Details", "Organisation", new { providerCode = providerCode }));
        }
        public async Task EnrichmentSaveTest()
        {
            SetupSmokeTestData();
            var apiClient = await BuildSigninAwareClient();

            const string ucasProviderCode = "ABC";
            var          model            = new UcasProviderEnrichmentPostModel();

            model.EnrichmentModel = new ProviderEnrichmentModel
            {
                TrainWithUs         = "wqeqwe",
                TrainWithDisability = "werwer"
            };
            await apiClient.Enrichment_SaveProviderAsync(ucasProviderCode, model);
        }
        public async Task EnrichmentPublishTest()
        {
            SetupSmokeTestData();
            var apiClient = await BuildSigninAwareClient();

            const string ucasProviderCode = "ABC";
            var          model            = new UcasProviderEnrichmentPostModel();

            model.EnrichmentModel = new ProviderEnrichmentModel
            {
                TrainWithUs         = "wqeqwe",
                TrainWithDisability = "werwer"
            };
            await apiClient.Enrichment_SaveProviderAsync(ucasProviderCode, model);

            var result = await apiClient.Publish_PublishCoursesToSearchAndCompareAsync(ucasProviderCode);

            result.Should().BeTrue();
        }
        public async Task AboutPost_SetAccreditingProviderToEmpty()
        {
            var existingEnrichment = new UcasProviderEnrichmentGetModel()
            {
                EnrichmentModel = new ProviderEnrichmentModel()
                {
                    AccreditingProviderEnrichments = new List <AccreditingProviderEnrichment>
                    {
                        new AccreditingProviderEnrichment
                        {
                            UcasProviderCode = "ACC",
                            Description      = "foo"
                        }
                    }
                }
            };

            var apiMock = new Mock <IManageApi>();

            apiMock.Setup(x => x.GetProviderEnrichment("ABC")).ReturnsAsync(existingEnrichment);

            UcasProviderEnrichmentPostModel result = null;

            apiMock.Setup(x => x.SaveProviderEnrichment("ABC", It.IsAny <UcasProviderEnrichmentPostModel>()))
            .Callback((string a, UcasProviderEnrichmentPostModel b) => result = b)
            .Returns(Task.CompletedTask);

            apiMock.Setup(x => x.GetCoursesOfProvider("ABC")).ReturnsAsync(new List <Course> {
                new Course {
                    AccreditingProvider = new GovUk.Education.ManageCourses.Domain.Models.Provider {
                        ProviderCode = "ACC"
                    }
                }
            });

            var objectValidator = new Mock <IObjectModelValidator>();

            objectValidator.Setup(o => o.Validate(It.IsAny <ActionContext>(),
                                                  It.IsAny <ValidationStateDictionary>(),
                                                  It.IsAny <string>(),
                                                  It.IsAny <Object>()));

            var frontendUrlMock = new Mock <IFrontendUrlService>();

            var controller = new OrganisationController(apiMock.Object, frontendUrlMock.Object);

            controller.ObjectValidator = objectValidator.Object;
            controller.TempData        = new Mock <ITempDataDictionary>().Object;

            var res = await controller.AboutPost("ABC", new OrganisationViewModelForAbout {
                AboutTrainingProviders = new List <TrainingProviderViewModel>
                {
                    new TrainingProviderViewModel
                    {
                        ProviderCode = "ACC",
                        Description  = null // not an empty string... this is how MVC model binding behaves
                    }
                }
            });


            result.Should().NotBeNull();
            result.EnrichmentModel.AccreditingProviderEnrichments[0].UcasProviderCode.Should().Be("ACC");
            result.EnrichmentModel.AccreditingProviderEnrichments[0].Description.Should().BeNullOrEmpty();
        }
Exemple #6
0
        /// <summary>
        /// This is an upsert.
        /// If a draft record exists then update it.
        /// If a draft record does not exist then add a new one.
        /// If a new draft record is created then:
        ///check for the existence of a previous published record and get the last pulished date
        /// </summary>
        /// <param name="model">holds the enriched data</param>
        /// <param name="providerCode">the provider code for the enrichment data</param>
        /// <param name="email">the email of the user</param>
        public void SaveProviderEnrichment(UcasProviderEnrichmentPostModel model, string providerCode, string email)
        {
            var userProvider = ValidateUserOrg(email, providerCode);

            providerCode = providerCode.ToUpperInvariant();
            var provider = _context.Providers
                           .Include(p => p.ProviderEnrichments)
                           .SingleOrDefault(p => p.ProviderCode == providerCode &&
                                            p.RecruitmentCycle.Year == RecruitmentCycle.CurrentYear);

            if (provider == null)
            {
                throw new Exception($"Provider {RecruitmentCycle.CurrentYear}/{providerCode} not found");
            }

            var enrichmentDraftRecord = provider.ProviderEnrichments
                                        .Where(ie => ie.Status == EnumStatus.Draft)
                                        .OrderByDescending(x => x.Id)
                                        .FirstOrDefault();

            // when saving enforce the region code is being saved.
            if (!model.EnrichmentModel.RegionCode.HasValue)
            {
                model.EnrichmentModel.RegionCode = provider.RegionCode;
            }

            string content = _converter.ConvertToJson(model);

            if (enrichmentDraftRecord != null)
            {
                //update
                enrichmentDraftRecord.UpdatedAt     = DateTime.UtcNow;
                enrichmentDraftRecord.UpdatedByUser = userProvider.User;
                enrichmentDraftRecord.JsonData      = content;
            }
            else
            {
                //insert
                var enrichmentPublishRecord = provider.ProviderEnrichments
                                              .Where(ie => ie.Status == EnumStatus.Published)
                                              .OrderByDescending(x => x.Id)
                                              .FirstOrDefault();

                DateTime?lastPublishedDate = null;
                if (enrichmentPublishRecord != null)
                {
                    lastPublishedDate = enrichmentPublishRecord.LastPublishedAt;
                }
                var enrichment = new ProviderEnrichment
                {
                    ProviderCode    = userProvider.UcasProviderCode,
                    CreatedAt       = DateTime.UtcNow,
                    UpdatedAt       = DateTime.UtcNow,
                    LastPublishedAt = lastPublishedDate,
                    CreatedByUser   = userProvider.User,
                    UpdatedByUser   = userProvider.User,
                    Status          = EnumStatus.Draft,
                    JsonData        = content,
                };
                provider.ProviderEnrichments.Add(enrichment);
            }
            _context.Save();
        }
 public ActionResult SaveProvider(string providerCode, [FromBody] UcasProviderEnrichmentPostModel model)
 {
     return(HandleVoid(() => _service.SaveProviderEnrichment(model, providerCode, User.Identity.Name)));
 }
 public async Task Enrichment_SaveProviderAsync(string ucasProviderCode, UcasProviderEnrichmentPostModel model)
 {
     await PostObjects($"enrichment/provider/{ucasProviderCode}", model);
 }
Exemple #9
0
 public async Task SaveProviderEnrichment(string providerCode, UcasProviderEnrichmentPostModel organisation)
 {
     await _apiClient.Enrichment_SaveProviderAsync(providerCode, organisation);
 }
Exemple #10
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);
        }
Exemple #11
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);
        }
 public string ConvertToJson(UcasProviderEnrichmentPostModel model)
 {
     return(JsonConvert.SerializeObject(model.EnrichmentModel, _jsonSerializerSettings));
 }