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

            var parentMptxInstance = MptxManager.CreateInstance(new ParentFlow());
            var childMptxInstance  = MptxManager.CreateInstance <FlowModel, IFlowModelCallback>(
                parentMptxInstance.InstanceId,
                FlowModel.Add(provider.ProviderId, cancelable: true),
                new Dictionary <string, object>()
            {
                { "ReturnUrl", "callback" }
            });

            await User.AsProviderUser(provider.ProviderId, ProviderType.Apprenticeships);

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("Radius", 15)
                                 .Add("DeliveryModes", ApprenticeshipDeliveryMode.DayRelease)
                                 .Add("DeliveryModes", ApprenticeshipDeliveryMode.BlockRelease)
                                 .ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"/apprenticeships/classroom-location?ffiid={childMptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);

            var doc = await response.GetDocument();

            doc.AssertHasError("VenueId", "Select the location");
        }
        public async Task PostRemove_ModeNotEdit_ReturnsBadRequest()
        {
            // Arrange
            var provider = await TestData.CreateProvider(providerType : ProviderType.Apprenticeships);

            var parentMptxInstance = MptxManager.CreateInstance(new ParentFlow());
            var childMptxInstance  = MptxManager.CreateInstance <FlowModel, IFlowModelCallback>(
                parentMptxInstance.InstanceId,
                FlowModel.Add(provider.ProviderId, cancelable: true),
                new Dictionary <string, object>()
            {
                { "ReturnUrl", "callback" }
            });

            await User.AsProviderUser(provider.ProviderId, ProviderType.Apprenticeships);

            var requestContent = new FormUrlEncodedContentBuilder().ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"apprenticeships/remove-classroom-location?ffiid={childMptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public async Task Get_ValidRequest_RendersExpectedOutput()
        {
            // Arrange
            var provider = await TestData.CreateProvider(providerType : ProviderType.Apprenticeships);

            await TestData.CreateVenue(provider.ProviderId, venueName : "Venue 1");

            await TestData.CreateVenue(provider.ProviderId, venueName : "Venue 2");

            var parentMptxInstance = MptxManager.CreateInstance(new ParentFlow());
            var childMptxInstance  = MptxManager.CreateInstance <FlowModel, IFlowModelCallback>(
                parentMptxInstance.InstanceId,
                FlowModel.Add(provider.ProviderId, cancelable: true),
                new Dictionary <string, object>()
            {
                { "ReturnUrl", "callback" }
            });

            await User.AsProviderUser(provider.ProviderId, ProviderType.Apprenticeships);

            // Act
            var response = await HttpClient.GetAsync(
                $"/apprenticeships/classroom-location?ffiid={childMptxInstance.InstanceId}");

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);

            var doc = await response.GetDocument();

            var venues = doc.GetElementById("VenueId").GetElementsByTagName("option");

            Assert.Equal(3, venues.Length);
            Assert.Equal("Venue 1", venues[1].TextContent.Trim());
            Assert.Equal("Venue 2", venues[2].TextContent.Trim());
        }
        public async Task Post_ValidRequest_UpdatesParentStateAndRedirects()
        {
            // Arrange
            var provider = await TestData.CreateProvider(providerType : ProviderType.Apprenticeships);

            var venueId = (await TestData.CreateVenue(provider.ProviderId)).Id;

            var parentMptxInstance = MptxManager.CreateInstance(new ParentFlow());
            var childMptxInstance  = MptxManager.CreateInstance <FlowModel, IFlowModelCallback>(
                parentMptxInstance.InstanceId,
                FlowModel.Add(provider.ProviderId, cancelable: true),
                new Dictionary <string, object>()
            {
                { "ReturnUrl", "callback" }
            });

            await User.AsProviderUser(provider.ProviderId, ProviderType.Apprenticeships);

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("VenueId", venueId)
                                 .Add("Radius", 15)
                                 .Add("DeliveryModes", ApprenticeshipDeliveryMode.DayRelease)
                                 .Add("DeliveryModes", ApprenticeshipDeliveryMode.BlockRelease)
                                 .ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"/apprenticeships/classroom-location?ffiid={childMptxInstance.InstanceId}",
                requestContent);

            // Assert
            Assert.Equal(HttpStatusCode.Found, response.StatusCode);
            Assert.Equal("callback", response.Headers.Location.OriginalString);

            Assert.Equal(venueId, parentMptxInstance.State.VenueId);
            Assert.Equal(15, parentMptxInstance.State.Radius);
            Assert.Contains(ApprenticeshipDeliveryMode.BlockRelease, parentMptxInstance.State.DeliveryModes);
            Assert.Contains(ApprenticeshipDeliveryMode.DayRelease, parentMptxInstance.State.DeliveryModes);
        }