public int GetFeedDuration(RouteAM route) { var feedLeg = GetLeg(route, RouteLegKind.Feed); var result = feedLeg != null ? feedLeg.Duration : 0; return(result); }
public async Task <BookingRouteAM> CalculateBookingRoute(RouteAM route, CargoAM cargo, BasketAM requestBasket) { var rootAddress = RouteService.GetRootAddress(route); var feedDistance = RouteService.GetFeedDistance(route); var feedDuration = RouteService.GetFeedDuration(route); var totalDistance = RouteService.GetTotalDistance(route); var billInfo = await BillService.GetBillInfo(rootAddress.ToCoordinate(), cargo.WeightCatalogItemId); // клонируем т.к. количество километров для каждого маршрута - индивидуально, а параметром передается общий объект var basket = requestBasket.Clone() as BasketAM; basket.KmValue = totalDistance; var bill = await BillService.CalculateBill(billInfo, basket); var title = $"{rootAddress.Locality} - {bill.TotalCost}₽"; return(new BookingRouteAM { RootAddress = rootAddress, FeedDistance = feedDistance, FeedDuration = feedDuration, TotalDistance = totalDistance, Bill = bill, Title = title }); }
public int GetFeedDistance(RouteAM route) { var feedLeg = GetLeg(route, RouteLegKind.Feed); var result = feedLeg != null ? feedLeg.Distance : 0; return(result); }
public async Task <RouteAM> FromExternalRoute(AddressAM origin, AddressAM destination, WaypointsAM waypoints, RouteEM externalRoute) { var result = new RouteAM { Comment = waypoints.Comment }; var routePoints = new List <AddressAM> { origin, destination }; routePoints.AddRange(waypoints.Points); routePoints = routePoints.Distinct().ToList(); foreach (var externalLeg in externalRoute.Legs) { var routeLegKind = RouteLegKind.Transportation; if (externalLeg.Equals(externalRoute.Legs.First())) { routeLegKind = RouteLegKind.Feed; } if (externalLeg.Equals(externalRoute.Legs.Last())) { routeLegKind = RouteLegKind.WayBack; } var startAddress = await AddressService.GetNearestAddress(externalLeg.StartCoordinate, routePoints); startAddress.AdjustedLatitude = externalLeg.StartCoordinate.Latitude; startAddress.AdjustedLongitude = externalLeg.StartCoordinate.Longitude; var endAddress = await AddressService.GetNearestAddress(externalLeg.EndCoordinate, routePoints); endAddress.AdjustedLatitude = externalLeg.EndCoordinate.Latitude; endAddress.AdjustedLongitude = externalLeg.EndCoordinate.Longitude; var leg = new RouteLegAM { Kind = routeLegKind, StartAddress = startAddress, EndAddress = endAddress, Distance = externalLeg.Distance, Duration = externalLeg.Duration }; result.Legs.Add(leg); } return(result); }
public async Task <Route> CreateDomainRoute(RouteAM route) { var domainRoute = await DomainRouteService.Create(route.Comment); foreach (var leg in route.Legs) { var startDomainAddress = await AddressService.GetOrCreateDomainAddress(leg.StartAddress); var endDomainAddress = await AddressService.GetOrCreateDomainAddress(leg.EndAddress); var routeLeg = await DomainRouteLegService.Create( domainRoute.Id, leg.Kind, startDomainAddress.Id, endDomainAddress.Id, leg.Duration, leg.Distance); } return(domainRoute); }
public void GetRootAddress() { var rootAddress = new AddressAM(); var route = new RouteAM { Comment = "It is customer comment", Legs = { new RouteLegAM { StartAddress = rootAddress, EndAddress = new AddressAM(), Distance = 30000, Duration = 1600, Kind = RouteLegKind.Feed }, new RouteLegAM { StartAddress = new AddressAM(), EndAddress = new AddressAM(), Distance = 35000, Duration = 18000, Kind = RouteLegKind.Transportation }, new RouteLegAM { StartAddress = new AddressAM(), EndAddress = rootAddress, Distance = 38000, Duration = 19600, Kind = RouteLegKind.WayBack } } }; var result = Suite.RouteService.GetRootAddress(route); Assert.Equal(rootAddress, result); }
public RouteLegAM GetLeg(RouteAM route, RouteLegKind legKind) { return(route.Legs.FirstOrDefault(l => l.Kind.Equals(RouteLegKind.Feed))); }
public int GetTotalDistance(RouteAM route) { return(route.Legs.Select(l => l.Distance).Sum()); }
public AddressAM GetRootAddress(RouteAM route) { return(GetLeg(route, RouteLegKind.Feed)?.StartAddress); }
public async Task CalculateBookingRoute() { var commonId = 1; var rootAddress = new AddressAM { Locality = "Ярославль", Latitude = 11.1111, Longitude = 22.2222 }; var billInfo = new BillInfoAM { PriceId = commonId++, CommissionPercentage = 10, DegreeOfDifficulty = 1 }; var basket = new BasketAM { KmValue = 0, LoadingValue = 1, LockedSteeringValue = 0, LockedWheelsValue = 3, OverturnedValue = 0, DitchValue = 1 }; var cargo = new CargoAM { BrandCatalogItemId = commonId++, KindCatalogItemId = commonId++, RegistrationNumber = "e111ey777", WeightCatalogItemId = commonId++ }; var route = new RouteAM { Legs = { new RouteLegAM { Kind = RouteLegKind.Feed, Distance = 3000, Duration = 1200 }, new RouteLegAM { Kind = RouteLegKind.Transportation, Distance = 100000, Duration = 7200 }, new RouteLegAM { Kind = RouteLegKind.WayBack, Distance = 103000, Duration = 8400 } } }; var feedDistance = route.Legs[0].Distance; var feedDuration = route.Legs[0].Duration; var totalDistance = route.Legs.Select(l => l.Distance).Sum(); var bill = new BillAM { TotalCost = 100 }; var title = $"{rootAddress.Locality} - {bill.TotalCost}₽"; Suite.RouteServiceMock .Setup(m => m.GetRootAddress(route)) .Returns(rootAddress); Suite.RouteServiceMock .Setup(m => m.GetFeedDistance(route)) .Returns(feedDistance); Suite.RouteServiceMock .Setup(m => m.GetFeedDuration(route)) .Returns(feedDuration); Suite.RouteServiceMock .Setup(m => m.GetTotalDistance(route)) .Returns(totalDistance); Suite.BillServiceMock .Setup(m => m.GetBillInfo( It.Is <Coordinate>(c => c.Latitude.Equals(rootAddress.Latitude) && c.Longitude.Equals(rootAddress.Longitude)), cargo.WeightCatalogItemId)) .ReturnsAsync(billInfo); Suite.BillServiceMock .Setup(m => m.CalculateBill( billInfo, It.Is <BasketAM>(b => (b != basket) && b.KmValue.Equals(totalDistance)))) .ReturnsAsync(bill); var result = await Suite.BookingService.CalculateBookingRoute(route, cargo, basket); Assert.Equal(rootAddress, result.RootAddress); Assert.Equal(feedDistance, result.FeedDistance); Assert.Equal(feedDuration, result.FeedDuration); Assert.Equal(totalDistance, result.TotalDistance); Assert.Equal(bill, result.Bill); Assert.Equal(title, result.Title); }
public async Task CreateDomainRoute() { var commonId = 1; var rootAddress = new AddressAM { Latitude = 55.55555, Longitude = 66.66666 }; var firstWaypointAddress = new AddressAM { Latitude = 11.11111, Longitude = 22.22222, AdjustedLatitude = 11.11000, AdjustedLongitude = 22.22000 }; var secondWaypointAddress = new AddressAM { Latitude = 33.33333, Longitude = 44.44444, AdjustedLatitude = 33.33000, AdjustedLongitude = 44.44000 }; var route = new RouteAM { Comment = "It is customer comment", Legs = { new RouteLegAM { StartAddress = rootAddress, EndAddress = firstWaypointAddress, Distance = 30000, Duration = 1600, Kind = RouteLegKind.Feed }, new RouteLegAM { StartAddress = firstWaypointAddress, EndAddress = secondWaypointAddress, Distance = 35000, Duration = 18000, Kind = RouteLegKind.Transportation }, new RouteLegAM { StartAddress = secondWaypointAddress, EndAddress = rootAddress, Distance = 38000, Duration = 19600, Kind = RouteLegKind.WayBack } } }; var domainRoute = new Route { Id = commonId++ }; var domainRouteAddress = new Address { Id = commonId++ }; var firstDomainWaypointAddress = new Address { Id = commonId++ }; var secondDomainWaypoinAddress = new Address { Id = commonId++ }; Suite.AddressServiceMock .Setup(m => m.GetOrCreateDomainAddress(rootAddress)) .ReturnsAsync(domainRouteAddress); Suite.AddressServiceMock .Setup(m => m.GetOrCreateDomainAddress(firstWaypointAddress)) .ReturnsAsync(firstDomainWaypointAddress); Suite.AddressServiceMock .Setup(m => m.GetOrCreateDomainAddress(secondWaypointAddress)) .ReturnsAsync(secondDomainWaypoinAddress); Suite.DomainRouteServiceMock .Setup(m => m.Create(route.Comment)) .ReturnsAsync(domainRoute); var result = await Suite.RouteService.CreateDomainRoute(route); Suite.DomainRouteServiceMock .Verify(m => m.Create(route.Comment)); var firstLeg = route.Legs[0]; Suite.DomainRouteLegServiceMock .Verify(m => m.Create(domainRoute.Id, firstLeg.Kind, domainRouteAddress.Id, firstDomainWaypointAddress.Id, firstLeg.Duration, firstLeg.Distance)); var secondLeg = route.Legs[1]; Suite.DomainRouteLegServiceMock .Verify(m => m.Create(domainRoute.Id, secondLeg.Kind, firstDomainWaypointAddress.Id, secondDomainWaypoinAddress.Id, secondLeg.Duration, secondLeg.Distance)); var thirdLeg = route.Legs[2]; Suite.DomainRouteLegServiceMock .Verify(m => m.Create(domainRoute.Id, thirdLeg.Kind, secondDomainWaypoinAddress.Id, domainRouteAddress.Id, thirdLeg.Duration, thirdLeg.Distance)); }
public async Task CreateOrder() { var commonId = 1; var booking = new BookingAM { OrderTime = DateTime.MinValue, RootAddress = new AddressAM { Latitude = 11.2222, Longitude = 22.3333 }, BillInfo = new BillInfoAM { PriceId = commonId++, CommissionPercentage = 10, DegreeOfDifficulty = 1 }, Customer = new CustomerAM { PhoneNumber = "79101112233", FirstName = "Генадий" }, Basket = new BasketAM { KmValue = 200, DitchValue = 0, LoadingValue = 1, LockedWheelsValue = 2, LockedSteeringValue = 1, OverturnedValue = 0 }, Cargo = new CargoAM { BrandCatalogItemId = commonId++, KindCatalogItemId = commonId++, WeightCatalogItemId = commonId++, RegistrationNumber = "в100вв76", Comment = "Не работает пневма" }, Waypoints = new WaypointsAM { Points = new List <AddressAM> { new AddressAM { Country = "Россия", Area = "Ярославская область", Province = "Ярославский район", Locality = "Ярославль", Street = "пр-кт Революции", House = "120" }, new AddressAM { Country = "Россия", Area = "Ярославская область", Province = "Пошехонский район", Locality = "Пошехонье", Street = "Солнечная", House = "12" } }, Comment = "На закрытой парковке. Попросить охраника открыть шлагбаум" } }; var route = new RouteAM(); var domainRoute = new Route { Id = commonId++ }; var domainCustomer = new Customer { Id = commonId++ }; var domainCargo = new Cargo { Id = commonId++ }; var domainBill = new Bill { Id = commonId++ }; var domainOrder = new Order { Id = commonId++ }; Suite.CustomerServiceMock .Setup(m => m.GetDomainCustomer(booking.Customer)) .ReturnsAsync(domainCustomer); Suite.CargoServiceMock .Setup(m => m.CreateDomainCargo(booking.Cargo)) .ReturnsAsync(domainCargo); Suite.RouteServiceMock .Setup(m => m.GetRoute(booking.RootAddress, booking.Waypoints)) .ReturnsAsync(route); Suite.RouteServiceMock .Setup(m => m.CreateDomainRoute(route)) .ReturnsAsync(domainRoute); Suite.BillServiceMock .Setup(m => m.CreateDomainBill(booking.BillInfo, booking.Basket)) .ReturnsAsync(domainBill); Suite.DomainOrderServiceMock .Setup(m => m.Create(booking.OrderTime, domainCustomer.Id, domainCargo.Id, domainRoute.Id, domainBill.Id)) .ReturnsAsync(domainOrder); var result = await Suite.OrderService.CreateOrder(booking); Suite.OrderStateServiceMock .Verify(m => m.New(domainOrder.Id)); Assert.Equal(domainOrder, result); }