public Bill InitializeBill(DeliveryOrderCreateModel deliveryOrderCreateDto, string initiatorName)
        {
            User addressee = _userRepository.FindByEmail(deliveryOrderCreateDto.AddresseeEmail);

            if (addressee == null)
            {
                throw new NoSuchUserException();
            }
            Way way = _wayRepository.FindByLocalitySand_IdAndLocalityGet_Id(deliveryOrderCreateDto.LocalitySandId
                                                                            , deliveryOrderCreateDto.LocalityGetId);

            if (way == null)
            {
                throw new NoSuchWayException();
            }
            Delivery newDelivery = getBuildDelivery(deliveryOrderCreateDto, addressee, way);

            _deliveryRepository.Create(newDelivery);
            User user = _userRepository.FindByName(initiatorName);

            if (user == null)
            {
                throw new NoSuchUserException();
            }
            Bill buildBill = getBuildBill(newDelivery
                                          , calculateDeliveryCost(deliveryOrderCreateDto.DeliveryWeight, way)
                                          , user);

            _billRepository.Create(
                buildBill);
            _billRepository.Save();
            return(buildBill);
        }
        private Delivery getBuildDelivery(DeliveryOrderCreateModel deliveryOrderCreateDto, User addressee, Way way)
        {
            Delivery delivery = new Delivery();

            delivery.Addressee       = addressee;
            delivery.AddresseeUserId = addressee.Id;
            delivery.Way             = way;
            delivery.WayId           = way.WayId;
            delivery.Weight          = deliveryOrderCreateDto.DeliveryWeight;
            return(delivery);
        }
Beispiel #3
0
        public void initializeBillIncorrectInWay()
        {
            EntitySetuper.SetupWayWithTarif(_context);

            User setupAdresee            = EntitySetuper.SetupAdresee(_context);
            User setupAdreser            = EntitySetuper.SetupAdreser(_context);
            int  incorrectLocalitySandId = 1000;
            int  incorrectLocalityGetId  = 100;
            DeliveryOrderCreateModel deliveryOrderCreateModel = new DeliveryOrderCreateModel(10,
                                                                                             incorrectLocalitySandId, incorrectLocalityGetId, setupAdresee.Email);

            var actualResult =
                Assert.Throws <NoSuchWayException>(() => _billService.InitializeBill(deliveryOrderCreateModel,
                                                                                     setupAdreser.UserName));

            Assert.AreEqual(typeof(NoSuchWayException), actualResult.GetType());
        }
Beispiel #4
0
        public void initializeBillCorrectInCorrectAddressee()
        {
            Way    setupWayWithTarif     = EntitySetuper.SetupWayWithTarif(_context);
            String incorrectAdreseeEmail = "incorrectAdreseeEmail";

            EntitySetuper.SetupAdresee(_context);
            User setupAdreser = EntitySetuper.SetupAdreser(_context);
            DeliveryOrderCreateModel deliveryOrderCreateModel = new DeliveryOrderCreateModel(10,
                                                                                             setupWayWithTarif.LocalitySandLocalityId, setupWayWithTarif.LocalityGetLocalityId,
                                                                                             incorrectAdreseeEmail);

            var actualResult =
                Assert.Throws <NoSuchUserException>(() => _billService.InitializeBill(deliveryOrderCreateModel,
                                                                                      setupAdreser.UserName)
                                                    );

            Assert.AreEqual(typeof(NoSuchUserException), actualResult.GetType());
        }
Beispiel #5
0
        public void initializeBillCorrect()
        {
            Way  setupWayWithTarif = EntitySetuper.SetupWayWithTarif(_context);
            User setupAdresee      = EntitySetuper.SetupAdresee(_context);
            User setupAdreser      = EntitySetuper.SetupAdreser(_context);
            DeliveryOrderCreateModel deliveryOrderCreateModel = new DeliveryOrderCreateModel(10,
                                                                                             setupWayWithTarif.LocalitySandLocalityId, setupWayWithTarif.LocalityGetLocalityId, setupAdresee.Email);
            int expectedCost = 200;


            Bill billResult = _billService.InitializeBill(deliveryOrderCreateModel,
                                                          setupAdreser.UserName);

            Assert.AreEqual(setupAdreser.Id, billResult.User.Id);
            Assert.False(billResult.IsDeliveryPaid);
            Assert.False(billResult.Delivery.IsPackageReceived);
            Assert.AreEqual(expectedCost, billResult.CostInCents);
        }
 public IActionResult userDeliveryInitiationPost(DeliveryOrderCreateModel deliveryOrderCreateDto)
 {
     ViewData.Add("localities", _localityService.GetLocalities());
     try
     {
         _billService.InitializeBill(deliveryOrderCreateDto, User.Identity.Name);
     }
     catch (NoSuchWayException e)
     {
         ViewData.Add("noSuchWayException", true);
     }
     catch (UnsupportableWeightFactorException e)
     {
         ViewData.Add("unsupportableWeightFactorException", true);
     }
     catch (NoSuchUserException e)
     {
         ViewData.Add("noSuchUserException", true);
     }
     return(View("userDeliveryInitiation"));
 }