Esempio n. 1
0
        public async Task when_try_to_create_passenger_and_command_are_null_should_not_find_command_handler_and_throw_exception()
        {
            var driverRepositoryMock     = new Mock <IDriverRepository>();
            var nodeManagerMock          = new Mock <INodeManager>();
            var dailyRouteRepositoryMock = new Mock <IDailyRouteRepository>();

            var startNode = Node.Create("asdas", 21, 22);
            var endNode   = Node.Create("asdas", 21, 22);

            var route      = Route.Create(startNode, endNode);
            var moneyValue = new MoneyValue(13, "Pln");

            var dailyRoute =
                DailyRoute.CreateDailyRoute(DateTime.UtcNow, DateTime.UtcNow, route, Guid.NewGuid(), 5, moneyValue);

            dailyRouteRepositoryMock.Setup(x => x.GetAsync(It.IsAny <Guid>()))
            .ReturnsAsync(dailyRoute);

            CreateDailyRouteCommand command = null;

            var handler = new CreateDailyRouteCommandHandler(driverRepositoryMock.Object, nodeManagerMock.Object);

            Func <Task> act = async() => await handler.Handle(command, CancellationToken.None);

            act.Should().Throw <Exception>();
        }
        public async Task when_remove_daily_route_command_handler_should_not_be_null()
        {
            var dailyRouteRepositoryMock = new Mock <IDailyRouteRepository>();

            var startNode = Node.Create("asdas", 21, 22);
            var endNode   = Node.Create("asdas", 21, 22);

            var route      = Route.Create(startNode, endNode);
            var moneyValue = new MoneyValue(13, "Pln");

            var dailyRoute = DailyRoute.CreateDailyRoute(DateTime.UtcNow, DateTime.UtcNow, route, Guid.NewGuid(), 5, moneyValue);

            dailyRouteRepositoryMock.Setup(x => x.GetAsync(It.IsAny <Guid>()))
            .ReturnsAsync(dailyRoute);

            var command = new RemoveDailyRouteCommand()
            {
                RouteId = Guid.NewGuid(), UserId = Guid.NewGuid()
            };

            var handler = new RemoveDailyRouteCommandHandler(dailyRouteRepositoryMock.Object);

            var result = await handler.Handle(command, CancellationToken.None);

            result.Should().NotBeNull();
        }
Esempio n. 3
0
        public double CalculateCost(DailyRoute dailyRoute, int startStationId, int destinationStationId, CarType carType)
        {
            double cost                    = 0;
            var    allRouteStations        = dailyRoute.Route.RouteStations.ToList();
            var    startRouteStation       = allRouteStations.First(x => x.StationId == startStationId);
            var    destinationRouteStation = allRouteStations.First(x => x.StationId == destinationStationId);
            var    routeStations           = allRouteStations
                                             .Where(x => x.StationOrder >= startRouteStation.StationOrder &&
                                                    x.StationOrder <= destinationRouteStation.StationOrder).ToList();

            for (var i = 0; i < routeStations.Count - 1; i++)
            {
                var firstStationId  = routeStations[i].StationId;
                var secondStationId = routeStations[i + 1].StationId;
                var distance        = context.Distances.FirstOrDefault(x => x.StartStationId == firstStationId && x.DestinationStationId == secondStationId);
                if (distance == null)
                {
                    cost += 1 * carType.CostRate;
                }
                else
                {
                    cost += Math.Ceiling(distance.DistanceValue * carType.CostRate);
                }
            }

            return(cost);
        }
Esempio n. 4
0
 public async Task UpdateAsync(DailyRoute dailyRoute)
 {
     _passengerContext.DailyRoutes.Update(dailyRoute);
     await _passengerContext.SaveChangesAsync();
 }
Esempio n. 5
0
        public async Task CreateAsync(DailyRoute dailyRoute)
        {
            await _passengerContext.AddAsync(dailyRoute);

            await _passengerContext.SaveChangesAsync();
        }
Esempio n. 6
0
        public DateTime CalculateArrivalDepartureTime(DailyRoute dailyRoute, int stationId)
        {
            var routeStation = dailyRoute.Route.RouteStations.First(x => x.StationId == stationId);

            return(dailyRoute.StartDateTime.AddMinutes(routeStation.MinutesFromStart));
        }
Esempio n. 7
0
 public int CalculateAvailableSeats(DailyRoute dailyRoute, int carTypeId)
 {
     return(dailyRoute.Route.Train.Cars.Where(x => x.CarTypeId == carTypeId).Sum(x => CalculateAvailableSeats(x)));
 }