public async Task <IActionResult> SignUpDriverCompany([FromBody] DriverCompanyAM driverCompanyModel) { var identityUserId = GetIdentityUserId(); if (identityUserId == -1) { var problem = new ValidationProblemDetails { Title = $"identity user id can't be parsed from claims", Detail = $"identity user id can't be parsed from claims", Status = 400 }; return(base.ValidationProblem(problem)); } var phoneNumber = GetIdentityUserPhoneNumber(); driverCompanyModel.Driver.IdentityUserId = identityUserId; driverCompanyModel.Driver.PhoneNumber = phoneNumber; await SignUpService.SignUpDriverCompany(driverCompanyModel); return(Ok()); }
public async Task SignUpDriverCompany(DriverCompanyAM driverCompanyModel) { using (var transaction = await TransactionService.BeginTransaction()) { try { var domainGarage = await DomainGarageService.GetByAddress( driverCompanyModel.GarageAddress.Country, driverCompanyModel.GarageAddress.Province, driverCompanyModel.GarageAddress.Locality, driverCompanyModel.GarageAddress.District ); var domainCompany = await DomainCompanyService.Create( domainGarage.Id, driverCompanyModel.CompanyName); var domainVehicle = await VehicleService.CreateDomainVehicle( domainCompany.Id, driverCompanyModel.Vehicle); var domainDispatcher = await DomainDispatcherService.Create( driverCompanyModel.Driver.FirstName, driverCompanyModel.Driver.LastName, driverCompanyModel.Driver.PhoneNumber, domainCompany.Id ); var domainDriver = await DomainDriverService.Create( driverCompanyModel.Driver.FirstName, driverCompanyModel.Driver.LastName, driverCompanyModel.Driver.PhoneNumber, domainCompany.Id ); await DomainDriverService.AssignVehicle(domainDriver.Id, domainVehicle.Id); transaction.Commit(); } catch { transaction.Rollback(); throw; } } }
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); }