public async Task AjaxChangedCatchesException()
        {
            // arrange
            var controller  = BuildCourseController(MediaTypeNames.Text.Html);
            var paramValues = new ParamValues
            {
                Town            = "CV1 2WT",
                CourseType      = "Online",
                CourseHours     = "Full time",
                CourseStudyTime = "Daytime",
            };
            var appdata = System.Text.Json.JsonSerializer.Serialize(paramValues);

            A.CallTo(() => FakeFindACoursesService.GetFilteredData(A <CourseSearchFilters> .Ignored, A <CourseSearchOrderBy> .Ignored, A <int> .Ignored)).Throws(new Exception());
            A.CallTo(() => FakeViewHelper.RenderViewAsync(A <CourseController> .Ignored, A <string> .Ignored, A <BodyViewModel> .Ignored, A <bool> .Ignored)).Returns("<p>some markup</p>");

            // act
            var result = await controller.AjaxChanged(appdata).ConfigureAwait(false);

            // assert
            Assert.False(string.IsNullOrWhiteSpace(result.HTML));
            Assert.Equal(0, result.Count);
            Assert.Null(result.IsPostcode);

            controller.Dispose();
        }
        public async Task AjaxChangedReturnAutoLocationSuggestions(string townOrPostcode, string coordinates, bool expectAutoLocationSuggest)
        {
            // arrange
            var controller  = BuildCourseController(MediaTypeNames.Text.Html);
            var paramValues = new ParamValues
            {
                Town        = townOrPostcode,
                Coordinates = coordinates,
            };
            var appdata            = System.Text.Json.JsonSerializer.Serialize(paramValues);
            var returnedCourseData = new CourseSearchResult
            {
                ResultProperties = new CourseSearchResultProperties
                {
                    Page             = 1,
                    TotalResultCount = 1,
                    TotalPages       = 1,
                },
                Courses = new List <Course>
                {
                    new Course {
                        Title = "Maths", CourseId = "1", AttendancePattern = "Online", Description = "This is a test description - over 220 chars" + new string(' ', 220)
                    },
                },
            };

            A.CallTo(() => FakeLocationsService.GetSuggestedLocationsAsync(A <string> .Ignored)).Returns(GetTestSuggestedLocations());
            A.CallTo(() => FakeFindACoursesService.GetFilteredData(A <CourseSearchFilters> .Ignored, A <CourseSearchOrderBy> .Ignored, A <int> .Ignored)).Returns(returnedCourseData);
            A.CallTo(() => FakeViewHelper.RenderViewAsync(A <CourseController> .Ignored, A <string> .Ignored, A <BodyViewModel> .Ignored, A <bool> .Ignored)).Returns("<p>some markup</p>");

            // act
            var result = await controller.AjaxChanged(appdata).ConfigureAwait(false);

            // assert
            if (expectAutoLocationSuggest)
            {
                A.CallTo(() => FakeLocationsService.GetSuggestedLocationsAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly();
                result.AutoSuggestedTown.Should().Be("LN1 (LAN1)");
                result.UsingAutoSuggestedLocation.Should().BeTrue();
                result.DidYouMeanLocations.Count.Should().Be(1);
            }
            else
            {
                A.CallTo(() => FakeLocationsService.GetSuggestedLocationsAsync(A <string> .Ignored)).MustNotHaveHappened();
                result.UsingAutoSuggestedLocation.Should().BeFalse();
            }

            controller.Dispose();
        }
        public async Task AjaxChangedReturnsSuccessWithCorrectStates(string townOrPostcode, string coordinates, bool expectedShowDistance)
        {
            // arrange
            var controller  = BuildCourseController(MediaTypeNames.Text.Html);
            var paramValues = new ParamValues
            {
                Town            = townOrPostcode,
                Coordinates     = coordinates,
                CourseType      = "Online",
                CourseHours     = "Full time",
                CourseStudyTime = "Daytime",
            };
            var appdata            = System.Text.Json.JsonSerializer.Serialize(paramValues);
            var returnedCourseData = new CourseSearchResult
            {
                ResultProperties = new CourseSearchResultProperties
                {
                    Page             = 1,
                    TotalResultCount = 1,
                    TotalPages       = 1,
                },
                Courses = new List <Course>
                {
                    new Course {
                        Title = "Maths", CourseId = "1", AttendancePattern = "Online", Description = "This is a test description - over 220 chars" + new string(' ', 220)
                    },
                },
            };

            A.CallTo(() => FakeFindACoursesService.GetFilteredData(A <CourseSearchFilters> .Ignored, A <CourseSearchOrderBy> .Ignored, A <int> .Ignored)).Returns(returnedCourseData);
            A.CallTo(() => FakeViewHelper.RenderViewAsync(A <CourseController> .Ignored, A <string> .Ignored, A <BodyViewModel> .Ignored, A <bool> .Ignored)).Returns("<p>some markup</p>");

            // act
            var result = await controller.AjaxChanged(appdata).ConfigureAwait(false);

            // assert
            Assert.False(string.IsNullOrWhiteSpace(result.HTML));
            Assert.Equal(returnedCourseData.Courses.ToList().Count, result.Count);
            result.ShowDistanceSelector.Should().Be(expectedShowDistance);

            controller.Dispose();
        }