public void WhenEducationLevelNumberIsNull_ShouldReturnLevelName(ApprenticeshipLevel level, string expectedDescription)
        {
            string result =
                EducationLevelNumberHelper.GetEducationLevelNameOrDefault(null, level);

            result.Should().Be(expectedDescription);
        }
        public void ShouldRequireApprenticeshipLevel(ApprenticeshipLevel apprenticeshipLevel, TrainingType trainingType, bool expectValid)
        {
            // Arrange.
            var viewModel = new TrainingDetailsViewModel
            {
                TrainingType        = trainingType,
                ApprenticeshipLevel = apprenticeshipLevel
            };
            var vacancyViewModel = new VacancyViewModelBuilder().With(viewModel).With(_furtherDetailsViewModel).Build();

            // Act.
            _validator.Validate(viewModel);
            _aggregateValidator.Validate(vacancyViewModel);
            _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSets.Errors);
            _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSets.Warnings);
            _aggregateValidator.Validate(vacancyViewModel, ruleSet: RuleSets.ErrorsAndWarnings);

            // Assert.
            if (expectValid)
            {
                _validator.ShouldNotHaveValidationErrorFor(m => m.ApprenticeshipLevel, viewModel);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel, RuleSets.Errors);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel, RuleSets.Warnings);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel, RuleSets.ErrorsAndWarnings);
            }
            else
            {
                _validator.ShouldHaveValidationErrorFor(m => m.ApprenticeshipLevel, viewModel);
                _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel);
                _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel, RuleSets.Errors);
                _aggregateValidator.ShouldNotHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel, RuleSets.Warnings);
                _aggregateValidator.ShouldHaveValidationErrorFor(vm => vm.TrainingDetailsViewModel, vm => vm.TrainingDetailsViewModel.ApprenticeshipLevel, vacancyViewModel, RuleSets.ErrorsAndWarnings);
            }
        }
        public void RemapFromInt_ShouldReturnCorrectEnum_WhenPassedAnIntWithCorrespondingValue()
        {
            var enumValues = Enum.GetValues(typeof(ApprenticeshipLevel))
                             .OfType <ApprenticeshipLevel>();

            foreach (ApprenticeshipLevel enumValue in enumValues)
            {
                ApprenticeshipLevel result = ApprenticeshipLevelHelper.RemapFromInt((int)enumValue);
                result.Should().Be(enumValue);
            }
        }
        public static bool TryRemapFromInt(int value, out ApprenticeshipLevel result)
        {
            switch (value)
            {
            case 5:     // Foundation Degree
                value = (int)ApprenticeshipLevel.Higher;
                break;

            case 7:     // Masters
                value = (int)ApprenticeshipLevel.Degree;
                break;
            }
            if (Enum.IsDefined(typeof(ApprenticeshipLevel), value))
            {
                result = (ApprenticeshipLevel)value;
                return(true);
            }
            result = ApprenticeshipLevel.Unknown;
            return(false);
        }
        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 GetEducationLevelNameOrDefault(int?educationLevelNumber, ApprenticeshipLevel level)
 => GetEducationLevelName(educationLevelNumber) ?? $"Level {(int)level} ({level})";
        public void RemapFromInt_ShouldReturnDegree_WhenConvertingFromMasters7()
        {
            ApprenticeshipLevel result = ApprenticeshipLevelHelper.RemapFromInt(7);

            result.Should().Be(ApprenticeshipLevel.Degree);
        }
        public void RemapFromInt_ShouldReturnHigher_WhenConvertingFromFoundation5()
        {
            ApprenticeshipLevel result = ApprenticeshipLevelHelper.RemapFromInt(5);

            result.Should().Be(ApprenticeshipLevel.Higher);
        }
        public void ShouldCreateApprenticeshipLevelIfTrainingTypeStandard(int standardId, ApprenticeshipLevel expectedApprenticeshipLevel)
        {
            // Arrange.
            var trainingDetailsViewModel = new TrainingDetailsViewModel
            {
                VacancyReferenceNumber = VacancyReferenceNumber,
                ApprenticeshipLevel    = expectedApprenticeshipLevel,
                TrainingType           = TrainingType.Standards,
                StandardId             = standardId
            };

            MockVacancyPostingService.Setup(s => s.UpdateVacancy(It.IsAny <Vacancy>())).Returns <Vacancy>(v => v);
            MockMapper.Setup(m => m.Map <Vacancy, TrainingDetailsViewModel>(It.IsAny <Vacancy>()))
            .Returns((Vacancy av) => new TrainingDetailsViewModel()
            {
                ApprenticeshipLevel = av.ApprenticeshipLevel
            });

            var provider = GetVacancyPostingProvider();

            // Act.
            var viewModel = provider.UpdateVacancy(trainingDetailsViewModel);

            // Assert.
            viewModel.ApprenticeshipLevel.Should().Be(expectedApprenticeshipLevel);
        }