public async Task DeleteVenue_Get_WithExistingApprenticeship_RendersExpectedOutputWithDeleteDisabled()
        {
            // Arrange
            var provider = await TestData.CreateProvider(providerType : ProviderType.Apprenticeships);

            await User.AsTestUser(TestUserType.ProviderUser, provider.ProviderId);

            var venue = await TestData.CreateVenue(provider.ProviderId);

            var standard = await TestData.CreateStandard(standardCode : 1234, version : 1, standardName : "Test Standard");

            var apprenticeship = await TestData.CreateApprenticeship(
                provider.ProviderId,
                standard,
                User.ToUserInfo(),
                ApprenticeshipStatus.Live,
                locations : new[] { CreateApprenticeshipLocation.CreateFromVenue(venue, 30, new[] { ApprenticeshipDeliveryMode.DayRelease }) });

            var request = new HttpRequestMessage(HttpMethod.Get, $"/venues/{venue.Id}/delete");

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(StatusCodes.Status200OK);

            var doc = await response.GetDocument();

            Assert.Null(doc.GetElementByTestId("delete-location-button"));
            Assert.NotNull(doc.GetElementByTestId($"affected-apprenticeship-{apprenticeship.Id}"));
        }
示例#2
0
        public async Task <Apprenticeship> CreateApprenticeship(
            Guid providerId,
            StandardOrFramework standardOrFramework,
            UserInfo createdBy,
            ApprenticeshipStatus status = ApprenticeshipStatus.Live,
            string marketingInformation = "Marketing info",
            string website          = "http://provider.com/apprenticeship",
            string contactTelephone = "01234 567890",
            string contactEmail     = "*****@*****.**",
            string contactWebsite   = "http://provider.com",
            DateTime?createdUtc     = null,
            IEnumerable <CreateApprenticeshipLocation> locations = null)
        {
            var provider = await _cosmosDbQueryDispatcher.ExecuteQuery(new GetProviderById()
            {
                ProviderId = providerId
            });

            if (provider == null)
            {
                throw new ArgumentException("Provider does not exist.", nameof(providerId));
            }

            var apprenticeshipId = Guid.NewGuid();

            await _cosmosDbQueryDispatcher.ExecuteQuery(new CreateApprenticeship()
            {
                Id                  = apprenticeshipId,
                ProviderId          = providerId,
                ProviderUkprn       = provider.Ukprn,
                Status              = (int)status,
                ApprenticeshipTitle = standardOrFramework.StandardOrFrameworkTitle,
                ApprenticeshipType  = standardOrFramework.IsStandard ?
                                      ApprenticeshipType.StandardCode :
                                      ApprenticeshipType.FrameworkCode,
                StandardOrFramework  = standardOrFramework,
                MarketingInformation = marketingInformation,
                Url = website,
                ContactTelephone        = contactTelephone,
                ContactEmail            = contactEmail,
                ContactWebsite          = contactWebsite,
                ApprenticeshipLocations = locations ?? new List <CreateApprenticeshipLocation> {
                    CreateApprenticeshipLocation.CreateNational()
                },
                CreatedDate   = createdUtc ?? _clock.UtcNow,
                CreatedByUser = createdBy
            });

            var createdApprenticeships = await _cosmosDbQueryDispatcher.ExecuteQuery(
                new GetApprenticeshipsByIds()
            {
                ApprenticeshipIds = new[] { apprenticeshipId }
            });

            var apprenticeship = createdApprenticeships[apprenticeshipId];

            await _sqlDataSync.SyncApprenticeship(apprenticeship);

            return(apprenticeship);
        }
示例#3
0
        public Task <Apprenticeship> CreateApprenticeship(
            Guid providerId,
            Standard standard,
            UserInfo createdBy,
            ApprenticeshipStatus status = ApprenticeshipStatus.Live,
            string marketingInformation = "Marketing info",
            string website          = "http://provider.com/apprenticeship",
            string contactTelephone = "01234 567890",
            string contactEmail     = "*****@*****.**",
            string contactWebsite   = "http://provider.com",
            DateTime?createdOn      = null,
            IEnumerable <CreateApprenticeshipLocation> locations = null)
        {
            locations ??= new[]
            {
                CreateApprenticeshipLocation.CreateNationalEmployerBased()
            };

            return(WithSqlQueryDispatcher(async dispatcher =>
            {
                var apprenticeshipId = Guid.NewGuid();

                await dispatcher.ExecuteQuery(new CreateApprenticeship()
                {
                    ApprenticeshipId = apprenticeshipId,
                    ProviderId = providerId,
                    Status = status,
                    Standard = standard,
                    MarketingInformation = marketingInformation,
                    ApprenticeshipWebsite = website,
                    ContactEmail = contactEmail,
                    ContactTelephone = contactTelephone,
                    ContactWebsite = contactWebsite,
                    ApprenticeshipLocations = locations,
                    CreatedBy = createdBy,
                    CreatedOn = createdOn ?? _clock.UtcNow
                });

                return await dispatcher.ExecuteQuery(new GetApprenticeship()
                {
                    ApprenticeshipId = apprenticeshipId
                });
            }));
        }
        public async Task DeleteVenue_Post_WithExistingApprenticeship_RendersExpectedOutputWithErrorMessageAndDeleteDisabled()
        {
            // Arrange
            var provider = await TestData.CreateProvider(
                providerType : ProviderType.Apprenticeships);

            await User.AsTestUser(TestUserType.ProviderUser, provider.ProviderId);

            var venue = await TestData.CreateVenue(provider.ProviderId);

            var standard = await TestData.CreateStandard(standardCode : 1234, version : 1, standardName : "Test Standard");

            var apprenticeship = await TestData.CreateApprenticeship(
                provider.ProviderId,
                standard,
                User.ToUserInfo(),
                ApprenticeshipStatus.Live,
                locations : new[] { CreateApprenticeshipLocation.CreateFromVenue(venue, 30, new[] { ApprenticeshipDeliveryMode.DayRelease }) });

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add(nameof(Command.Confirm), true)
                                 .Add(nameof(Command.ProviderId), provider.ProviderId)
                                 .ToContent();

            var request = new HttpRequestMessage(HttpMethod.Post, $"/venues/{venue.Id}/delete")
            {
                Content = requestContent
            };

            // Act
            var response = await HttpClient.SendAsync(request);

            // Assert
            response.StatusCode.Should().Be(StatusCodes.Status400BadRequest);

            var doc = await response.GetDocument();

            Assert.Null(doc.GetElementByTestId("delete-location-button"));
            Assert.NotNull(doc.GetElementByTestId($"affected-apprenticeship-{apprenticeship.Id}"));
            doc.GetElementByTestId("affected-apprenticeships-error-message").TextContent.Should().Be("The affected apprenticeships have changed");
        }
        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 Initialize_BothLocationType_InitializesModelCorrectly()
        {
            // 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 radius       = 30;
            var deliveryMode = ApprenticeshipDeliveryMode.BlockRelease;
            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 venueId = await TestData.CreateVenue(providerId);

            var venue = await CosmosDbQueryDispatcher.Object.ExecuteQuery(new GetVenueById()
            {
                VenueId = venueId
            });

            var apprenticeshipId = await TestData.CreateApprenticeship(providerId,
                                                                       framework,
                                                                       createdBy : user,
                                                                       contactEmail : contactEmail,
                                                                       contactTelephone : contactTelephone,
                                                                       contactWebsite : contactWebsite,
                                                                       marketingInformation : marketingInfo,
                                                                       website : website,
                                                                       locations : new[]
            {
                CreateApprenticeshipLocation.CreateNational(),
                CreateApprenticeshipLocation.CreateFromVenue(
                    venue,
                    radius,
                    new[] { deliveryMode })
            });

            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.True(model.ApprenticeshipIsNational);
                Assert.Equal(ApprenticeshipLocationType.ClassroomBasedAndEmployerBased, model.ApprenticeshipLocationType);
                Assert.Equal(marketingInfo, model.ApprenticeshipMarketingInformation);
                Assert.Collection(
                    model.ApprenticeshipClassroomLocations.Values,
                    location =>
                {
                    Assert.Equal(venueId, location.VenueId);
                    Assert.Equal(radius, location.Radius);
                    Assert.Contains(deliveryMode, location.DeliveryModes);
                });
                Assert.Equal(website, model.ApprenticeshipWebsite);
                Assert.True(model.ApprenticeshipStandardOrFramework.IsFramework);
                Assert.False(model.ApprenticeshipStandardOrFramework.IsStandard);
            });
        }
示例#7
0
        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")))));
        }
        public async Task Initialize_NationalApprenticeship_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.CreateNationalEmployerBased()
            })).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.True(model.ApprenticeshipIsNational);
                Assert.Equal(ApprenticeshipLocationType.EmployerBased, model.ApprenticeshipLocationType);
                Assert.Equal(marketingInfo, model.ApprenticeshipMarketingInformation);
                Assert.Null(model.ApprenticeshipClassroomLocations);
                Assert.Equal(website, model.ApprenticeshipWebsite);
            });
        }