Exemplo n.º 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 <GetRoutesQuery>(),
                       It.IsAny <CancellationToken>()))
            .ThrowsAsync(new InvalidOperationException());

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

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

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

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

            Assert.IsNotNull(model);
            model.Routes.Should().BeEquivalentTo(mediatorResult.Routes.Select(c => (GetRouteResponseItem)c).ToList());
        }