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}"));
        }
        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_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);
            });
        }