Exemplo n.º 1
0
        public PriceAndTimeOnDeliveryModel GetDeliveryCostAndTimeDto(DeliveryInfoRequestModel deliveryInfoRequestDto)
        {
            Way way = getWay(deliveryInfoRequestDto.LocalitySandId, deliveryInfoRequestDto.LocalityGetId);

            return(new PriceAndTimeOnDeliveryModel(calculateDeliveryCost(deliveryInfoRequestDto.DeliveryWeight, way),
                                                   way.TimeOnWayInDays));
        }
Exemplo n.º 2
0
        public void getDeliveryCostAndTimeDtoAllCorrect()
        {
            Way way = EntitySetuper.SetupWayWithTarif(_context);
            DeliveryInfoRequestModel deliveryInfoRequestDto =
                new DeliveryInfoRequestModel(10, way.LocalitySandLocalityId, way.LocalityGetLocalityId);
            PriceAndTimeOnDeliveryModel priceAndTimeOnDeliveryModel = new PriceAndTimeOnDeliveryModel(200, 2);

            PriceAndTimeOnDeliveryModel result = _deliveryService.GetDeliveryCostAndTimeDto(deliveryInfoRequestDto);

            Assert.AreEqual(priceAndTimeOnDeliveryModel, result);
        }
Exemplo n.º 3
0
        public void getDeliveryCostAndTimeIncorrectWay()
        {
            Way way = EntitySetuper.SetupWayWithTarif(_context);
            int notExistLocalitySend = 300;
            DeliveryInfoRequestModel deliveryInfoRequestDto =
                new DeliveryInfoRequestModel(10, notExistLocalitySend, way.LocalityGetLocalityId);

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

            Assert.AreEqual(typeof(NoSuchWayException), actualResult.GetType());
        }
Exemplo n.º 4
0
        public void getDeliveryCostAndTimeIncorrectWay()
        {
            DeliveryInfoRequestModel    deliveryInfoRequestDto    = getDeliveryInfoRequestDto(1);
            PriceAndTimeOnDeliveryModel priceAndTimeOnDeliveryDto = getPriceAndTimeOnDeliveryDto();

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

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

            Assert.AreEqual(typeof(NoSuchWayException), actualResult.GetType());
        }
Exemplo n.º 5
0
        public void getDeliveryCostAndTimeIncorrectWeightFactorBiggerOnOne()
        {
            Way way = EntitySetuper.SetupWayWithTarif(_context);
            int weightBigerOnOneOfMaximumTarifWeightFactor =
                EntitySetuper.MAX_WRIGHT_ON_SETUPED_TARIF_WEIGHT_FACTOR + 1;
            DeliveryInfoRequestModel deliveryInfoRequestDto =
                new DeliveryInfoRequestModel(weightBigerOnOneOfMaximumTarifWeightFactor, way.LocalitySandLocalityId,
                                             way.LocalityGetLocalityId);

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

            Assert.AreEqual(typeof(UnsupportableWeightFactorException), actualResult.GetType());
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 public IActionResult HomeCount(DeliveryInfoRequestModel deliveryInfoRequestDto)
 {
     try
     {
         ViewData.Add("localities", _localityService.GetLocalities());
         ViewData.Add("priceAndTimeOnDeliveryModel",
                      _deliveryService.GetDeliveryCostAndTimeDto(deliveryInfoRequestDto));
     }
     catch (NoSuchWayException e)
     {
         ViewData.Add("noSuchWayException", true);
     }
     catch (UnsupportableWeightFactorException e)
     {
         ViewData.Add("unsupportableWeightFactorException", true);
     }
     return(View("Home"));
 }
Exemplo n.º 8
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());
        }