Exemple #1
0
        public async Task And_Exception_Then_Returns_Bad_Request(
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] TrainingCoursesController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetFrameworksQuery>(),
                       It.IsAny <CancellationToken>()))
            .Throws <InvalidOperationException>();

            var controllerResult = await controller.GetFrameworks() as BadRequestResult;

            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
        public async Task Then_Gets_Frameworks_From_Mediator(
            GetFrameworksResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] TrainingCoursesController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetFrameworksQuery>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mediatorResult);

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

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

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