Example #1
0
        public async Task And_Exception_Then_Returns_Bad_Request(
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] ReferenceDataController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetTrainingCoursesQuery>(),
                       It.IsAny <CancellationToken>()))
            .ThrowsAsync(new InvalidOperationException());

            var controllerResult = await controller.GetTrainingCourses() as StatusCodeResult;

            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
        }
Example #2
0
        public async Task Then_Gets_Training_Courses_From_Mediator(
            GetTrainingCoursesQueryResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] ReferenceDataController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetTrainingCoursesQuery>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mediatorResult);

            var controllerResult = await controller.GetTrainingCourses() as ObjectResult;

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

            Assert.IsNotNull(model);
            model.Should().BeEquivalentTo((GetTrainingCoursesListResponse)mediatorResult);
        }