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