コード例 #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);
        }
コード例 #2
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());
        }
コード例 #3
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);
        }
コード例 #4
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());
        }
コード例 #5
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());
        }
コード例 #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());
        }