Ejemplo n.º 1
0
        public async void Create()
        {
            var tripServiceMock = new Mock <ITripService> ();
            var pathServiceMock = new Mock <IPathService> ();

            string lineID            = "Line:1";
            string pathID            = "Path:1";
            string tripDepartureTime = "20:12:10";

            var trip    = new Trip(lineID, pathID, tripDepartureTime);
            var tripDTO = new TripDTO(trip.Id.AsGuid(), new LineId(lineID), new PathId(pathID), tripDepartureTime);

            var path         = new PathId(pathID);
            var pathDTO      = new PathDTO(pathID, true, new List <SegmentDTO> ());
            var creatingTrip = new CreatingTripDTO(lineID, pathID, tripDepartureTime);

            pathServiceMock.Setup(_ => _.GetById(path)).ReturnsAsync(pathDTO);
            tripServiceMock.Setup(_ => _.AddTrip(creatingTrip, new List <CreatingNodePassageDTO> ())).ReturnsAsync(tripDTO);

            var controller = new TripController(tripServiceMock.Object, pathServiceMock.Object);

            var actual = await controller.Create(creatingTrip);

            Assert.NotNull(actual);
            Assert.NotNull(actual.Result);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostParsePath([FromBody] PathDTO path)
        {
            if (path == null || string.IsNullOrEmpty(path.Path))
            {
                return(BadRequest(BaseStatusDto.CreateErrorDto("Path string is not correct.")));
            }

            try
            {
                Subtitle subtitle = _subtitleService.GetSubtitleByPath(path.Path);

                if (subtitle == null)
                {
                    return(BadRequest(BaseStatusDto.CreateErrorDto($"There is not any Subtitle record with Path = {path}.")));
                }

                await Task.Run(() => _subtitleService.ParseSubtitle(subtitle));

                return(Ok(BaseStatusDto.CreateSuccessDto("Subtitle parsing operation is successful.")));
            }
            catch (Exception ex)
            {
                _logger.Debug($"{ex.GetType()} exception is generated.");
                _logger.Debug($"{ex.Message}");

                return(BadRequest(BaseStatusDto.CreateErrorDto(ex.Message)));
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <TripDTO> > Create(CreatingTripDTO dto)
        {
            try {
                PathDTO path = await this.pathService.GetById(new PathId (dto.pathID));

                var nodePassageList = new List <CreatingNodePassageDTO> ();

                int departTime = TimeUtils.fromTimeToSec(new Time(dto.tripDepartureTime));

                int passageTime = 0;

                for (int i = 0; i < path.segments.Count; i++)
                {
                    var segment = path.segments[i];
                    CreatingNodePassageDTO nodePassage;

                    if (i == 0)
                    {
                        nodePassage  = new CreatingNodePassageDTO(segment.firstNodeID.code, dto.tripDepartureTime);
                        passageTime += TimeUtils.fromTimeToSec(new Time(dto.tripDepartureTime));

                        nodePassageList.Add(nodePassage);
                    }
                    else
                    {
                        var previousSegment = path.segments[i - 1];

                        int nodePassageSec = passageTime + previousSegment.travelTimeBetweenNodes;

                        passageTime = nodePassageSec;

                        string nodePassageString = TimeUtils.fromSecToString(nodePassageSec);

                        nodePassage = new CreatingNodePassageDTO(segment.firstNodeID.code, nodePassageString);

                        nodePassageList.Add(nodePassage);

                        if (i == path.segments.Count - 1)
                        {
                            nodePassageSec    = passageTime + segment.travelTimeBetweenNodes;
                            nodePassageString = TimeUtils.fromSecToString(nodePassageSec);
                            CreatingNodePassageDTO lastNodePassage = new CreatingNodePassageDTO(segment.secondNodeID.code, nodePassageString);

                            nodePassageList.Add(lastNodePassage);
                        }
                    }
                }

                var trip = await tripService.AddTrip(dto, nodePassageList);

                var a = CreatedAtAction(
                    nameof(GetById),
                    new { id = trip.Id },
                    trip
                    );
                return(a);
            } catch (BusinessRuleValidationException ex) {
                return(BadRequest(new { Message = ex.Message }));
            }
        }
Ejemplo n.º 4
0
        public SearchResultDTO ClickCalculate(Parcel parcel, City source, City destination)
        {
            List <Edge> edges;
            List <City> cities;

            cities = MappingService.GetCities();
            edges  = MappingService.GetEdges(cities);    //context.GetAllEdges();

            Graph <City, string> graphPrice     = GraphFabric.CreateGraphPrice(cities, edges, "priceCost", parcel);
            Graph <City, string> graphTime      = GraphFabric.CreateGraphTime(cities, edges, "timeCost");
            Graph <City, string> graphPriceTime = GraphFabric.CreateGraphTime(cities, edges, "price times cost");

            RouteCalculatorService routeCalcPrice = new RouteCalculatorService(graphPrice);
            ShortestPathResult     resultPrice    = routeCalcPrice.CalculateShortestPath(source, destination);
            List <City>            pathPrice      = routeCalcPrice.GetCityPath(resultPrice);

            RouteCalculatorService routeCalcTime = new RouteCalculatorService(graphTime);
            ShortestPathResult     resultTime    = routeCalcPrice.CalculateShortestPath(source, destination);
            List <City>            pathTime      = routeCalcTime.GetCityPath(resultTime);

            RouteCalculatorService routePriceTime  = new RouteCalculatorService(graphPriceTime);
            ShortestPathResult     resultPriceTime = routeCalcPrice.CalculateShortestPath(source, destination);
            List <City>            pathPriceTime   = routeCalcTime.GetCityPath(resultPriceTime);

            this.SaveParcel(parcel);

            var cPath = new PathDTO()
            {
                Cities   = ReturnCityDtos(pathPrice),
                Duration = 42,
                Price    = resultPrice.Distance
            };

            var fPath = new PathDTO()
            {
                Cities   = ReturnCityDtos(pathTime),
                Duration = resultTime.Distance,
                Price    = 42
            };

            var bPath = new PathDTO()
            {
                Cities   = ReturnCityDtos(pathPriceTime),
                Duration = resultPriceTime.Distance,
                Price    = 42
            };

            return(new SearchResultDTO
            {
                Cheapest = cPath,
                Fastest = fPath,
                Best = bPath
            });
        }
Ejemplo n.º 5
0
        public async Task <PathDTO> GetById(PathId id)
        {
            PathDTO path = await HttpRequest <PathDTO> .GetByID("http://localhost:8080/api/path/" + id.ToString());

            if (path == null)
            {
                throw new Exception("Invalid path for code " + id.ToString());
            }

            return(path);
        }
Ejemplo n.º 6
0
        public async Task <int> GetPathDurationById(PathId id)
        {
            PathDTO path = await HttpRequest <PathDTO> .GetByID("http://localhost:8080/api/path/" + id.ToString());

            if (path == null)
            {
                throw new Exception("Invalid path for code " + id.ToString());
            }

            int duration = 0;

            foreach (var item in path.segments)
            {
                duration += item.travelTimeBetweenNodes;
            }

            return(duration);
        }