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); }
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()); }
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); }
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()); }
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()); }
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()); }