예제 #1
0
        public async Task Then_Gets_Training_Course_And_Providers_Count_From_Mediator(
            int standardCode,
            double lat,
            double lon,
            Guid?shortlistUserId,
            GetTrainingCourseResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] TrainingCoursesController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetTrainingCourseQuery>(c =>
                                                      c.Id.Equals(standardCode) &&
                                                      c.Lat.Equals(lat) &&
                                                      c.Lon.Equals(lon) &&
                                                      c.ShortlistUserId.Equals(shortlistUserId)
                                                      ),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mediatorResult);

            var controllerResult = await controller.Get(standardCode, lat, lon, shortlistUserId) as ObjectResult;

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

            Assert.IsNotNull(model);
            model.TrainingCourse.Should().BeEquivalentTo((GetTrainingCourseListItem)mediatorResult.Course);

            model.TrainingCourse.Id.Should().Be(mediatorResult.Course.LarsCode);
            model.ProvidersCount.TotalProviders.Should().Be(mediatorResult.ProvidersCount);
            model.ProvidersCount.ProvidersAtLocation.Should().Be(mediatorResult.ProvidersCountAtLocation);
            model.ShortlistItemCount.Should().Be(mediatorResult.ShortlistItemCount);
            model.ShowEmployerDemand.Should().Be(mediatorResult.ShowEmployerDemand);
        }
예제 #2
0
        public async Task And_Exception_Then_Returns_Bad_Request(
            int standardCode,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] TrainingCoursesController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetTrainingCourseQuery>(),
                       It.IsAny <CancellationToken>()))
            .Throws <InvalidOperationException>();

            var controllerResult = await controller.Get(standardCode) as StatusCodeResult;

            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
예제 #3
0
        public async Task Then_If_Null_Response_Then_Not_Found_Returned(
            int standardCode,
            GetTrainingCourseResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] TrainingCoursesController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetTrainingCourseQuery>(c =>
                                                      c.Id.Equals(standardCode)
                                                      ),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(new GetTrainingCourseResult());

            var controllerResult = await controller.Get(standardCode) as StatusCodeResult;

            Assert.IsNotNull(controllerResult);
            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
        public async Task Then_Gets_Training_Courses_From_Mediator(
            int standardCode,
            GetTrainingCourseResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] TrainingCoursesController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.Is <GetTrainingCourseQuery>(c => c.Id.Equals(standardCode)),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mediatorResult);

            var controllerResult = await controller.Get(standardCode) as ObjectResult;

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

            Assert.IsNotNull(model);
            model.TrainingCourse.Should().BeEquivalentTo(mediatorResult.Course, options => options
                                                         .Excluding(tc => tc.ApprenticeshipFunding)
                                                         .Excluding(tc => tc.StandardDates)
                                                         );
        }