Exemplo n.º 1
0
        public async Task And_Exception_Then_Returns_Bad_Request(
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] TrainingProgrammesController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetTrainingProgrammesQuery>(),
                       It.IsAny <CancellationToken>()))
            .Throws <InvalidOperationException>();

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

            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
Exemplo n.º 2
0
        public async Task Then_Gets_TrainingProgrammes_From_Mediator(
            GetTrainingProgrammesQueryResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] TrainingProgrammesController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetTrainingProgrammesQuery>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mediatorResult);

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

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

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