public async Task Post_ValidRequestNotNationalUpdatesFlowStateAndRedirects(
            ApprenticeshipLocationType locationType)
        {
            // Arrange
            var providerId = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

            await User.AsProviderUser(providerId, ProviderType.Apprenticeships);

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipLocationType(locationType);
            var mptxInstance = CreateMptxInstance(flowModel);

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("National", false)
                                 .ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-employer-locations?providerId={providerId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            var state = GetMptxInstance <FlowModel>(mptxInstance.InstanceId).State;

            Assert.False(state.ApprenticeshipIsNational);

            Assert.Equal(HttpStatusCode.Found, response.StatusCode);
            Assert.Equal(
                "/new-apprenticeship-provider/apprenticeship-employer-locations-regions",
                UrlHelper.StripQueryParams(response.Headers.Location.OriginalString));
        }
        public async Task Post_ValidRequestUpdatesFlowStateAndRedirects(
            ApprenticeshipLocationType locationType,
            string expectedRedirect)
        {
            // Arrange
            var provider = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

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

            var mptxInstance = CreateMptxInstance(new FlowModel());

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("LocationType", locationType.ToString())
                                 .ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-locations?providerId={provider.ProviderId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            var state = GetMptxInstance <FlowModel>(mptxInstance.InstanceId).State;

            Assert.Equal(locationType, state.ApprenticeshipLocationType);

            Assert.Equal(HttpStatusCode.Found, response.StatusCode);
            Assert.StartsWith(expectedRedirect, response.Headers.Location.OriginalString);
        }
        public IActionResult AddNewVenue(ApprenticeshipLocationType type)
        {
            _session.SetString("Option", type == ApprenticeshipLocationType.ClassroomBasedAndEmployerBased ?
                               "AddNewVenueForApprenticeshipsCombined" :"AddNewVenueForApprenticeships");

            return(Json(Url.Action("AddVenue", "Venues")));
        }
        private void SetupReturnOneHundredResultsOfType(ApprenticeshipLocationType locationType)
        {
            _apprenticeshipSearchService.Setup(
                x => x.Search(It.Is <ApprenticeshipSearchParameters>(asp => asp.VacancyLocationType == locationType))).Returns <ApprenticeshipSearchParameters>(asp => new
                                                                                                                                                                SearchResults <ApprenticeshipSearchResponse, ApprenticeshipSearchParameters>(100, new List <ApprenticeshipSearchResponse>
            {
                new ApprenticeshipSearchResponse
                {
                    VacancyLocationType = locationType,
                    //TODO: So many unit tests with so much setup. It's a smell that we're testing a unit and requiring a completely unrelated stub.
                    Wage = new Wage(WageType.Custom, null, null, null, null, WageUnit.Weekly, 0, null)
                }
            }, new List <AggregationResult>(0), asp));

            _apprenticeshipSearchService.Setup(
                x => x.Search(It.Is <ApprenticeshipSearchParameters>(asp => asp.VacancyLocationType != locationType))).Returns <ApprenticeshipSearchParameters>(asp => new
                                                                                                                                                                SearchResults <ApprenticeshipSearchResponse, ApprenticeshipSearchParameters>(0, new List <ApprenticeshipSearchResponse>
            {
                new ApprenticeshipSearchResponse
                {
                    VacancyLocationType = locationType,
                    Wage = new Wage(WageType.Custom, null, null, null, null, WageUnit.Weekly, 0, null)
                }
            }, new List <AggregationResult>(0), asp));
        }
        public void SetApprenticeshipLocationType(ApprenticeshipLocationType apprenticeshipLocationType)
        {
            ApprenticeshipLocationType = apprenticeshipLocationType;

            if (apprenticeshipLocationType == Core.Models.ApprenticeshipLocationType.ClassroomBased)
            {
                ApprenticeshipIsNational = null;
            }
        }
        public async Task Post_ValidRequestUpdatesStateAndRedirects(
            ApprenticeshipLocationType locationType,
            bool gotClassroomLocation,
            string expectedRedirectLocation)
        {
            // Arrange
            var provider = await TestData.CreateProvider(apprenticeshipQAStatus : ApprenticeshipQAStatus.NotStarted);

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

            var flowModel = new FlowModel();

            flowModel.SetApprenticeshipLocationType(locationType);
            flowModel.SetApprenticeshipIsNational(false);
            var mptxInstance = CreateMptxInstance(flowModel);

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

                mptxInstance.Update(s => s.SetClassroomLocationForVenue(
                                        venueId,
                                        originalVenueId: null,
                                        radius: 5,
                                        new[] { ApprenticeshipDeliveryMode.BlockRelease }));
            }

            var subRegion1Id = "E06000001";  // County Durham
            var subRegion2Id = "E06000009";  // Blackpool

            var requestContent = new FormUrlEncodedContentBuilder()
                                 .Add("RegionIds", subRegion1Id)
                                 .Add("RegionIds", subRegion2Id)
                                 .ToContent();

            // Act
            var response = await HttpClient.PostAsync(
                $"new-apprenticeship-provider/apprenticeship-employer-locations-regions?providerId={provider.ProviderId}&ffiid={mptxInstance.InstanceId}",
                requestContent);

            // Assert
            var state = GetMptxInstance <FlowModel>(mptxInstance.InstanceId).State;

            Assert.False(state.ApprenticeshipIsNational);

            Assert.Equal(HttpStatusCode.Found, response.StatusCode);
            Assert.Equal(
                expectedRedirectLocation,
                UrlHelper.StripQueryParams(response.Headers.Location.OriginalString));
        }
Exemplo n.º 7
0
        internal string DeliveryMethodConvert(ApprenticeshipLocationType input)
        {
            switch (input)
            {
            case ApprenticeshipLocationType.ClassroomBased:
                return("Classroom");

            case ApprenticeshipLocationType.ClassroomBasedAndEmployerBased:
                return("Both");

            case ApprenticeshipLocationType.EmployerBased:
                return("Employer");

            default:
                return(string.Empty);
            }
        }
Exemplo n.º 8
0
        private static ApprenticeshipSearchViewModel GetASearchViewModelOfType(ApprenticeshipLocationType locationType)
        {
            var search = new ApprenticeshipSearchViewModel
            {
                Location       = "Test",
                Longitude      = 0d,
                Latitude       = 0d,
                PageNumber     = 1,
                WithinDistance = 2,
                ResultsPerPage = PageSize,
                LocationType   = locationType
            };

            if (locationType == ApprenticeshipLocationType.NonNational)
            {
                search.SortType = VacancySearchSortType.Distance;
            }

            return(search);
        }
Exemplo n.º 9
0
        private void SetupReturnOneHundredResultsOfType(ApprenticeshipLocationType locationType)
        {
            _apprenticeshipSearchService.Setup(
                x => x.Search(It.Is <ApprenticeshipSearchParameters>(asp => asp.VacancyLocationType == locationType))).Returns <ApprenticeshipSearchParameters>(asp => new
                                                                                                                                                                SearchResults <ApprenticeshipSearchResponse, ApprenticeshipSearchParameters>(100, new List <ApprenticeshipSearchResponse>
            {
                new ApprenticeshipSearchResponse
                {
                    VacancyLocationType = locationType
                }
            }, new List <AggregationResult>(0), asp));

            _apprenticeshipSearchService.Setup(
                x => x.Search(It.Is <ApprenticeshipSearchParameters>(asp => asp.VacancyLocationType != locationType))).Returns <ApprenticeshipSearchParameters>(asp => new
                                                                                                                                                                SearchResults <ApprenticeshipSearchResponse, ApprenticeshipSearchParameters>(0, new List <ApprenticeshipSearchResponse>
            {
                new ApprenticeshipSearchResponse
                {
                    VacancyLocationType = locationType
                }
            }, new List <AggregationResult>(0), asp));
        }
        public void FromSearchUrlParseTests(
            ApprenticeshipLevel apprenticeshipLevel,
            string keywords,
            double latitude,
            double longitude,
            string location,
            ApprenticeshipLocationType locationType,
            int pageNumber,
            SearchAction searchAction,
            string searchField,
            ApprenticeshipSearchMode searchMode,
            VacancySearchSortType searchSortType,
            int withinDistance,
            string category,
            string[] subCategories,
            string url)
        {
            var searchViewModel = ApprenticeshipSearchViewModel.FromSearchUrl(url);

            searchViewModel.Should().NotBeNull();
            searchViewModel.ApprenticeshipLevel.Should().Be(apprenticeshipLevel.ToString());
            searchViewModel.Keywords.Should().Be(keywords);
            searchViewModel.Latitude.Should().Be(latitude);
            searchViewModel.Longitude.Should().Be(longitude);
            searchViewModel.Location.Should().Be(location);
            searchViewModel.LocationType.Should().Be(locationType);
            searchViewModel.PageNumber.Should().Be(1);
            searchViewModel.ResultsPerPage.Should().Be(5);
            searchViewModel.SearchAction.Should().Be(searchAction);
            searchViewModel.SearchField.Should().Be(searchField);
            searchViewModel.SearchMode.Should().Be(searchMode);
            searchViewModel.SortType.Should().Be(searchSortType);
            searchViewModel.WithinDistance.Should().Be(withinDistance);
            searchViewModel.Category.Should().Be(category);
            searchViewModel.SubCategories.ShouldAllBeEquivalentTo(subCategories);
        }
 public static string ToDescription(this ApprenticeshipLocationType apprenticeshipLocationType) =>
 apprenticeshipLocationType switch
 {
        private ApprenticeshipLocation CreateDeliveryLocation(DeliveryOption loc, ApprenticeshipLocationType apprenticeshipLocationType)
        {
            List <int> deliveryModes = new List <int>();

            ApprenticeshipLocation apprenticeshipLocation = new ApprenticeshipLocation()
            {
                Name        = loc.LocationName,
                CreatedDate = DateTime.Now,
                CreatedBy   =
                    User.Claims.Where(c => c.Type == "email").Select(c => c.Value).SingleOrDefault(),
                ApprenticeshipLocationType = apprenticeshipLocationType,
                Id           = Guid.NewGuid(),
                LocationType = LocationType.Venue,
                RecordStatus = RecordStatus.Live,
                Regions      = loc.Regions,
                National     = loc.National ?? false,
                UpdatedDate  = DateTime.Now,
                UpdatedBy    =
                    User.Claims.Where(c => c.Type == "email").Select(c => c.Value).SingleOrDefault(),
            };

            if (loc.Venue != null)
            {
                apprenticeshipLocation.TribalId   = loc.Venue.TribalLocationId ?? null;
                apprenticeshipLocation.ProviderId = loc.Venue.ProviderID;
                apprenticeshipLocation.LocationId = loc.Venue.LocationId ?? null;
                apprenticeshipLocation.VenueId    = Guid.Parse(loc.Venue.ID);
                apprenticeshipLocation.Address    = new Address
                {
                    Address1  = loc.Venue.Address1,
                    Address2  = loc.Venue.Address2,
                    Town      = loc.Venue.Town,
                    County    = loc.Venue.County,
                    Postcode  = loc.Venue.PostCode,
                    Email     = loc.Venue.Email,
                    Phone     = loc.Venue.Telephone,
                    Website   = loc.Venue.Website,
                    Latitude  = (double)loc.Venue.Latitude,
                    Longitude = (double)loc.Venue.Longitude
                };
            }
            if (!string.IsNullOrEmpty(loc.LocationId))
            {
                apprenticeshipLocation.LocationGuidId = new Guid(loc.LocationId);
            }

            if (!string.IsNullOrEmpty(loc.Radius))
            {
                apprenticeshipLocation.Radius = Convert.ToInt32(loc.Radius);
            }

            if (!string.IsNullOrEmpty(loc.Delivery))
            {
                var delModes = loc.Delivery.Split(",");

                foreach (var delMode in delModes)
                {
                    if (delMode.ToLower().Trim() ==
                        @WebHelper.GetEnumDescription(ApprenticeShipDeliveryLocation.DayRelease).ToLower())
                    {
                        deliveryModes.Add((int)ApprenticeShipDeliveryLocation.DayRelease);
                    }

                    if (delMode.ToLower().Trim() == @WebHelper
                        .GetEnumDescription(ApprenticeShipDeliveryLocation.BlockRelease).ToLower())
                    {
                        deliveryModes.Add((int)ApprenticeShipDeliveryLocation.BlockRelease);
                    }
                }
            }

            if (apprenticeshipLocationType == ApprenticeshipLocationType.ClassroomBasedAndEmployerBased || apprenticeshipLocationType == ApprenticeshipLocationType.EmployerBased)
            {
                deliveryModes.Add((int)ApprenticeShipDeliveryLocation.EmployerAddress);
            }

            apprenticeshipLocation.DeliveryModes = deliveryModes;

            return(apprenticeshipLocation);
        }
Exemplo n.º 13
0
 private string DeliveryMethodConvert(ApprenticeshipLocationType input) => input switch
 {