示例#1
0
        public void GetDeliveryInfoToGet()
        {
            Delivery delivery = ServicesTestConstant.getDelivery();

            delivery.Bill      = ServicesTestConstant.getBill();
            delivery.Bill.User = ServicesTestConstant.getAddreser();
            DeliveryInfoToGetDto deliveryInfoToGetDto = ServicesTestConstant.getDeliveryInfoToGetDto();

            deliveryInfoToGetDto.LocalityGetName  = delivery.Way.LocalityGet.NameEn;
            deliveryInfoToGetDto.LocalitySandName = delivery.Way.LocalitySand.NameEn;

            _deliveryRepository.Setup(s => s.FindAllByAddressee_IdAndIsPackageReceivedFalseAndBill_IsDeliveryPaidTrue(
                                          ServicesTestConstant.getUserId())).Returns(new List <Delivery> {
                delivery
            });

            List <DeliveryInfoToGetDto> result = _deliveryService.GetDeliveryInfoToGet(ServicesTestConstant.getUserId());

            _deliveryRepository.Verify(
                place =>
                place.FindAllByAddressee_IdAndIsPackageReceivedFalseAndBill_IsDeliveryPaidTrue(It.IsAny <string>()),
                Times.Once());

            Assert.AreEqual(deliveryInfoToGetDto, result[0]);
            Assert.AreEqual(ServicesTestConstant.getDeliveres().Count, result.Count);
        }
示例#2
0
        public void getDeliveryCostAndTimeDtoAllCorrect()
        {
            DeliveryInfoRequestModel    deliveryInfoRequestDto    = getDeliveryInfoRequestDto(1);
            PriceAndTimeOnDeliveryModel priceAndTimeOnDeliveryDto = getPriceAndTimeOnDeliveryDto();
            Delivery delivery = ServicesTestConstant.getDelivery();
            Way      way      = delivery.Way;

            _wayRepository.Setup(s => s.FindByLocalitySand_IdAndLocalityGet_Id
                                     (It.IsAny <long>(), It.IsAny <long>())).Returns(way);

            PriceAndTimeOnDeliveryModel result = _deliveryService.GetDeliveryCostAndTimeDto(deliveryInfoRequestDto);

            _wayRepository.Verify(
                s => s.FindByLocalitySand_IdAndLocalityGet_Id
                    (It.IsAny <long>(), It.IsAny <long>()), Times.Once());
            Assert.AreEqual(priceAndTimeOnDeliveryDto, result);
        }
示例#3
0
        public void getDeliveryCostAndTimeIncorrectWeightFactorBiggerOnOne()
        {
            int weightRangeMax  = 2;
            int weightRangeReal = 2;
            DeliveryInfoRequestModel deliveryInfoRequestDto = getDeliveryInfoRequestDto(weightRangeReal);
            Delivery delivery = ServicesTestConstant.getDelivery();
            Way      way      = delivery.Way;

            way.WayToTariffWeightFactors[0].TariffWeightFactor.MaxWeightRange = weightRangeMax;
            _wayRepository.Setup(s => s.FindByLocalitySand_IdAndLocalityGet_Id
                                     (It.IsAny <long>(), It.IsAny <long>())).Returns(way);

            var actualResult =
                Assert.Throws <UnsupportableWeightFactorException>(() =>
                                                                   _deliveryService.GetDeliveryCostAndTimeDto(deliveryInfoRequestDto));

            Assert.AreEqual(typeof(UnsupportableWeightFactorException), actualResult.GetType());
        }
示例#4
0
        public void initializeBillCorrectInCorrectAddressee()
        {
            Bill bill = ServicesTestConstant.getBill();

            bill.CostInCents    = _defaultCostInCents;
            bill.BillId         = _defaultBillId;
            bill.IsDeliveryPaid = false;
            Delivery delivery = ServicesTestConstant.getDelivery();

            delivery.DeliveryId = _defaultDeliveryId;
            _userRepository.Setup(a => a.FindByEmail(It.IsAny <string>())
                                  ).Returns(null as User);

            var actualResult =
                Assert.Throws <NoSuchUserException>(() => _billService.InitializeBill
                                                        (ServicesTestConstant.getDeliveryOrderCreateDto(), ServicesTestConstant.getUserId()));

            Assert.AreEqual(typeof(NoSuchUserException), actualResult.GetType());
        }
示例#5
0
        public void initializeBillCorrect()
        {
            Bill bill = ServicesTestConstant.getBill();

            bill.CostInCents    = _defaultCostInCents;
            bill.BillId         = _defaultBillId;
            bill.IsDeliveryPaid = false;
            Delivery delivery = ServicesTestConstant.getDelivery();

            delivery.DeliveryId = _defaultDeliveryId;
            _wayRepository.Setup(a => a.FindByLocalitySand_IdAndLocalityGet_Id
                                     (It.IsAny <long>(), It.IsAny <long>())
                                 ).Returns(ServicesTestConstant.getWay());

            Bill billResult = _billService.InitializeBill(ServicesTestConstant.getDeliveryOrderCreateDto(),
                                                          ServicesTestConstant.getUserId());

            Assert.AreEqual(bill, billResult);
        }
示例#6
0
        public void initializeBillIncorrectInWay()
        {
            Bill bill = ServicesTestConstant.getBill();

            bill.CostInCents    = _defaultCostInCents;
            bill.BillId         = _defaultBillId;
            bill.IsDeliveryPaid = false;
            Delivery delivery = ServicesTestConstant.getDelivery();

            delivery.DeliveryId = _defaultDeliveryId;

            _wayRepository.Setup(a => a.FindByLocalitySand_IdAndLocalityGet_Id
                                     (It.IsAny <long>(), It.IsAny <long>())
                                 ).Returns((Way)null);

            var actualResult =
                Assert.Throws <NoSuchWayException>(() => _billService.InitializeBill
                                                       (ServicesTestConstant.getDeliveryOrderCreateDto(), ServicesTestConstant.getUserId()));

            Assert.AreEqual(typeof(NoSuchWayException), actualResult.GetType());
        }
示例#7
0
        public void confirmGettingDeliveryAllCorrect()
        {
            Delivery delivery = ServicesTestConstant.getDelivery();

            _deliveryRepository.Setup(s => s.FindByIdAndAddressee_IdAndIsPackageReceivedFalse(
                                          ServicesTestConstant.getUserId(), ServicesTestConstant.getDeliveryId()))
            .Returns(delivery);

            bool result = _deliveryService.ConfirmGettingDelivery(ServicesTestConstant.getUserId(),
                                                                  ServicesTestConstant.getDeliveryId());

            _deliveryRepository.Verify(
                place =>
                place.FindByIdAndAddressee_IdAndIsPackageReceivedFalse
                    (It.IsAny <string>(), It.IsAny <long>()), Times.Once());
            _deliveryRepository.Verify(
                place =>
                place.Save(),
                Times.Once());

            Assert.IsTrue(result);
            Assert.IsTrue(delivery.IsPackageReceived);
        }