public async Task Initialize_ApprenticeshipWithStandard_PopulatesModelCorrectly() { // Arrange 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 provider = await TestData.CreateProvider( providerName : "Provider 1", apprenticeshipQAStatus : ApprenticeshipQAStatus.Submitted); var providerUser = await TestData.CreateUser(providerId : provider.ProviderId); var adminUser = await TestData.CreateUser(); var standard = await TestData.CreateStandard(standardCode : 1234, version : 1, standardName : "Test Standard"); var apprenticeshipId = (await TestData.CreateApprenticeship(provider.ProviderId, standard, createdBy: providerUser, contactEmail: contactEmail, contactTelephone: contactTelephone, contactWebsite: contactWebsite, marketingInformation: marketingInfo, website: website, locations: new[] { CreateApprenticeshipLocation.CreateRegionalEmployerBased(regions) })).ApprenticeshipId; var standardsAndFrameworksCache = new StandardsCache(CosmosDbQueryDispatcher.Object); var submissionId = await TestData.CreateApprenticeshipQASubmission( provider.ProviderId, submittedOn : Clock.UtcNow, submittedByUserId : providerUser.UserId, providerMarketingInformation : "The overview", apprenticeshipIds : new[] { apprenticeshipId }); await WithSqlQueryDispatcher(async dispatcher => { var initializer = new FlowModelInitializer(CosmosDbQueryDispatcher.Object, dispatcher); // Act var model = await initializer.Initialize(provider.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); }); }
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 provider = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted); var user = await TestData.CreateUser(providerId : provider.ProviderId); var adminUser = await TestData.CreateUser(); var standard = await TestData.CreateStandard(standardCode, standardVersion, standardName : "My standard"); var apprenticeshipId = (await TestData.CreateApprenticeship(provider.ProviderId, standard, createdBy: user, contactEmail: adminUser.Email, contactTelephone: contactTelephone, contactWebsite: contactWebsite, marketingInformation: marketingInfo, locations: new[] { CreateApprenticeshipLocation.CreateRegionalEmployerBased(regions) })).ApprenticeshipId; var venueId = (await TestData.CreateVenue(provider.ProviderId, createdBy: User.ToUserInfo())).VenueId; await User.AsProviderUser(provider.ProviderId, ProviderType.Apprenticeships); var flowModel = new FlowModel(); flowModel.SetProviderDetails("Provider 1 rocks"); flowModel.SetApprenticeshipStandard(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={provider.ProviderId}&ffiid={mptxInstance.InstanceId}", requestContent); // Assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); SqlQuerySpy.VerifyQuery <UpdateApprenticeship, OneOf <NotFound, Success> >(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.SubRegionIds.Contains("E06000001") && l.SubRegionIds.Contains("E10000009"))); }