Esempio n. 1
0
        public void SetupBeforeEachTest()
        {
            _billRepository     = new Mock <IBillRepository>();
            _userRepository     = new Mock <IUserRepository>();
            _deliveryRepository = new Mock <IDeliveryRepository>();
            _wayRepository      = new Mock <IWayRepository>();

            _billRepository.Setup(a => a.FindByIdAndIsDeliveryPaidFalse(ServicesTestConstant.getBillId()))
            .Returns(ServicesTestConstant.getBill());
            _billRepository.Setup(a => a.FindAllByUserIdAndIsDeliveryPaidFalse(It.IsAny <string>()))
            .Returns(ServicesTestConstant.getBills());

            _userRepository.Setup(a => a.FindByIdAndUserMoneyInCentsGreaterThanEqual
                                      (ServicesTestConstant.getUserId(), ServicesTestConstant.getBill().CostInCents)
                                  ).Returns(ServicesTestConstant.getAddreser());

            _userRepository.Setup(a => a.FindByEmail(It.IsAny <string>())
                                  ).Returns(ServicesTestConstant.getAdversee());
            _userRepository.Setup(a => a.FindByName(It.IsAny <string>())
                                  ).Returns(ServicesTestConstant.getAdversee());

            _wayRepository.Setup(a => a.FindByLocalitySand_IdAndLocalityGet_Id
                                     (It.IsAny <long>(), It.IsAny <long>())
                                 ).Returns(ServicesTestConstant.getWay());
            _billService = new BillService
                               (_billRepository.Object, _userRepository.Object, _deliveryRepository.Object, _wayRepository.Object);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public void getBillsToPayByUserId()
        {
            BillInfoToPayModel billInfoToPayDto = ServicesTestConstant.getBillInfoToPayDto();
            Bill bill = ServicesTestConstant.getBill();

            billInfoToPayDto.LocalityGetName  = bill.Delivery.Way.LocalityGet.NameEn;
            billInfoToPayDto.LocalitySandName = bill.Delivery.Way.LocalitySand.NameEn;

            List <BillInfoToPayModel> result = _billService.GetBillsToPayByUserName(ServicesTestConstant.getUserId());

            _billRepository.Verify(place => place.FindAllByUserIdAndIsDeliveryPaidFalse
                                       (ServicesTestConstant.getUserId()), Times.Once());
            Assert.AreEqual(ServicesTestConstant.getBills().Count, result.Count);
            Assert.AreEqual(billInfoToPayDto, result[0]);
        }
Esempio n. 4
0
        public void payForDeliveryWhenAllCorrect()
        {
            Bill bill = ServicesTestConstant.getBill();

            bill.IsDeliveryPaid = false;
            _billRepository.Setup(a => a.FindByIdAndIsDeliveryPaidFalse(ServicesTestConstant.getBillId())).Returns(bill);

            bool payResult = _billService.PayForDelivery(ServicesTestConstant.getUserId(), ServicesTestConstant.getBillId());

            _billRepository.Verify
                (place => place.FindByIdAndIsDeliveryPaidFalse(ServicesTestConstant.getBillId()), Times.Once());
            _userRepository.Verify(place => place.FindByIdAndUserMoneyInCentsGreaterThanEqual
                                       (ServicesTestConstant.getUserId(), bill.CostInCents), Times.Once());

            Assert.IsTrue(payResult);
            Assert.IsTrue(bill.IsDeliveryPaid);
        }
Esempio n. 5
0
        public void payForDeliveryNotEnoughMoney()
        {
            Bill bill = ServicesTestConstant.getBill();

            bill.IsDeliveryPaid = false;
            User adverser = ServicesTestConstant.getAddreser();

            adverser.UserMoneyInCents = 0L;
            _userRepository.Setup(a => a.FindByIdAndUserMoneyInCentsGreaterThanEqual
                                      (ServicesTestConstant.getUserId(), ServicesTestConstant.getBill().CostInCents)
                                  ).Returns((User)null);

            var actualResult =
                Assert.Throws <NotEnoughMoneyException>
                    (() => _billService.PayForDelivery(ServicesTestConstant.getUserId(), ServicesTestConstant.getBillId()));

            Assert.AreEqual(typeof(NotEnoughMoneyException), actualResult.GetType());
        }
Esempio n. 6
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());
        }
Esempio n. 7
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);
        }
Esempio n. 8
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());
        }