public async Task Then_If_Course_Is_After_Last_Start_Then_Redirected_To_Course_Page(
            int providerId,
            int courseId,
            GetCourseProvidersRequest providersRequest,
            GetCourseProviderResult response,
            [Frozen] Mock <IMediator> mediator,
            [Frozen] Mock <ICookieStorageService <GetCourseProvidersRequest> > cookieStorageService,
            [Greedy] CoursesController controller)
        {
            //Arrange
            response.Course.StandardDates.LastDateStarts = DateTime.UtcNow.AddDays(-1);
            cookieStorageService
            .Setup(x => x.Get(Constants.ProvidersCookieName))
            .Returns(providersRequest);
            mediator
            .Setup(x => x.Send(
                       It.IsAny <GetCourseProviderQuery>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            //Act
            var actual = await controller.CourseProviderDetail(courseId, providerId, "", "", "") as RedirectToRouteResult;

            //Assert
            Assert.IsNotNull(actual);
            actual.RouteName.Should().Be(RouteNames.CourseDetails);
        }
Ejemplo n.º 2
0
        public void GivenIHaveAProviderFiltersCookie()
        {
            var protector = _context.Get <TestServer>(ContextKeys.TestServer).Services
                            .GetService <IDataProtectionProvider>()
                            .CreateProtector(ProtectorPurpose);

            var getProvidersRequest = new GetCourseProvidersRequest
            {
                Id            = 324,
                Location      = "Somewhere",
                DeliveryModes = new List <DeliveryModeType> {
                    DeliveryModeType.BlockRelease
                },
                ProviderRatings = new List <ProviderRating> {
                    ProviderRating.Excellent
                }
            };

            var json = JsonConvert.SerializeObject(getProvidersRequest);

            var encoded = Convert.ToBase64String(
                protector.Protect(System.Text.Encoding.UTF8.GetBytes(json)));

            _context.Set($"{nameof(GetCourseProvidersRequest)}={encoded}", ContextKeys.ProviderFiltersCookie);
        }
        public async Task Then_No_Course_Returns_Page_Not_Found(
            int providerId,
            int courseId,
            GetCourseProvidersRequest providersRequest,
            GetCourseProviderResult response,
            [Frozen] Mock <IMediator> mediator,
            [Frozen] Mock <ICookieStorageService <GetCourseProvidersRequest> > cookieStorageService,
            [Greedy] CoursesController controller)
        {
            //Arrange
            response.Course = null;
            cookieStorageService
            .Setup(x => x.Get(Constants.ProvidersCookieName))
            .Returns(providersRequest);
            mediator
            .Setup(x => x.Send(
                       It.IsAny <GetCourseProviderQuery>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            //Act
            var actual = await controller.CourseProviderDetail(courseId, providerId, "", "", "") as RedirectToRouteResult;

            //Assert
            Assert.IsNotNull(actual);
            actual.RouteName.Should().Be(RouteNames.Error404);
        }
Ejemplo n.º 4
0
        public async Task Then_If_The_Removed_And_Added_Parameter_Is_Is_Unable_To_Be_Decoded_An_Empty_String_Is_Added(
            GetCourseProvidersRequest request,
            GetCourseProvidersResult response,
            [Frozen] Mock <IMediator> mediator,
            [Frozen] Mock <IDataProtector> protector,
            [Frozen] Mock <IDataProtectionProvider> provider,
            [Greedy] CoursesController controller)
        {
            //Arrange
            protector.Setup(sut => sut.Unprotect(It.IsAny <byte[]>())).Throws <CryptographicException>();
            provider.Setup(x => x.CreateProtector(Constants.ShortlistProtectorName)).Returns(protector.Object);
            response.Course.StandardDates.LastDateStarts = DateTime.UtcNow.AddDays(5);
            mediator.Setup(x => x.Send(
                               It.Is <GetCourseProvidersQuery>(c => c.CourseId.Equals(request.Id) &&
                                                               c.Location.Equals(request.Location)),
                               It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            //Act
            var actual = await controller.CourseProviders(request) as ViewResult;

            //Assert
            Assert.IsNotNull(actual);
            var actualModel = actual.Model as CourseProvidersViewModel;

            Assert.IsNotNull(actualModel);
            actualModel.BannerUpdateMessage.Should().BeEmpty();
        }
        public async Task Then_ProviderFilters_Populated_From_Cookie_And_Id_From_Request_If_Matches_CookieValue(
            int providerId,
            int courseId,
            GetCourseProvidersRequest providersRequest,
            GetCourseProviderResult response,
            [Frozen] Mock <IMediator> mediator,
            [Frozen] Mock <ICookieStorageService <GetCourseProvidersRequest> > cookieStorageService,
            [Greedy] CoursesController controller)
        {
            //Arrange
            providersRequest.Id = courseId;
            response.Course.StandardDates.LastDateStarts = DateTime.UtcNow.AddDays(5);
            cookieStorageService
            .Setup(x => x.Get(Constants.ProvidersCookieName))
            .Returns(providersRequest);
            mediator
            .Setup(x => x.Send(
                       It.IsAny <GetCourseProviderQuery>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            //Act
            var actual = await controller.CourseProviderDetail(courseId, providerId, "", "", "") as ViewResult;

            //Assert
            var model = actual !.Model as CourseProviderViewModel;

            model !.GetCourseProvidersRequest.Where(key => key.Key != "Id").Should().BeEquivalentTo(providersRequest.ToDictionary().Where(key => key.Key != "Id"));
        }
Ejemplo n.º 6
0
        public async Task Then_The_Help_Url_Is_Built_From_Config_If_Feature_Enabled_And_Show_Demand_Is_Returned(
            GetCourseProvidersRequest request,
            GetCourseProvidersResult response,
            [Frozen] Mock <IMediator> mediator,
            [Frozen] Mock <IDataProtector> protector,
            [Frozen] Mock <IDataProtectionProvider> provider,
            [Frozen] Mock <IOptions <FindApprenticeshipTrainingWeb> > config,
            [Greedy] CoursesController controller)
        {
            //Arrange
            config.Object.Value.EmployerDemandFeatureToggle = true;
            response.ShowEmployerDemand = true;
            provider.Setup(x => x.CreateProtector(Constants.GaDataProtectorName)).Returns(protector.Object);
            response.Course.StandardDates.LastDateStarts = DateTime.UtcNow.AddDays(5);
            mediator.Setup(x => x.Send(
                               It.Is <GetCourseProvidersQuery>(c => c.CourseId.Equals(request.Id) &&
                                                               c.Location.Equals(request.Location)),
                               It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            //Act
            var actual = await controller.CourseProviders(request) as ViewResult;

            //Assert
            Assert.IsNotNull(actual);
            var actualModel = actual.Model as CourseProvidersViewModel;

            Assert.IsNotNull(actualModel);
            actualModel.HelpFindingCourseUrl.Should().Be($"{config.Object.Value.EmployerDemandUrl}/registerdemand/course/{actualModel.Course.Id}/enter-apprenticeship-details");
        }
Ejemplo n.º 7
0
        public async Task Then_If_The_Added_Parameter_Is_Provided_It_Is_Is_Decoded_And_Added_To_The_Model(
            string added,
            GetCourseProvidersRequest request,
            GetCourseProvidersResult response,
            [Frozen] Mock <IMediator> mediator,
            [Frozen] Mock <IDataProtector> protector,
            [Frozen] Mock <IDataProtectionProvider> provider,
            [Greedy] CoursesController controller
            )
        {
            //Arrange
            var encodedData = Encoding.UTF8.GetBytes($"{added}");

            request.Removed = "";
            request.Added   = WebEncoders.Base64UrlEncode(encodedData);
            protector.Setup(sut => sut.Unprotect(It.IsAny <byte[]>())).Returns(encodedData);
            provider.Setup(x => x.CreateProtector(Constants.ShortlistProtectorName)).Returns(protector.Object);
            response.Course.StandardDates.LastDateStarts = DateTime.UtcNow.AddDays(5);
            mediator.Setup(x => x.Send(
                               It.Is <GetCourseProvidersQuery>(c => c.CourseId.Equals(request.Id) &&
                                                               c.Location.Equals(request.Location)),
                               It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            //Act
            var actual = await controller.CourseProviders(request) as ViewResult;

            //Assert
            Assert.IsNotNull(actual);
            var actualModel = actual.Model as CourseProvidersViewModel;

            Assert.IsNotNull(actualModel);
            actualModel.BannerUpdateMessage.Should().Be($"{added} added to shortlist.");
        }
        public async Task Then_If_The_Course_Differs_From_The_Cookie_Request_The_Filter_And_Id_Are_Updated_And_Filters_Cleared(
            int providerId,
            int courseId,
            GetCourseProvidersRequest providersRequest,
            GetCourseProviderResult response,
            [Frozen] Mock <IMediator> mediator,
            [Frozen] Mock <ICookieStorageService <GetCourseProvidersRequest> > cookieStorageService,
            [Greedy] CoursesController controller)
        {
            //Arrange
            response.Course.StandardDates.LastDateStarts = DateTime.UtcNow.AddDays(5);
            cookieStorageService
            .Setup(x => x.Get(Constants.ProvidersCookieName))
            .Returns(providersRequest);
            mediator
            .Setup(x => x.Send(
                       It.IsAny <GetCourseProviderQuery>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            //Act
            var actual = await controller.CourseProviderDetail(courseId, providerId, "", "", "") as ViewResult;

            //Assert
            var model = actual !.Model as CourseProviderViewModel;

            model !.GetCourseProvidersRequest["Id"].Should().Be(courseId.ToString());
            model !.GetCourseProvidersRequest.ContainsKey("DeliveryModes[0]").Should().BeFalse();
            model !.GetCourseProvidersRequest.ContainsKey("ProviderRatings[0]").Should().BeFalse();
        }
Ejemplo n.º 9
0
        public async Task Then_The_Query_Is_Sent_And_Data_Retrieved_And_View_Shown(
            GetCourseProvidersRequest request,
            GetCourseProvidersResult response,
            [Frozen] Mock <IMediator> mediator,
            [Greedy] CoursesController controller)
        {
            //Arrange
            response.Course.StandardDates.LastDateStarts = DateTime.UtcNow.AddDays(5);
            mediator.Setup(x => x.Send(
                               It.Is <GetCourseProvidersQuery>(c => c.CourseId.Equals(request.Id) &&
                                                               c.Location.Equals(request.Location) &&
                                                               c.DeliveryModes.SequenceEqual(request.DeliveryModes.Select(type => (Domain.Courses.DeliveryModeType)type)) &&
                                                               c.ProviderRatings.SequenceEqual(request.ProviderRatings.Select(type => (Domain.Courses.ProviderRating)type))),
                               It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            //Act
            var actual = await controller.CourseProviders(request) as ViewResult;

            //Assert
            Assert.IsNotNull(actual);
            var actualModel = actual.Model as CourseProvidersViewModel;

            Assert.IsNotNull(actualModel);
            actualModel.Should().BeEquivalentTo(new CourseProvidersViewModel(request, response, null), options => options
                                                .Excluding(c => c.ProviderOrder)
                                                .Excluding(c => c.BannerUpdateMessage)
                                                .Excluding(c => c.HelpFindingCourseUrl)
                                                );
        }
Ejemplo n.º 10
0
        public async Task Then_The_Provider_Position_Is_Added_To_The_ViewModel(
            string encodedValue,
            GetCourseProvidersRequest request,
            GetCourseProvidersResult response,
            [Frozen] Mock <IMediator> mediator,
            [Frozen] Mock <ICookieStorageService <GetCourseProvidersRequest> > cookieStorageService,
            [Frozen] Mock <IDataProtector> protector,
            [Frozen] Mock <IDataProtectionProvider> provider,
            [Greedy] CoursesController controller)
        {
            //Arrange
            var encodedData = Encoding.UTF8.GetBytes(encodedValue);

            protector.Setup(sut => sut.Protect(It.IsAny <byte[]>())).Returns(encodedData);
            provider.Setup(x => x.CreateProtector(It.IsAny <string>())).Returns(protector.Object);
            response.Course.StandardDates.LastDateStarts = DateTime.UtcNow.AddDays(5);
            mediator.Setup(x => x.Send(
                               It.Is <GetCourseProvidersQuery>(c => c.CourseId.Equals(request.Id) &&
                                                               c.Location.Equals(request.Location)),
                               It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            //Act
            var actual = await controller.CourseProviders(request) as ViewResult;

            //Assert
            Assert.IsNotNull(actual);
            var actualModel = actual.Model as CourseProvidersViewModel;

            Assert.IsNotNull(actualModel);
            actualModel.ProviderOrder.Count.Should().Be(response.Providers.Count());
            actualModel.ProviderOrder.Select(c => c.Value).All(c => c.Equals(Convert.ToBase64String(encodedData))).Should().BeTrue();
            actualModel.ProviderOrder.Select(c => c.Key).ToList().Should()
            .BeEquivalentTo(response.Providers.Select(c => c.ProviderId).ToList());
        }
Ejemplo n.º 11
0
        public async Task Then_The_Shortlist_UserId_Is_Added_To_The_Cookie_If_Set(
            GetCourseProvidersRequest request,
            GetCourseProvidersResult response,
            ShortlistCookieItem shortlistCookieItem,
            [Frozen] Mock <IMediator> mediator,
            [Frozen] Mock <ICookieStorageService <ShortlistCookieItem> > shortlistCookieService,
            [Greedy] CoursesController controller)
        {
            //Arrange
            response.Course.StandardDates.LastDateStarts = DateTime.UtcNow.AddDays(5);
            mediator.Setup(x => x.Send(
                               It.Is <GetCourseProvidersQuery>(c => c.CourseId.Equals(request.Id) &&
                                                               c.ShortlistUserId.Equals(shortlistCookieItem.ShortlistUserId)),
                               It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);
            shortlistCookieService.Setup(x => x.Get(Constants.ShortlistCookieName)).Returns(shortlistCookieItem);

            //Act
            var actual = await controller.CourseProviders(request) as ViewResult;

            //Assert
            Assert.IsNotNull(actual);
            var actualModel = actual.Model as CourseProvidersViewModel;

            Assert.IsNotNull(actualModel);
        }
Ejemplo n.º 12
0
        public async Task Then_The_Provider_Position_List_Is_Encoded(
            GetCourseProvidersRequest request,
            GetCourseProvidersResult response,
            [Frozen] Mock <IMediator> mediator,
            [Frozen] Mock <IDataProtector> protector,
            [Frozen] Mock <IDataProtectionProvider> provider,
            [Greedy] CoursesController controller
            )
        {
            //Arrange
            provider.Setup(x => x.CreateProtector(Constants.GaDataProtectorName)).Returns(protector.Object);
            response.Course.StandardDates.LastDateStarts = DateTime.UtcNow.AddDays(5);
            mediator.Setup(x => x.Send(
                               It.Is <GetCourseProvidersQuery>(c => c.CourseId.Equals(request.Id) &&
                                                               c.Location.Equals(request.Location)),
                               It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            //Act
            await controller.CourseProviders(request);

            //Assert
            var expectedProviders = response.Providers.ToList();

            foreach (var responseProvider in expectedProviders)
            {
                protector.Verify(c => c.Protect(It.Is <byte[]>(
                                                    x => x[0].Equals(Encoding.UTF8.GetBytes($"{expectedProviders.IndexOf(responseProvider) + 1}|{response.TotalFiltered}")[0]))), Times.Once);
            }
        }
Ejemplo n.º 13
0
        public void Then_The_Total_Message_Is_Created_Correctly_For_Delivery_Modes_With_Location(
            int totalCount,
            int filterTotal,
            bool hasFilter,
            string expectedMessage,
            Dictionary <uint, string> providerOrder,
            GetCourseProvidersResult result)
        {
            //arrange
            var selectedDeliveryModes = new List <DeliveryModeType>();

            if (hasFilter)
            {
                selectedDeliveryModes.Add(DeliveryModeType.BlockRelease);
            }
            var request = new GetCourseProvidersRequest {
                DeliveryModes = selectedDeliveryModes
            };

            result.TotalFiltered = filterTotal;
            result.Total         = totalCount;

            //act
            var viewModel = new CourseProvidersViewModel(request, result, providerOrder);

            //assert
            viewModel.TotalMessage.Should().Be($"{expectedMessage} at {viewModel.Location}");
        }
Ejemplo n.º 14
0
        public void Then_The_Total_Message_Is_Created_Correctly_For_Provider_Ratings(
            int totalCount,
            int filterTotal,
            bool hasFilter,
            string expectedMessage,
            Dictionary <uint, string> providerOrder,
            GetCourseProvidersResult result)
        {
            //arrange
            var selectedProviderRatings = new List <ProviderRating>();

            if (hasFilter)
            {
                selectedProviderRatings.Add(ProviderRating.Good);
            }
            var request = new GetCourseProvidersRequest {
                ProviderRatings = selectedProviderRatings
            };

            result.TotalFiltered = filterTotal;
            result.Total         = totalCount;

            //act
            var viewModel = new CourseProvidersViewModel(request, result, providerOrder);

            //assert
            viewModel.TotalMessage.Should().Be(expectedMessage);
        }
Ejemplo n.º 15
0
        public async Task Then_The_Location_Is_Removed_From_The_Cookie_If_Set_To_Minus_One(
            GetCourseProvidersRequest request,
            GetCourseProvidersResult response,
            [Frozen] Mock <IMediator> mediator,
            [Frozen] Mock <ICookieStorageService <LocationCookieItem> > cookieStorageService,
            [Greedy] CoursesController controller)
        {
            //Arrange
            response.Course.StandardDates.LastDateStarts = DateTime.UtcNow.AddDays(5);
            response.Location = string.Empty;
            request.Location  = "-1";
            response.Location = null;
            mediator.Setup(x => x.Send(
                               It.Is <GetCourseProvidersQuery>(c => c.CourseId.Equals(request.Id) &&
                                                               c.Location.Equals(string.Empty)),
                               It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            //Act
            var actual = await controller.CourseProviders(request) as ViewResult;

            //Assert
            Assert.IsNotNull(actual);
            var actualModel = actual.Model as CourseProvidersViewModel;

            Assert.IsNotNull(actualModel);
            actualModel.HasLocation.Should().BeFalse();
            cookieStorageService.Verify(x => x.Delete(Constants.LocationCookieName));
        }
Ejemplo n.º 16
0
        public async Task Then_The_Location_Is_Added_To_The_Cookie_If_Set(
            GetCourseProvidersRequest request,
            GetCourseProvidersResult response,
            [Frozen] Mock <IMediator> mediator,
            [Frozen] Mock <ICookieStorageService <LocationCookieItem> > cookieStorageService,
            [Greedy] CoursesController controller)
        {
            //Arrange
            response.Course.StandardDates.LastDateStarts = DateTime.UtcNow.AddDays(5);
            mediator.Setup(x => x.Send(
                               It.Is <GetCourseProvidersQuery>(c => c.CourseId.Equals(request.Id) &&
                                                               c.Location.Equals(request.Location)),
                               It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            //Act
            var actual = await controller.CourseProviders(request) as ViewResult;

            //Assert
            Assert.IsNotNull(actual);
            var actualModel = actual.Model as CourseProvidersViewModel;

            Assert.IsNotNull(actualModel);
            cookieStorageService.Verify(x => x.Update(Constants.LocationCookieName,
                                                      It.Is <LocationCookieItem>(c => c.Name.Equals(response.Location) &&
                                                                                 c.Lat.Equals(response.LocationGeoPoint.FirstOrDefault()) &&
                                                                                 c.Lon.Equals(response.LocationGeoPoint.LastOrDefault())), 2));
            actualModel.HasLocation.Should().BeTrue();
        }
Ejemplo n.º 17
0
        public async Task Then_The_Help_Url_Set_If_Feature_Disabled(
            GetCourseProvidersRequest request,
            GetCourseProvidersResult response,
            [Frozen] Mock <IMediator> mediator,
            [Frozen] Mock <IDataProtector> protector,
            [Frozen] Mock <IDataProtectionProvider> provider,
            [Frozen] Mock <IOptions <FindApprenticeshipTrainingWeb> > config,
            [Greedy] CoursesController controller)
        {
            //Arrange
            config.Object.Value.EmployerDemandFeatureToggle = false;
            response.ShowEmployerDemand = true;
            provider.Setup(x => x.CreateProtector(Constants.GaDataProtectorName)).Returns(protector.Object);
            response.Course.StandardDates.LastDateStarts = DateTime.UtcNow.AddDays(5);
            mediator.Setup(x => x.Send(
                               It.Is <GetCourseProvidersQuery>(c => c.CourseId.Equals(request.Id) &&
                                                               c.Location.Equals(request.Location)),
                               It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            //Act
            var actual = await controller.CourseProviders(request) as ViewResult;

            //Assert
            Assert.IsNotNull(actual);
            var actualModel = actual.Model as CourseProvidersViewModel;

            Assert.IsNotNull(actualModel);
            actualModel.HelpFindingCourseUrl.Should().Be("https://help.apprenticeships.education.gov.uk/hc/en-gb#contact-us");
        }
        public void Then_Adds_ProviderRatings_To_Dictionary(GetCourseProvidersRequest request)
        {
            var dictionary = request.ToDictionary();

            for (int i = 0; i < request.ProviderRatings.Count; i++)
            {
                dictionary.Should().ContainKey($"{nameof(GetCourseProvidersRequest.ProviderRatings)}[{i}]")
                .WhichValue.Should().Be(request.ProviderRatings[i].ToString());
            }
        }
Ejemplo n.º 19
0
        public void Then_Sets_Properties(GetCourseProvidersRequest request, GetCourseProvidersResult result, Dictionary <uint, string> providerOrder)
        {
            var model = new CourseProvidersViewModel(request, result, providerOrder);

            model.Course.Should().BeEquivalentTo((CourseViewModel)result.Course);
            model.Providers.Should().BeEquivalentTo(
                result.Providers.Select(provider => (ProviderViewModel)provider));
            model.Total.Should().Be(result.Total);
            model.TotalFiltered.Should().Be(result.TotalFiltered);
            model.Location.Should().Be(result.Location);
            model.ProviderOrder.Should().BeEquivalentTo(providerOrder);
            model.ShortlistItemCount.Should().Be(result.ShortlistItemCount);
        }
Ejemplo n.º 20
0
        public void And_Zero_Results_And_Has_Location_And_No_Other_Filters_Then_Adds_Location_Text(
            Dictionary <uint, string> providerOrder,
            GetCourseProvidersRequest request,
            GetCourseProvidersResult result)
        {
            //arrange
            result.TotalFiltered = 0;
            result.Total         = 0;

            //act
            var viewModel = new CourseProvidersViewModel(request, result, providerOrder);

            //assert
            viewModel.TotalMessage.Should().Be($"0 results at {viewModel.Location}");
        }
        public async Task And_Exception_Then_Returns_Bad_Request(
            int id,
            GetCourseProvidersRequest request,
            List <DeliveryModeType> deliveryModes,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] TrainingCoursesController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetTrainingCourseProvidersQuery>(),
                       It.IsAny <CancellationToken>()))
            .Throws <InvalidOperationException>();

            var controllerResult = await controller.GetProviders(id, request) as StatusCodeResult;

            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
Ejemplo n.º 22
0
        public void Then_Builds_Provider_Ratings(GetCourseProvidersRequest request, GetCourseProvidersResult result, Dictionary <uint, string> providerOrder)
        {
            var expectedProviderRatings = new List <ProviderRatingOptionViewModel>();

            foreach (ProviderRating providerRatingType in Enum.GetValues(typeof(ProviderRating)))
            {
                expectedProviderRatings.Add(new ProviderRatingOptionViewModel
                {
                    ProviderRatingType = providerRatingType,
                    Description        = providerRatingType.GetDescription(),
                    Selected           = request.ProviderRatings.Any(type => type == providerRatingType)
                });
            }

            var model = new CourseProvidersViewModel(request, result, providerOrder);

            model.ProviderRatings.Should().BeEquivalentTo(expectedProviderRatings);
        }
Ejemplo n.º 23
0
        public void Then_Builds_Delivery_Modes_Excluding_NotFound(GetCourseProvidersRequest request, GetCourseProvidersResult result, Dictionary <uint, string> providerOrder)
        {
            var expectedDeliveryModes = new List <DeliveryModeOptionViewModel>();

            foreach (DeliveryModeType deliveryModeType in Enum.GetValues(typeof(DeliveryModeType)))
            {
                expectedDeliveryModes.Add(new DeliveryModeOptionViewModel
                {
                    DeliveryModeType = deliveryModeType,
                    Description      = deliveryModeType.GetDescription(),
                    Selected         = request.DeliveryModes.Any(type => type == deliveryModeType)
                });
            }

            var model = new CourseProvidersViewModel(request, result, providerOrder);

            model.DeliveryModes.Should().BeEquivalentTo(expectedDeliveryModes.Where(c => c.DeliveryModeType != DeliveryModeType.NotFound));
        }
        public async Task Then_Nulls_Are_Filtered_Out_From_The_Providers_List_And_The_Filtered_Count_Returned(
            int id,
            GetCourseProvidersRequest request,
            GetProvidersListItem provider1,
            GetProvidersListItem provider2,
            ProviderCourseSortOrder.SortOrder sortOrder,
            GetTrainingCourseProvidersResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] TrainingCoursesController controller)
        {
            request.DeliveryModes = new List <DeliveryModeType>
            {
                DeliveryModeType.Workplace
            };
            provider1.DeliveryTypes = provider1.DeliveryTypes.Select(c =>
            {
                c.DeliveryModes = "100PercentEmployer";
                return(c);
            }).ToList();
            provider2.DeliveryTypes = provider2.DeliveryTypes.Select(c =>
            {
                c.DeliveryModes = "DayRelease";
                return(c);
            }).ToList();
            mediatorResult.Providers = new List <GetProvidersListItem> {
                provider1, provider2
            };
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetTrainingCourseProvidersQuery>(c => c.Id.Equals(id)),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mediatorResult);

            var controllerResult = await controller.GetProviders(id, request) as ObjectResult;

            Assert.IsNotNull(controllerResult);
            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var model = controllerResult.Value as GetTrainingCourseProvidersResponse;

            Assert.IsNotNull(model);
            model.TrainingCourseProviders.Count().Should().Be(1);
            model.Total.Should().Be(mediatorResult.Total);
            model.TotalFiltered.Should().Be(model.TrainingCourseProviders.Count());
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> GetProviders(int id, [FromQuery] GetCourseProvidersRequest request)
        {
            try
            {
                var result = await _mediator.Send(new GetTrainingCourseProvidersQuery
                {
                    Id              = id,
                    Location        = request.Location,
                    SortOrder       = (short)request.SortOrder,
                    Lat             = request.Lat,
                    Lon             = request.Lon,
                    ShortlistUserId = request.ShortlistUserId
                });

                var mappedProviders = result.Providers
                                      .Select(c => new GetTrainingCourseProviderListItem().Map(c, result.Course.SectorSubjectAreaTier2Description, result.Course.Level, request.DeliveryModes, request.ProviderRatings, result.Location?.GeoPoint != null))
                                      .Where(x => x != null)
                                      .OrderByProviderScore(request.DeliveryModes)
                                      .ToList();
                var model = new GetTrainingCourseProvidersResponse
                {
                    TrainingCourse          = result.Course,
                    TrainingCourseProviders = mappedProviders,
                    Total         = result.Total,
                    TotalFiltered = mappedProviders.Count,
                    Location      = new GetLocationSearchResponseItem
                    {
                        Name     = result.Location?.Name,
                        Location = new GetLocationSearchResponseItem.LocationResponse
                        {
                            GeoPoint = result.Location?.GeoPoint
                        }
                    },
                    ShortlistItemCount = result.ShortlistItemCount,
                    ShowEmployerDemand = result.ShowEmployerDemand
                };
                return(Ok(model));
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"Error attempting to get a training course {id}");
                return(BadRequest());
            }
        }
        public async Task Then_Gets_Training_Course_And_Providers_From_Mediator(
            int id,
            GetCourseProvidersRequest request,
            GetTrainingCourseProvidersResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] TrainingCoursesController controller)
        {
            request.DeliveryModes = new List <DeliveryModeType>();
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetTrainingCourseProvidersQuery>(c =>
                                                               c.Id.Equals(id) &&
                                                               c.Location.Equals(request.Location) &&
                                                               c.SortOrder == (short)request.SortOrder &&
                                                               c.Lat.Equals(request.Lat) &&
                                                               c.Lon.Equals(request.Lon) &&
                                                               c.ShortlistUserId.Equals(request.ShortlistUserId)
                                                               ),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mediatorResult);

            var controllerResult = await controller.GetProviders(id, request) as ObjectResult;

            Assert.IsNotNull(controllerResult);
            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var model = controllerResult.Value as GetTrainingCourseProvidersResponse;

            Assert.IsNotNull(model);
            model.TrainingCourse.Should().BeEquivalentTo((GetTrainingCourseListItem)mediatorResult.Course);
            model.TrainingCourseProviders.Should()
            .BeEquivalentTo(mediatorResult.Providers,
                            options => options.Excluding(c => c.Ukprn)
                            .Excluding(c => c.AchievementRates)
                            .Excluding(c => c.DeliveryTypes)
                            .Excluding(c => c.FeedbackAttributes)
                            .Excluding(c => c.FeedbackRatings)
                            );
            model.Total.Should().Be(mediatorResult.Total);
            model.Location.Location.GeoPoint.Should().BeEquivalentTo(mediatorResult.Location.GeoPoint);
            model.Location.Name.Should().Be(mediatorResult.Location.Name);
            model.ShortlistItemCount.Should().Be(mediatorResult.ShortlistItemCount);
            model.ShowEmployerDemand.Should().Be(mediatorResult.ShowEmployerDemand);
        }
Ejemplo n.º 27
0
        public async Task And_Error_Then_Redirect_To_Error_Route(
            GetCourseProvidersRequest request,
            Exception exception,
            [Frozen] Mock <IMediator> mediator,
            [Greedy] CoursesController controller)
        {
            //Arrange
            mediator.Setup(x => x.Send(
                               It.Is <GetCourseProvidersQuery>(c => c.CourseId.Equals(request.Id)),
                               It.IsAny <CancellationToken>()))
            .ThrowsAsync(exception);

            //Act
            var actual = await controller.CourseProviders(request) as RedirectToRouteResult;

            //Assert
            Assert.IsNotNull(actual);
            actual.RouteName.Should().Be(RouteNames.Error500);
        }
Ejemplo n.º 28
0
        public async Task Then_If_No_Course_Then_Page_Not_Found_Returned(
            GetCourseProvidersRequest request,
            GetCourseProvidersResult response,
            [Frozen] Mock <IMediator> mediator,
            [Frozen] Mock <ICookieStorageService <GetCourseProvidersRequest> > cookieStorageService,
            [Greedy] CoursesController controller)
        {
            //Arrange
            response.Course = null;
            mediator.Setup(x => x.Send(
                               It.Is <GetCourseProvidersQuery>(c => c.CourseId.Equals(request.Id) &&
                                                               c.Location.Equals(request.Location)),
                               It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            //Act
            var actual = await controller.CourseProviders(request) as RedirectToRouteResult;

            //Assert
            Assert.IsNotNull(actual);
            actual.RouteName.Should().Be(RouteNames.Error404);
        }
Ejemplo n.º 29
0
        public async Task Then_The_Request_Is_Added_To_A_Cookie(
            GetCourseProvidersRequest request,
            GetCourseProvidersResult response,
            [Frozen] Mock <IMediator> mediator,
            [Frozen] Mock <ICookieStorageService <GetCourseProvidersRequest> > cookieStorageService,
            [Greedy] CoursesController controller)
        {
            //Arrange
            response.Course.StandardDates.LastDateStarts = DateTime.UtcNow.AddDays(5);
            mediator.Setup(x => x.Send(
                               It.Is <GetCourseProvidersQuery>(c => c.CourseId.Equals(request.Id) &&
                                                               c.Location.Equals(request.Location)),
                               It.IsAny <CancellationToken>()))
            .ReturnsAsync(response);

            //Act
            await controller.CourseProviders(request);

            //Assert
            cookieStorageService.Verify(x => x.Update(
                                            Constants.ProvidersCookieName,
                                            It.Is <GetCourseProvidersRequest>(c => c == request),
                                            2));
        }
        public async Task Then_FeedbackRating_Filter_Is_Applied(
            int id,
            GetCourseProvidersRequest request,
            string location,
            GetProvidersListItem provider1,
            GetProvidersListItem provider2,
            GetProvidersListItem provider3,
            GetTrainingCourseProvidersResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] TrainingCoursesController controller)
        {
            request.ProviderRatings = new List <FeedbackRatingType>
            {
                FeedbackRatingType.Excellent,
                FeedbackRatingType.Good
            };
            request.DeliveryModes     = null;
            provider1.FeedbackRatings = new List <GetFeedbackRatingItem>
            {
                new GetFeedbackRatingItem
                {
                    FeedbackName  = "Excellent",
                    FeedbackCount = 1,
                }
            };
            provider2.FeedbackRatings = new List <GetFeedbackRatingItem>
            {
                new GetFeedbackRatingItem
                {
                    FeedbackName  = "Poor",
                    FeedbackCount = 1,
                }
            };
            provider3.FeedbackRatings = new List <GetFeedbackRatingItem>
            {
                new GetFeedbackRatingItem
                {
                    FeedbackName  = "Good",
                    FeedbackCount = 1,
                }
            };
            mediatorResult.Providers = new List <GetProvidersListItem> {
                provider1, provider2, provider3
            };
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetTrainingCourseProvidersQuery>(c => c.Id.Equals(id)),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mediatorResult);

            var controllerResult = await controller.GetProviders(id, request) as ObjectResult;

            Assert.IsNotNull(controllerResult);
            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var model = controllerResult.Value as GetTrainingCourseProvidersResponse;

            Assert.IsNotNull(model);
            model.TrainingCourseProviders.Count().Should().Be(2);
            model.Total.Should().Be(mediatorResult.Total);
            model.TotalFiltered.Should().Be(model.TrainingCourseProviders.Count());
        }