コード例 #1
0
        public async Task Then_Gets_Routes_From_Mediator(
            GetRoutesQueryResult mediatorResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] RoutesController 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);

            foreach (var sector in model.Routes)
            {
                mediatorResult.Routes.Should().Contain(c => c.Name.Equals(sector.Route));
                mediatorResult.Routes.Should().Contain(c => c.Id.Equals(sector.Id));
            }
        }
コード例 #2
0
        public void Routes_Get_Id_StatusCode_200(int status)
        {
            RoutesController controller = new RoutesController(_pathRepository, _pointRepository, _routeRepository);

            IActionResult result = controller.GetRoutes("A", "A", 'A');

            int?statusCode = ((ObjectResult)(result.Should().Subject)).StatusCode;

            statusCode.Should().Be(status, $"StatusCode should be {status}");
        }
コード例 #3
0
        public void Paths_Get_Specific(params string[] values)
        {
            RoutesController controller = new RoutesController(_pathRepository, _pointRepository, _routeRepository);

            IActionResult result = controller.GetRoutes(values[0], values[1], char.Parse(values[2]));

            List <Route> route = ((ObjectResult)(result.Should().Subject)).Value.As <List <Route> >();

            route.Should().HaveCountGreaterThan(0, $"Routes total should be greater than 0");
        }
コード例 #4
0
        public void Routes_Get_All_StatusCode_404(int status)
        {
            IRouteRepository routeRepository = null;
            RoutesController controller      = new RoutesController(_pathRepository, _pointRepository, routeRepository);

            IActionResult result = controller.GetRoutes();

            int?statusCode = ((NotFoundResult)(result.Should().Subject)).StatusCode;

            statusCode.Should().Be(status, $"StatusCode should be {status}");
        }
コード例 #5
0
        public void RouteListAsync()
        {
            // Arrange
            RoutesController controller = new RoutesController();

            // Act
            IQueryable <Route> result = controller.GetRoutes();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreNotEqual(0, result.ToList().Count);
            Assert.IsInstanceOf <Route>(result.ToList()[0]);
        }
コード例 #6
0
        public async Task And_Exception_Then_Returns_InternalServerError(
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] RoutesController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetRoutesQuery>(),
                       It.IsAny <CancellationToken>()))
            .Throws <InvalidOperationException>();

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

            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
        }
コード例 #7
0
        public void GetRoutesTest()
        {
            // Arrange
            RoutesController routeController = new RoutesController(unitOfFactory);

            // Act
            IEnumerable <RouteDTO> result1 = routeController.GetRoutes();
            List <RouteDTO>        list    = (List <RouteDTO>)result1;
            var result2       = routeController.GetRoute(5);
            var result3       = routeController.GetRoute(-2);
            var contentresult = result2.Result as OkNegotiatedContentResult <RouteDTO>;

            // Assert
            Assert.IsTrue(list.Count > 0);
            Assert.AreEqual(5, contentresult.Content.Id);
            Assert.IsInstanceOfType(result3.Result, typeof(NotFoundResult));
        }