コード例 #1
0
        public void HandleBusAndBusStopToRoute()
        {
            var target = new RoutesController(this._EFRouteRepository, this._EFRouteBusStopRepository, this._EFBusStopRepository, this._EFRouteBusRepository, this._MockMapper);

            //Add bus to route
            //Remove bus from other route first
            target.DeleteBusFromRoute(3, 5);
            target.PostAddBusWithDriverToRoute(
                7,
                new BusWithDriverDto {
                BusID = 5, BusDriverID = 8
            }
                );

            //Add busstop with order to route
            target.PostOrderOfBusStop(7, 1, 2);
            target.PostOrderOfBusStop(7, 2, 1);

            var okBusStopsResult = target.GetAllBusStopsOfRoute(7) as OkObjectResult;
            var busStops         = (List <ReturnBusStopWithOrderDto>)okBusStopsResult.Value;

            Assert.Equal(200, okBusStopsResult.StatusCode);
            Assert.Equal(2, busStops.Count);
            Assert.Equal("5733", busStops[1].BusStop.StopNumber.ToString());
            Assert.Equal("3306", busStops[0].BusStop.StopNumber.ToString());

            var okBusResult = target.GetAllBussesOfRoute(7) as OkObjectResult;
            var busses      = (List <ReturnBusAndDriverInRouteDto>)okBusResult.Value;

            Assert.Equal(200, okBusResult.StatusCode);
            Assert.Equal("AF22454", busses[0].Bus.RegistrationNumber.ToString());
            Assert.Single(busses);

            //Remove busstop from the route
            var okRemoveBusStopResult = target.DeleteBusStopFromRoute(7, 1) as OkObjectResult;
            var removeBusStop         = (bool)okRemoveBusStopResult.Value;

            Assert.Equal(200, okRemoveBusStopResult.StatusCode);
            Assert.True(removeBusStop);
            okBusStopsResult = target.GetAllBusStopsOfRoute(7) as OkObjectResult;
            busStops         = (List <ReturnBusStopWithOrderDto>)okBusStopsResult.Value;
            Assert.Single(busStops);
        }