Example #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);
        }
Example #2
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);
        }
Example #3
0
        public void payForDeliveryDeliveryAlreadyPaid()
        {
            Delivery setupDeliveryAndBill = EntitySetuper.SetupDeliveryAndBill(_context, false, true);

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

            Assert.AreEqual(typeof(DeliveryAlreadyPaidException), actualResult.GetType());
        }
Example #4
0
        public void payForDeliveryDeliveryAlreadyPaid()
        {
            _billRepository.Setup(a => a.FindByIdAndIsDeliveryPaidFalse(ServicesTestConstant.getBillId()))
            .Returns((Bill)null);

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

            Assert.AreEqual(typeof(DeliveryAlreadyPaidException), actualResult.GetType());
        }
Example #5
0
        public void confirmGettingDeliveryIsNoExistDelivery()
        {
            _deliveryRepository.Setup(s => s.FindByIdAndAddressee_IdAndIsPackageReceivedFalse(
                                          ServicesTestConstant.getUserId(), ServicesTestConstant.getDeliveryId()))
            .Returns((Delivery)null);
            var actualResult =
                Assert.Throws <AskedDataIsNotExist>(() => _deliveryService.ConfirmGettingDelivery(
                                                        ServicesTestConstant.getUserId(),
                                                        ServicesTestConstant.getDeliveryId()));

            Assert.AreEqual(typeof(AskedDataIsNotExist), actualResult.GetType());
        }
Example #6
0
        public void payForDeliveryNotEnoughMoney()
        {
            Delivery setupDeliveryAndBill = EntitySetuper.SetupDeliveryAndBill(_context, false, false);

            setupDeliveryAndBill.Bill.User.UserMoneyInCents = 0;
            _context.SaveChanges();

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

            Assert.AreEqual(typeof(NotEnoughMoneyException), actualResult.GetType());
        }
Example #7
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]);
        }
Example #8
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);
        }
Example #9
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());
        }
Example #10
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);
        }
Example #11
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);
        }
Example #12
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());
        }
Example #13
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());
        }
Example #14
0
        public void getBillsToPayByUserIdUserIsNotExist()
        {
            _billRepository.Setup(a => a.FindAllByUserIdAndIsDeliveryPaidFalse(It.IsAny <string>())).Returns(new List <Bill>());

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

            _billRepository.Verify(place => place.FindAllByUserIdAndIsDeliveryPaidFalse(It.IsAny <string>()), Times.Once());
            Assert.AreEqual(0, billInfoToPayDtos.Count);
        }
        public void replenishAccountBalanceToMuchMoneyException()
        {
            User user = new User(null, null, long.MaxValue);

            userRepository.Setup(s => s.FindByName(It.IsAny <string>()))
            .Returns(user);

            var actualResult =
                Assert.Throws <ToMuchMoneyException>(() =>
                                                     _userService.ReplenishAccountBalance(ServicesTestConstant.getUserId(), 10));

            Assert.AreEqual(typeof(ToMuchMoneyException), actualResult.GetType());
        }
        public void replenishAccountBalanceNoSuchUser()
        {
            userRepository.Setup(s => s.FindByName(It.IsAny <string>()))
            .Returns((User)null);

            var actualResult =
                Assert.Throws <NoSuchUserException>(() =>
                                                    _userService.ReplenishAccountBalance(ServicesTestConstant.getUserId(), 10));

            Assert.AreEqual(typeof(NoSuchUserException), actualResult.GetType());
        }