Esempio n. 1
0
        public async Task Then_Returns_List_From_Handler(
            int ukprn,
            int?courseId,
            double?lat,
            double?lon,
            int radius,
            GetAggregatedCourseDemandListResult resultFromMediator,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] DemandController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetAggregatedCourseDemandListQuery>(query =>
                                                                  query.Ukprn == ukprn &&
                                                                  query.CourseId == courseId &&
                                                                  query.Lat.Equals(lat) &&
                                                                  query.Lon.Equals(lon) &&
                                                                  query.Radius == radius),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(resultFromMediator);

            var result = await controller.GetAggregatedCourseDemandList(ukprn, courseId, lat, lon, radius) as ObjectResult;

            result.Should().NotBeNull();
            result !.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var model = result.Value as GetAggregatedCourseDemandListResponse;

            model !.AggregatedCourseDemandList.Should().BeEquivalentTo(
                resultFromMediator.AggregatedCourseDemandList.Select(summary =>
                                                                     (GetAggregatedCourseDemandSummaryResponse)summary));
            model.TotalFiltered.Should().Be(resultFromMediator.AggregatedCourseDemandList.Count());
            model.Total.Should().Be(resultFromMediator.Total);
        }
Esempio n. 2
0
        public async Task Then_Gets_Courses_And_Demands_From_Mediator(
            int ukprn,
            int courseId,
            string location,
            int locationRadius,
            List <string> routes,
            GetAggregatedCourseDemandListResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] DemandController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetAggregatedCourseDemandListQuery>(query =>
                                                                  query.Ukprn == ukprn &&
                                                                  query.CourseId == courseId &&
                                                                  query.LocationName == location &&
                                                                  query.LocationRadius == locationRadius),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mediatorResult);

            var controllerResult = await controller.GetAggregatedCourseDemandList(ukprn, courseId, location, locationRadius, routes) as ObjectResult;

            controllerResult !.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var model = controllerResult.Value as GetAggregatedCourseDemandListResponse;

            model !.TrainingCourses.Should().BeEquivalentTo(mediatorResult.Courses.Select(item => (GetCourseListItem)item));
            model !.AggregatedCourseDemands.Should().BeEquivalentTo(mediatorResult.AggregatedCourseDemands.Select(response => (GetAggregatedCourseDemandSummary)response));
            model !.Total.Should().Be(mediatorResult.Total);
            model !.TotalFiltered.Should().Be(mediatorResult.TotalFiltered);
            model !.Location.Should().BeEquivalentTo((GetLocationSearchResponseItem)mediatorResult.LocationItem);
            model !.Routes.Should().BeEquivalentTo(mediatorResult.Routes);
        }
Esempio n. 3
0
        public async Task And_Exception_Then_Returns_Bad_Request(
            int ukprn,
            int courseId,
            string location,
            int locationRadius,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] DemandController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetAggregatedCourseDemandListQuery>(),
                       It.IsAny <CancellationToken>()))
            .Throws <InvalidOperationException>();

            var controllerResult = await controller.GetAggregatedCourseDemandList(ukprn, courseId, location, locationRadius) as BadRequestResult;

            controllerResult !.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }