Exemplo n.º 1
0
        public void GetUrlEncodedStringTest(string input, string expectedOutput)
        {
            //Act
            var result = StringManipulationExtension.GetUrlEncodedString(input);

            //Assert
            result.Should().BeEquivalentTo(expectedOutput);
        }
Exemplo n.º 2
0
        public void ReplaceSpecialCharactersTest(string searchTerm, string expectedSearchTerm)
        {
            //Act
            var result = StringManipulationExtension.ReplaceSpecialCharacters(searchTerm, RegexPattern);

            // Assert
            result.Should().Be(expectedSearchTerm);
        }
        public string BuildRedirectPathAndQueryString(string courseSearchResultsPage, string searchTerm, CourseSearchFilters courseSearchFilters)
        {
            if (courseSearchFilters == null)
            {
                return(courseSearchResultsPage);
            }

            var parameters = new Dictionary <string, string>();

            if (!string.IsNullOrWhiteSpace(searchTerm) || !string.IsNullOrWhiteSpace(courseSearchFilters.Provider))
            {
                if (!string.IsNullOrWhiteSpace(searchTerm))
                {
                    parameters.Add(nameof(searchTerm), StringManipulationExtension.GetUrlEncodedString(searchTerm));
                }

                if (!string.IsNullOrWhiteSpace(courseSearchFilters.Provider))
                {
                    parameters.Add(nameof(courseSearchFilters.Provider), StringManipulationExtension.GetUrlEncodedString(courseSearchFilters.Provider));
                }

                if (courseSearchFilters.Attendance.Any())
                {
                    parameters.Add(nameof(courseSearchFilters.Attendance), string.Join(",", courseSearchFilters.Attendance));
                }

                if (courseSearchFilters.Only1619Courses)
                {
                    parameters.Add(nameof(courseSearchFilters.Only1619Courses), "true");
                }

                if (!string.IsNullOrWhiteSpace(courseSearchFilters.Location))
                {
                    parameters.Add(nameof(CourseSearchFilters.Location), StringManipulationExtension.GetUrlEncodedString(courseSearchFilters.Location));
                }

                if (courseSearchFilters.AttendancePattern.Any())
                {
                    parameters.Add(nameof(CourseSearchFilters.AttendancePattern), string.Join(",", courseSearchFilters.AttendancePattern));
                }

                //parameters.Add(nameof(CourseSearchFilters.StartDate), "anytime");
                if (courseSearchFilters.StudyMode.Any())
                {
                    parameters.Add(nameof(CourseSearchFilters.StudyMode), string.Join(",", courseSearchFilters.StudyMode));
                }
            }

            var queryParameters = string.Join("&", parameters.Select(kvp => $"{kvp.Key}={kvp.Value}"));

            return($"{courseSearchResultsPage}?{queryParameters}");
        }
        public ActionResult Index(string searchTerm, string attendance, string studyMode, string attendancePattern, string location, string sortBy, string startDate, string provider, bool only1619Courses = false, int page = 1)
        {
            var viewModel = new CourseSearchResultsViewModel {
                SearchTerm = searchTerm
            };

            var cleanCourseName =
                StringManipulationExtension.ReplaceSpecialCharacters(searchTerm, InvalidCharactersRegexPattern);

            if (!string.IsNullOrEmpty(cleanCourseName))
            {
                var courseSearchProperties = new CourseSearchProperties
                {
                    Page      = page,
                    Count     = RecordsPerPage,
                    OrderedBy = GetSortBy(sortBy),
                    Filters   = new CourseSearchFilters
                    {
                        Attendance        = attendance?.Split(','),
                        StudyMode         = studyMode?.Split(','),
                        Only1619Courses   = only1619Courses,
                        AttendancePattern = attendancePattern?.Split(','),
                        Location          = StringManipulationExtension.ReplaceSpecialCharacters(location, InvalidCharactersRegexPattern),
                        Provider          =
                            StringManipulationExtension.ReplaceSpecialCharacters(provider, InvalidCharactersRegexPattern),
                        StartDate = startDate
                    }
                };

                var response = asyncHelper.Synchronise(() => courseSearchService.SearchCoursesAsync(cleanCourseName, courseSearchProperties));
                if (response.Courses.Any())
                {
                    foreach (var course in response.Courses)
                    {
                        course.CourseUrl = $"{CourseDetailsPage}?courseid={course.CourseId}";
                        viewModel.Courses.Add(new CourseListingViewModel
                        {
                            Course = course,
                            AdvancedLoanProviderLabel = AdvancedLoanProviderLabel,
                            LocationLabel             = LocationLabel,
                            ProviderLabel             = ProviderLabel,
                            StartDateLabel            = StartDateLabel
                        });
                    }

                    var pathQuery = Request?.Url?.PathAndQuery;
                    if (!string.IsNullOrWhiteSpace(pathQuery) && pathQuery.IndexOf("&page=", StringComparison.InvariantCultureIgnoreCase) > 0)
                    {
                        pathQuery = pathQuery.Substring(0, pathQuery.IndexOf("&page=", StringComparison.InvariantCultureIgnoreCase));
                    }

                    courseSearchViewModelService.SetupPaging(viewModel, response, pathQuery, RecordsPerPage, CourseSearchResultsPage);
                    SetupSearchLinks(searchTerm, viewModel, pathQuery, response.ResultProperties.OrderedBy);
                }

                // SetupFilterDisplayData(attendance, studymode, qualificationLevel, distance, dfe1619Funded, pattern, location, startDate, provider, viewModel);
            }

            viewModel.NoTrainingCoursesFoundText =
                string.IsNullOrWhiteSpace(searchTerm) ? string.Empty : NoTrainingCoursesFoundText;

            SetupWidgetDefaults(viewModel);
            return(View("SearchResults", viewModel));
        }