コード例 #1
0
        public async Task <Garage> CreateDomainGarage(int cityId, AddressAM address)
        {
            using (var transaction = await TransactionService.BeginTransaction())
            {
                try
                {
                    var domainCity = await CityService.GetDomainCity(cityId);

                    if (domainCity == null)
                    {
                        throw new EntityNotFoundException($"CityId: {cityId} doesn't exist.", "City");
                    }

                    var domainAddress = await AddressService.CreateDomainAddress(AddressKind.Garage, address);

                    var result = await DomainGarageService.Create(cityId, domainAddress.Id, domainCity.PricelistId);

                    transaction.Commit();
                    return(result);
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
コード例 #2
0
        public async Task CreateCity()
        {
            var commonId = 1;

            var address = new AddressAM
            {
                Country   = "Россия",
                Province  = "Ярославская область",
                Area      = "Пошехонский район",
                Locality  = "Пошехонье",
                Latitude  = 11.1111,
                Longitude = 22.2222
            };

            var domainAddress = new Address {
                Id = commonId++
            };
            var domainPricelist = new Pricelist {
                Id = commonId++
            };

            var domain = "poshehon";

            Suite.AddressServiceMock
            .Setup(m => m.CreateDomainAddress(AddressKind.City, address))
            .ReturnsAsync(domainAddress);
            Suite.PricelistServiceMock
            .Setup(m => m.CreateDomainPricelist())
            .ReturnsAsync(domainPricelist);

            var result = await Suite.CityService.CreateDomainCity(domain, address);

            Suite.DomainCityServiceMock
            .Verify(m => m.Create(domain, domainAddress.Id, domainPricelist.Id));
        }
コード例 #3
0
        private static async Task InitOrganizations()
        {
            var rybinskDomain  = "rybinsk";
            var rybinskAddress = new AddressAM {
                Country = "Россия", Province = "Ярославская", Area = "Рыбинский район", Locality = "Рыбинск", Latitude = 58.0610321, Longitude = 38.7416854
            };
            var rybinskGaragesAddresses = new List <AddressAM>
            {
                new AddressAM {
                    Country = "Россия", Province = "Ярославская", Area = "Рыбинский район", Locality = "Рыбинск", District = "Центральный", Street = "Пр. Серова", House = "1", Latitude = 58.0569028, Longitude = 38.780219
                },
                new AddressAM {
                    Country = "Россия", Province = "Ярославская", Area = "Рыбинский район", Locality = "Рыбинск", District = "Заволжский", Street = "Большая Вольская", House = "55", Latitude = 58.0681517, Longitude = 38.8615214
                }
            };

            await CreateCityInfrastructure(rybinskDomain, rybinskAddress, rybinskGaragesAddresses);

            var vologdaDomain  = "vologda";
            var vologdaAddress = new AddressAM {
                Country = "Россия", Province = "Вологодская", Locality = "Вологда", Latitude = 59.2221979, Longitude = 39.8057537
            };
            var vologdaGaragesAddresses = new List <AddressAM>
            {
                new AddressAM {
                    Country = "Россия", Province = "Вологодская", Locality = "Вологда", District = "Центральный", Street = "Благовещенская", House = "20", Latitude = 59.2224107, Longitude = 39.8715978
                }
            };

            await CreateCityInfrastructure(vologdaDomain, vologdaAddress, vologdaGaragesAddresses);

            var cherepovecDomain  = "cherepovec";
            var cherepovecAddress = new AddressAM {
                Country = "Россия", Province = "Вологодская", Locality = "Череповец", Latitude = 59.1291174, Longitude = 37.7098701
            };
            var cherepovecGaragesAddresses = new List <AddressAM>
            {
                new AddressAM {
                    Country = "Россия", Province = "Вологодская", Locality = "Череповец", District = "Центральный", Street = "Сталеваров", House = "78", Latitude = 59.1367202, Longitude = 37.9103716
                }
            };

            await CreateCityInfrastructure(cherepovecDomain, cherepovecAddress, cherepovecGaragesAddresses);

            var yaroslavlDomain  = "yaroslavl";
            var yaroslavlAddress = new AddressAM {
                Country = "Россия", Province = "Ярославская", Locality = "Ярославль", Latitude = 57.6525644, Longitude = 39.724092
            };
            var yaroslavlGaragesAddresses = new List <AddressAM>
            {
                new AddressAM {
                    Country = "Россия", Province = "Ярославская", Locality = "Ярославль", District = "Ленинский", Street = "Радищева", House = "24", Latitude = 57.6379029, Longitude = 39.840627
                },
            };

            await CreateCityInfrastructure(yaroslavlDomain, yaroslavlAddress, yaroslavlGaragesAddresses);
        }
コード例 #4
0
        public static Coordinate ToCoordinate(this AddressAM address)
        {
            var result = new Coordinate
            {
                Latitude  = address.Latitude,
                Longitude = address.Longitude,
            };

            return(result);
        }
コード例 #5
0
        public async Task <RouteAM> GetRoute(AddressAM rootAddress, WaypointsAM waypoints)
        {
            var rootCoordinate      = rootAddress.ToCoordinate();
            var waypointsCoordinate = waypoints.Points.Select(p => p.ToCoordinate());
            var externalRoute       = await DirectionService.GetRoute(rootCoordinate, rootCoordinate, waypointsCoordinate);

            var result = await FromExternalRoute(rootAddress, rootAddress, waypoints, externalRoute);

            return(result);
        }
コード例 #6
0
        public async Task <Address> GetOrCreateDomainAddress(AddressAM address)
        {
            var result = await DomainAddressService.GetByCoordinate(address.Latitude, address.Longitude);

            if (result == null)
            {
                result = await CreateDomainAddress(AddressKind.Other, address);
            }

            return(result);
        }
コード例 #7
0
        public async Task <AddressAM> GetAddress(int addressId)
        {
            AddressAM result = null;

            var domainAddress = await GetDomainAddress(addressId);

            if (domainAddress != null)
            {
                result = FromDomainAddress(domainAddress);
            }

            return(result);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        private static async Task CreateCityInfrastructure(
            string cityDomain,
            AddressAM cityAddress,
            List <AddressAM> garagesAddresses)
        {
            if (!await CityService.IsExistByDomain(cityDomain))
            {
                var domainCity = await CityService.CreateDomainCity(cityDomain, cityAddress);

                foreach (var garageAddress in garagesAddresses)
                {
                    await GarageService.CreateDomainGarage(domainCity.Id, garageAddress);
                }
            }
        }
コード例 #10
0
        public async Task CreateDomainGarage()
        {
            var commonId    = 1;
            var cityId      = commonId++;
            var pricelistId = commonId++;

            var address = new AddressAM
            {
                Country   = "Россия",
                Province  = "Московская область",
                Area      = "Москва",
                Locality  = "Москва",
                District  = "Северо-Восточный район",
                Latitude  = 55.771899,
                Longitude = 37.597576,
            };

            var domainAddress = new Address
            {
                Id        = commonId++,
                Country   = "Россия",
                Province  = "Московская область",
                Area      = "Москва",
                Locality  = "Москва",
                District  = "Северо-Восточный район",
                Latitude  = 55.771899,
                Longitude = 37.597576,
            };

            var domainCity = new City
            {
                Id          = cityId,
                PricelistId = pricelistId
            };

            Suite.CityServiceMock
            .Setup(m => m.GetDomainCity(cityId))
            .ReturnsAsync(domainCity);
            Suite.AddressServiceMock
            .Setup(m => m.CreateDomainAddress(AddressKind.Garage, address))
            .ReturnsAsync(domainAddress);

            await Suite.GarageService.CreateDomainGarage(cityId, address);

            Suite.DomainGarageServiceMock
            .Verify(m => m.Create(cityId, domainAddress.Id, domainCity.PricelistId));
        }
コード例 #11
0
 public Task <Address> CreateDomainAddress(AddressKind kind, AddressAM address)
 {
     return(DomainAddressService.Create(
                kind,
                address.Request,
                address.Country,
                address.Province,
                address.Area,
                address.Locality,
                address.District,
                address.Street,
                address.House,
                address.Latitude,
                address.Longitude,
                address.AdjustedLatitude,
                address.AdjustedLongitude));
 }
コード例 #12
0
        public async Task GetDomainAddressByApplicationAddressWhenDomainAddressDoesNotExist()
        {
            var ApplicationAddress = new AddressAM
            {
                Country           = "Россия",
                Province          = "Московская область",
                Area              = "Москва",
                Locality          = "Москва",
                District          = "Северо-Восточный район",
                Street            = "4-я Тверская-Ямская улица",
                House             = "7",
                Latitude          = 55.771899,
                Longitude         = 37.597576,
                AdjustedLatitude  = 55.771800,
                AdjustedLongitude = 37.597500,
                FormattedText     = "Россия, Москва, 4-я Тверская-Ямская улица, 7",
                Request           = "Москва 4-я Тверская улица 7"
            };

            Suite.DomainAddressServiceMock
            .Setup(m => m.GetByCoordinate(ApplicationAddress.Latitude, ApplicationAddress.Longitude))
            .Returns(Task.FromResult <Address>(null));

            await Suite.AddressService.GetOrCreateDomainAddress(ApplicationAddress);

            Suite.DomainAddressServiceMock
            .Verify(m => m.Create(
                        AddressKind.Other,
                        ApplicationAddress.Request,
                        ApplicationAddress.Country,
                        ApplicationAddress.Province,
                        ApplicationAddress.Area,
                        ApplicationAddress.Locality,
                        ApplicationAddress.District,
                        ApplicationAddress.Street,
                        ApplicationAddress.House,
                        ApplicationAddress.Latitude,
                        ApplicationAddress.Longitude,
                        ApplicationAddress.AdjustedLatitude,
                        ApplicationAddress.AdjustedLongitude));
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        public async Task <City> CreateDomainCity(string domain, AddressAM address)
        {
            using (var transaction = await TransactionService.BeginTransaction())
            {
                try
                {
                    var domainAddress = await AddressService.CreateDomainAddress(AddressKind.City, address);

                    var domainPricelist = await PricelistService.CreateDomainPricelist();

                    var domainCity = await DomainCityService.Create(domain, domainAddress.Id, domainPricelist.Id);

                    transaction.Commit();
                    return(domainCity);
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
コード例 #15
0
        public async Task GetDomainAddressByApplicationAddressWhenDomainAddressExist()
        {
            var ApplicationAddress = new AddressAM
            {
                Latitude  = 55.771899,
                Longitude = 37.597576
            };

            var domainAddress = new Address
            {
                Latitude  = ApplicationAddress.Latitude,
                Longitude = ApplicationAddress.Longitude
            };

            Suite.DomainAddressServiceMock
            .Setup(m => m.GetByCoordinate(ApplicationAddress.Latitude, ApplicationAddress.Longitude))
            .ReturnsAsync(domainAddress);

            var result = await Suite.AddressService.GetOrCreateDomainAddress(ApplicationAddress);

            Suite.DomainAddressServiceMock
            .Verify(m => m.Create(
                        It.IsAny <AddressKind>(),
                        It.IsAny <string>(),
                        It.IsAny <string>(),
                        It.IsAny <string>(),
                        It.IsAny <string>(),
                        It.IsAny <string>(),
                        It.IsAny <string>(),
                        It.IsAny <string>(),
                        It.IsAny <string>(),
                        It.IsAny <double>(),
                        It.IsAny <double>(),
                        It.IsAny <double>(),
                        It.IsAny <double>())
                    , Times.Never);
        }
コード例 #16
0
        public async Task SignUpDispatcherDriver()
        {
            var ApplicationDispatcher = new DispatcherAM
            {
                IdentityUserId = 6,
                FirstName      = "Петя",
                LastName       = "Лиссерман"
            };

            var garageAddress = new AddressAM
            {
                Country  = "Россия",
                Province = "Ярославская",
                Locality = "Рыбинск",
                District = "Центральный"
            };

            var dispatcherCompanyModel = new DispatcherCompanyAM
            {
                GarageAddress = garageAddress,
                CompanyName   = "Транспортные Системы",
                Dispatcher    = ApplicationDispatcher
            };

            var domainCompany = new Company {
                Id = 1
            };
            var domainDispatcher = new Dispatcher {
                Id = 3
            };
            var domainGarage = new Garage {
                Id = 4
            };

            Suite.DomainGarageServiceMock
            .Setup(m => m.GetByAddress(garageAddress.Country, garageAddress.Province, garageAddress.Locality, garageAddress.District))
            .ReturnsAsync(domainGarage);

            Suite.DomainCompanyServiceMock
            .Setup(m => m.Create(domainGarage.Id, dispatcherCompanyModel.CompanyName))
            .ReturnsAsync(domainCompany);

            Suite.DomainDispatcherServiceMock
            .Setup(m => m.Create(ApplicationDispatcher.FirstName, ApplicationDispatcher.LastName, ApplicationDispatcher.PhoneNumber, domainCompany.Id))
            .ReturnsAsync(domainDispatcher);

            Suite.TransactionServiceMock
            .Setup(m => m.BeginTransaction())
            .ReturnsAsync(Suite.TransactionMock.Object);

            await Suite.SignUpService.SignUpDispatcherCompany(dispatcherCompanyModel);

            Suite.DomainGarageServiceMock
            .Verify(m => m.GetByAddress(garageAddress.Country, garageAddress.Province, garageAddress.Locality, garageAddress.District), Times.Once);

            Suite.DomainCompanyServiceMock
            .Verify(m => m.Create(domainGarage.Id, dispatcherCompanyModel.CompanyName), Times.Once);

            Suite.DomainDispatcherServiceMock
            .Verify(m => m.Create(ApplicationDispatcher.FirstName, ApplicationDispatcher.LastName, ApplicationDispatcher.PhoneNumber, domainCompany.Id), Times.Once);

            Suite.TransactionMock
            .Verify(m => m.Commit(), Times.Once);

            Suite.TransactionMock
            .Verify(m => m.Rollback(), Times.Never);
        }
コード例 #17
0
        public async Task FromExternalRoute()
        {
            var rootAddress = new AddressAM
            {
                Latitude  = 55.55555,
                Longitude = 66.66666
            };

            var firstWaypointAddress = new AddressAM
            {
                Latitude  = 11.11111,
                Longitude = 22.22222
            };

            var secondWaypointAddress = new AddressAM
            {
                Latitude  = 33.33333,
                Longitude = 44.44444
            };

            var waypoints = new WaypointsAM
            {
                Points = new List <AddressAM>
                {
                    firstWaypointAddress,
                    secondWaypointAddress
                },
                Comment = "Машина на охраняемой парковке. Пароль:\"Нраииттьься\""
            };

            var rootCoordinate = new Coordinate {
                Latitude = 55.55000, Longitude = 66.66000
            };
            var firstWaypointCoordinate = new Coordinate {
                Latitude = 11.11000, Longitude = 22.22000
            };
            var secondWaypointCoordinate = new Coordinate {
                Latitude = 33.33000, Longitude = 44.44000
            };

            var externalRoute = new RouteEM
            {
                Status = External.Models.Enums.Status.Ok,
                Legs   = new List <LegEM>
                {
                    new LegEM
                    {
                        StartCoordinate = rootCoordinate,
                        EndCoordinate   = firstWaypointCoordinate,
                        Distance        = 3000,
                        Duration        = 1600
                    },
                    new LegEM
                    {
                        StartCoordinate = firstWaypointCoordinate,
                        EndCoordinate   = secondWaypointCoordinate,
                        Distance        = 35000,
                        Duration        = 18000
                    },
                    new LegEM
                    {
                        StartCoordinate = secondWaypointCoordinate,
                        EndCoordinate   = rootCoordinate,
                        Distance        = 38000,
                        Duration        = 19600
                    }
                }
            };

            Suite.AddressServiceMock
            .Setup(m => m.GetNearestAddress(rootCoordinate, It.IsAny <IEnumerable <AddressAM> >()))
            .ReturnsAsync(rootAddress);
            Suite.AddressServiceMock
            .Setup(m => m.GetNearestAddress(firstWaypointCoordinate, It.IsAny <IEnumerable <AddressAM> >()))
            .ReturnsAsync(firstWaypointAddress);
            Suite.AddressServiceMock
            .Setup(m => m.GetNearestAddress(secondWaypointCoordinate, It.IsAny <IEnumerable <AddressAM> >()))
            .ReturnsAsync(secondWaypointAddress);

            var result = await Suite.RouteService.FromExternalRoute(rootAddress, rootAddress, waypoints, externalRoute);

            Assert.Equal(3, result.Legs.Count);

            // Check feeding leg
            Assert.Equal(rootAddress, result.Legs[0].StartAddress);
            Assert.Equal(firstWaypointAddress, result.Legs[0].EndAddress);
            Assert.Equal(externalRoute.Legs[0].Distance, result.Legs[0].Distance);
            Assert.Equal(externalRoute.Legs[0].Duration, result.Legs[0].Duration);
            Assert.Equal(RouteLegKind.Feed, result.Legs[0].Kind);

            // Check transportation leg
            Assert.Equal(firstWaypointAddress, result.Legs[1].StartAddress);
            Assert.Equal(secondWaypointAddress, result.Legs[1].EndAddress);
            Assert.Equal(externalRoute.Legs[1].Distance, result.Legs[1].Distance);
            Assert.Equal(externalRoute.Legs[1].Duration, result.Legs[1].Duration);
            Assert.Equal(RouteLegKind.Transportation, result.Legs[1].Kind);

            // Check wayBacking leg
            Assert.Equal(secondWaypointAddress, result.Legs[2].StartAddress);
            Assert.Equal(rootAddress, result.Legs[2].EndAddress);
            Assert.Equal(externalRoute.Legs[2].Distance, result.Legs[2].Distance);
            Assert.Equal(externalRoute.Legs[2].Duration, result.Legs[2].Duration);
            Assert.Equal(RouteLegKind.WayBack, result.Legs[2].Kind);

            Assert.Equal(rootCoordinate.Latitude, result.Legs[0].StartAddress.AdjustedLatitude);
            Assert.Equal(rootCoordinate.Longitude, result.Legs[0].StartAddress.AdjustedLongitude);

            Assert.Equal(firstWaypointCoordinate.Latitude, result.Legs[1].StartAddress.AdjustedLatitude);
            Assert.Equal(firstWaypointCoordinate.Longitude, result.Legs[1].StartAddress.AdjustedLongitude);

            Assert.Equal(secondWaypointCoordinate.Latitude, result.Legs[2].StartAddress.AdjustedLatitude);
            Assert.Equal(secondWaypointCoordinate.Longitude, result.Legs[2].StartAddress.AdjustedLongitude);
        }
コード例 #18
0
        public AddressAM FromExternalAddress(AddressEM source)
        {
            var destination = new AddressAM();

            return(MappingService.Map(source, destination));
        }
コード例 #19
0
        public AddressAM FromDomainAddress(Address source)
        {
            var destination = new AddressAM();

            return(MappingService.Map(source, destination));
        }
コード例 #20
0
        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));
        }
コード例 #21
0
        public async void SignUpDriverCompany()
        {
            var ApplicationVehicle = new VehicleAM
            {
                RegistrationNumber    = "К100ЕЕ77",
                BrandCatalogItemId    = 0,
                CapacityCatalogItemId = 1,
                KindCatalogItemId     = 2
            };

            var ApplicationDriver = new DriverAM
            {
                IdentityUserId = 6,
                FirstName      = "Петя",
                LastName       = "Лиссерман"
            };

            var garageAddress = new AddressAM
            {
                Country  = "Россия",
                Province = "Ярославская",
                Locality = "Рыбинск",
                District = "Центральный"
            };

            var driverCompanyModel = new DriverCompanyAM
            {
                GarageAddress = garageAddress,
                CompanyName   = "Транспортные Системы",
                Vehicle       = ApplicationVehicle,
                Driver        = ApplicationDriver
            };

            var domainCompany = new Company {
                Id = 1
            };
            var domainVehicle = new Vehicle {
                Id = 2
            };
            var domainDriver = new Driver {
                Id = 3
            };
            var domainGarage = new Garage {
                Id = 4
            };

            Suite.DomainGarageServiceMock
            .Setup(m => m.GetByAddress(garageAddress.Country, garageAddress.Province, garageAddress.Locality, garageAddress.District))
            .ReturnsAsync(domainGarage);

            Suite.DomainCompanyServiceMock
            .Setup(m => m.Create(domainGarage.Id, driverCompanyModel.CompanyName))
            .ReturnsAsync(domainCompany);

            Suite.VehicleServiceMock
            .Setup(m => m.CreateDomainVehicle(domainCompany.Id, ApplicationVehicle))
            .ReturnsAsync(domainVehicle);

            Suite.DomainDriverServiceMock
            .Setup(m => m.Create(ApplicationDriver.FirstName, ApplicationDriver.LastName, ApplicationDriver.PhoneNumber, domainCompany.Id))
            .ReturnsAsync(domainDriver);

            Suite.TransactionServiceMock
            .Setup(m => m.BeginTransaction())
            .ReturnsAsync(Suite.TransactionMock.Object);

            await Suite.SignUpService.SignUpDriverCompany(driverCompanyModel);

            Suite.DomainGarageServiceMock
            .Verify(m => m.GetByAddress(garageAddress.Country, garageAddress.Province, garageAddress.Locality, garageAddress.District), Times.Once);

            Suite.DomainCompanyServiceMock
            .Verify(m => m.Create(domainGarage.Id, driverCompanyModel.CompanyName), Times.Once);

            Suite.VehicleServiceMock
            .Verify(m => m.CreateDomainVehicle(
                        domainCompany.Id,
                        It.Is <VehicleAM>(v => v == ApplicationVehicle)), Times.Once);

            Suite.DomainDispatcherServiceMock
            .Verify(m => m.Create(ApplicationDriver.FirstName, ApplicationDriver.LastName, ApplicationDriver.PhoneNumber, domainCompany.Id), Times.Once);

            Suite.DomainDriverServiceMock
            .Verify(m => m.Create(ApplicationDriver.FirstName, ApplicationDriver.LastName, ApplicationDriver.PhoneNumber, domainCompany.Id), Times.Once);

            Suite.DomainDriverServiceMock
            .Verify(m => m.AssignVehicle(domainDriver.Id, domainVehicle.Id), Times.Once);

            Suite.TransactionMock
            .Verify(m => m.Commit(), Times.Once);

            Suite.TransactionMock
            .Verify(m => m.Rollback(), Times.Never);
        }
コード例 #22
0
        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);
        }