public static Delivery SetupDeliveryAndBill(MockDbContext _context, bool isDeliveryRecived, bool isDeliveryPayed)
        {
            Way  way       = SetupWayWithTarif(_context);
            User addressee = SetupAdresee(_context);
            User addresser = SetupAdreser(_context);

            Delivery delivery = new Delivery();

            delivery.Addressee         = addressee;
            delivery.AddresseeUserId   = addressee.Id;
            delivery.Way               = way;
            delivery.WayId             = way.WayId;
            delivery.IsPackageReceived = isDeliveryRecived;
            delivery.Weight            = 11;
            _context.Add(delivery);
            _context.SaveChanges();
            Bill bill = new Bill();

            bill.DeliveryId     = delivery.DeliveryId;
            bill.UserId         = addresser.Id;
            bill.Delivery       = delivery;
            bill.User           = addresser;
            bill.IsDeliveryPaid = isDeliveryPayed;
            bill.CostInCents    = BILL_COST;
            bill.DateOfPay      = DateTime.Today;
            _context.Add(bill);
            _context.SaveChanges();

            return(delivery);
        }
        public static Way SetupWayWithTarif(MockDbContext _context)
        {
            Locality send = new Locality();

            send.NameEn = "localitySend";
            _context.Add(send);
            _context.SaveChanges();
            Locality gett = new Locality();

            gett.NameEn = "localityGet";
            _context.Add(gett);
            _context.SaveChanges();
            Way way = new Way(send.LocalityId, send, gett.LocalityId, gett, 10, 2, 10);

            _context.Add(way);
            _context.SaveChanges();
            TariffWeightFactor tariffWeightFactor = new TariffWeightFactor();

            tariffWeightFactor.MaxWeightRange     = MAX_WRIGHT_ON_SETUPED_TARIF_WEIGHT_FACTOR;
            tariffWeightFactor.MinWeightRange     = 0;
            tariffWeightFactor.OverPayOnKilometer = 10;
            _context.Add(tariffWeightFactor);
            _context.SaveChanges();
            WayToTariffWeightFactor wayToTariffWeightFactor = new WayToTariffWeightFactor();

            wayToTariffWeightFactor.WayId = way.WayId;
            wayToTariffWeightFactor.Way   = way;
            wayToTariffWeightFactor.TariffWeightFactorId = tariffWeightFactor.TariffWeightFactorId;
            wayToTariffWeightFactor.TariffWeightFactor   = tariffWeightFactor;
            _context.Add(wayToTariffWeightFactor);
            _context.SaveChanges();
            return(way);
        }
        public static User SetupAdreser(MockDbContext _context)
        {
            User addresser = new User();

            addresser.UserName         = "******";
            addresser.Email            = "*****@*****.**";
            addresser.Password         = "******";
            addresser.UserMoneyInCents = 8000000000;
            _context.Add(addresser);
            _context.SaveChanges();
            return(addresser);
        }
Exemple #4
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());
        }