public async Task Initialize_ApprenticeshipWithFramework_PopulatesModelSuccessfully() { // Arrange var ukprn = 12346; var adminUserId = $"admin-user"; var contactTelephone = "1111 111 1111"; var website = "https://somerandomprovider.com/apprenticeship"; var contactWebsite = "https://somerandomprovider.com"; var marketingInfo = "Providing Online training"; var regions = new List <string> { "123" }; var contactEmail = "*****@*****.**"; var providerId = await TestData.CreateProvider( ukprn : ukprn, providerName : "Provider 1", apprenticeshipQAStatus : ApprenticeshipQAStatus.Submitted); var providerUserId = $"{ukprn}-user"; var user = await TestData.CreateUser(providerUserId, "*****@*****.**", "Provider 1", "Person", providerId); var adminUser = await TestData.CreateUser(adminUserId, "*****@*****.**", "admin", "admin", null); var framework = await TestData.CreateFramework(1, 1, 1, "Test Framework"); var apprenticeshipId = await TestData.CreateApprenticeship(providerId, framework, createdBy : user, contactEmail : contactEmail, contactTelephone : contactTelephone, contactWebsite : contactWebsite, marketingInformation : marketingInfo, website : website, locations : new[] { CreateApprenticeshipLocation.CreateRegions(regions) }); var standardsAndFrameworksCache = new StandardsAndFrameworksCache(CosmosDbQueryDispatcher.Object); var submissionId = await TestData.CreateApprenticeshipQASubmission( providerId, submittedOn : Clock.UtcNow, submittedByUserId : providerUserId, providerMarketingInformation : "The overview", apprenticeshipIds : new[] { apprenticeshipId }); await WithSqlQueryDispatcher(async dispatcher => { var initializer = new FlowModelInitializer(CosmosDbQueryDispatcher.Object, dispatcher, standardsAndFrameworksCache); // Act var model = await initializer.Initialize(providerId); // Assert Assert.True(model.GotApprenticeshipDetails); Assert.Equal(contactEmail, model.ApprenticeshipContactEmail); Assert.Equal(contactTelephone, model.ApprenticeshipContactTelephone); Assert.Equal(contactWebsite, model.ApprenticeshipContactWebsite); Assert.Equal(apprenticeshipId, model.ApprenticeshipId); Assert.False(model.ApprenticeshipIsNational); Assert.Equal(ApprenticeshipLocationType.EmployerBased, model.ApprenticeshipLocationType); Assert.Equal(marketingInfo, model.ApprenticeshipMarketingInformation); Assert.Null(model.ApprenticeshipClassroomLocations); Assert.Collection(model.ApprenticeshipLocationSubRegionIds, item1 => { Assert.Equal(item1, regions.First()); }); Assert.Equal(website, model.ApprenticeshipWebsite); Assert.True(model.ApprenticeshipStandardOrFramework.IsFramework); Assert.False(model.ApprenticeshipStandardOrFramework.IsStandard); }); }
public async Task PostConfirmation_ValidRequestWithExistingApprenticeshipRegionsAndVenue_UpdatesApprenticeship() { // Arrange var ukprn = 12347; var providerUserId = $"{ukprn}-user"; var adminUserId = $"admin-user"; var contactTelephone = "1111 111 1111"; var contactWebsite = "https://somerandomprovider.com"; var marketingInfo = "Providing Online training"; var regions = new List <string> { "123" }; var standardCode = 123; var standardVersion = 1; var providerId = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted); var user = await TestData.CreateUser(providerUserId, "*****@*****.**", "Provider 1", "Person", providerId); var adminUser = await TestData.CreateUser(adminUserId, "*****@*****.**", "admin", "admin", null); var standard = await TestData.CreateStandard(standardCode, standardVersion, standardName : "My standard"); var apprenticeshipId = await TestData.CreateApprenticeship(providerId, standard, createdBy : user, contactEmail : adminUser.Email, contactTelephone : contactTelephone, contactWebsite : contactWebsite, marketingInformation : marketingInfo, locations : new[] { CreateApprenticeshipLocation.CreateRegions(regions) }); var venueId = await TestData.CreateVenue(providerId); await User.AsProviderUser(providerId, ProviderType.Apprenticeships); var flowModel = new FlowModel(); flowModel.SetProviderDetails("Provider 1 rocks"); flowModel.SetApprenticeshipStandardOrFramework(standard); flowModel.SetApprenticeshipDetails( marketingInformation: "My apprenticeship", website: "http://provider.com/apprenticeship", contactTelephone: "01234 5678902", contactEmail: "*****@*****.**", contactWebsite: "http://provider.com"); flowModel.SetApprenticeshipLocationType(ApprenticeshipLocationType.ClassroomBasedAndEmployerBased); flowModel.SetApprenticeshipLocationRegionIds(new[] { "E06000001", // County Durham "E10000009" // Dorset }); flowModel.SetApprenticeshipId(apprenticeshipId); flowModel.SetClassroomLocationForVenue( venueId, originalVenueId: null, radius: 5, deliveryModes: new[] { ApprenticeshipDeliveryMode.BlockRelease }); var mptxInstance = CreateMptxInstance(flowModel); var requestContent = new FormUrlEncodedContentBuilder().ToContent(); // Act var response = await HttpClient.PostAsync( $"new-apprenticeship-provider/apprenticeship-confirmation?providerId={providerId}&ffiid={mptxInstance.InstanceId}", requestContent); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); CosmosDbQueryDispatcher.Verify(mock => mock.ExecuteQuery(It.Is <UpdateApprenticeship>(q => q.ApprenticeshipLocations.Any(l => l.ApprenticeshipLocationType == ApprenticeshipLocationType.ClassroomBased && l.DeliveryModes.Single() == ApprenticeshipDeliveryMode.BlockRelease && l.Radius == 5 && l.VenueId == venueId) && q.ApprenticeshipLocations.Any(l => l.ApprenticeshipLocationType == ApprenticeshipLocationType.EmployerBased && l.DeliveryModes.Single() == ApprenticeshipDeliveryMode.EmployerAddress && l.National == false && l.VenueId == null && l.Regions.Contains("E06000001") && l.Regions.Contains("E10000009"))))); }