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, createdBy : User.ToUserInfo());

            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.CreateClassroomBased(new[] { ApprenticeshipDeliveryMode.DayRelease }, 30, venue.VenueId) });

            var request = new HttpRequestMessage(HttpMethod.Get, $"/venues/{venue.VenueId}/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.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, createdBy : User.ToUserInfo());

            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.CreateClassroomBased(new[] { ApprenticeshipDeliveryMode.DayRelease }, 30, venue.VenueId) });

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

            var request = new HttpRequestMessage(HttpMethod.Post, $"/venues/{venue.VenueId}/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.ApprenticeshipId}"));
            doc.GetElementByTestId("affected-apprenticeships-error-message").TextContent.Should().Be("The affected apprenticeships have changed");
        }
        public async Task Initialize_BothLocationType_InitializesModelCorrectly()
        {
            // 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 radius       = 30;
            var deliveryMode = ApprenticeshipDeliveryMode.BlockRelease;
            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 venueId = (await TestData.CreateVenue(provider.ProviderId, createdBy: providerUser)).VenueId;

            var venue = await WithSqlQueryDispatcher(sqlDispatcher => sqlDispatcher.ExecuteQuery(new GetVenue()
            {
                VenueId = venueId
            }));

            var apprenticeshipId = (await TestData.CreateApprenticeship(provider.ProviderId,
                                                                        standard,
                                                                        createdBy: providerUser,
                                                                        contactEmail: contactEmail,
                                                                        contactTelephone: contactTelephone,
                                                                        contactWebsite: contactWebsite,
                                                                        marketingInformation: marketingInfo,
                                                                        website: website,
                                                                        locations: new[]
            {
                CreateApprenticeshipLocation.CreateNationalEmployerBased(),
                CreateApprenticeshipLocation.CreateClassroomBased(
                    new[] { deliveryMode },
                    radius,
                    venue.VenueId)
            })).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.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);
            });
        }