Beispiel #1
0
        public void ReturnMovie()
        {
            var rent = Alex.DoRent(new RentInfo(Avatar, 1)).Rents[0];

            VideoRentDateTime.AddDays(3);
            var overdueReceipt = Alex.ReturnRent(rent);

            Assert.IsNotNull(overdueReceipt);
            Assert.AreNotEqual(0, overdueReceipt.Payment);
        }
Beispiel #2
0
        public void MovieItemLastRentedOn()
        {
            VideoRentDateTime.AddDays(10);
            var rentDate = VideoRentDateTime.Now;
            var rent     = Anton.DoRent(new RentInfo(Postal)).Rents[0];
            var item     = rent.Item;

            VideoRentDateTime.AddDays(2);
            rent.Return();
            Assert.AreEqual(rentDate, item.LastRentedOn);
        }
Beispiel #3
0
        public void RentOn_And_DateReturned()
        {
            VideoRentDateTime.AddDays(-2);
            var rent = Andrew.DoRent(new RentInfo(Avatar)).Rents[0];

            Assert.IsNull(rent.ReturnedOn);
            VideoRentDateTime.AddDays(2);
            rent.Return();
            Assert.AreEqual(VideoRentDateTime.Now.Date, rent.ReturnedOn.Value.Date);
            Assert.AreEqual(VideoRentDateTime.Now.AddDays(-2).Date, rent.RentedOn.Date);
        }
Beispiel #4
0
        public void CustomerIsDebter()
        {
            var antonReceipt = Anton.DoRent(new RentInfo(Postal, 1));

            VideoRentDateTime.AddDays(5);
            Andrew.DoRent(new RentInfo(Avatar, 3));
            Session.CommitChanges();
            Assert.IsTrue(Anton.IsDebter);
            Assert.IsFalse(Andrew.IsDebter);
            Anton.ReturnRent(antonReceipt.Rents[0]);
            Session.CommitChanges();
            Assert.IsFalse(Anton.IsDebter);
        }
Beispiel #5
0
        public void TryDeleteItemWasInRent()
        {
            var item    = Avatar.AddItem();
            var receipt = Andrew.DoRent(new RentInfo(item));

            VideoRentDateTime.AddDays(3);
            Andrew.ReturnRents(receipt.Rents);
            SessionHelper.CommitSession(Session, null);
            if (item.AllowDelete)
            {
                item.Delete();
            }
            SessionHelper.CommitSession(Session, null);
        }
        public void CheckDayOffset()
        {
            var cashAccount = new Account(Session)
            {
                Debit = 300, Type = AccountTypeEnum.Cash
            };

            Session.CommitChanges();
            Andrew.DepositAmount(30);
            Session.CommitChanges();
            VideoRentDateTime.AddDays(2);
            Alex.DepositAmount(30);
            Session.CommitChanges();
            VideoRentDateTime.AddDays(2);
            Andrew.DepositAmount(30);
            Session.CommitChanges();
            Assert.IsTrue((VideoRentDateTime.Now - Andrew.LastPayDate()).Days == 4);
            Assert.IsTrue((VideoRentDateTime.Now - Alex.LastPayDate()).Days == 2);
        }
Beispiel #7
0
        void WriteHistoryToDB()
        {
            bool realTime = VideoRentDateTime.RealTime;

            VideoRentDateTime.RealTime = false;
            backgroundWorker.ReportProgress(10);
            WriteItemsToDB();
            double percentProgress = backgroundWorker.ReportedProgress;
            double percentPerDay   = (70.0 - percentProgress) / daysCount;

            VideoRentDateTime.AddDays(-daysCount - 1);
            for (int day = 0; day < daysCount; ++day)
            {
                VideoRentDateTime.AddDays(1);
                foreach (CustomerData customer in customers)
                {
                    Point point = customer.GetPoint(day);
                    if (point == null)
                    {
                        continue;
                    }
                    VideoRentDateTime.SetTimeOfDay(point.Time);
                    List <RentInfo> rentsInfo = new List <RentInfo>();
                    foreach (RentData rent in point.Rents)
                    {
                        rentsInfo.Add(new RentInfo(rent.Item.DBItem, rent.Days));
                    }
                    Receipt receipt = customer.DBCustomer.DoRent(rentsInfo);
                    foreach (RentData rent in point.Rents)
                    {
                        foreach (Rent dbRent in receipt.Rents)
                        {
                            if (dbRent.Item != rent.Item.DBItem)
                            {
                                continue;
                            }
                            rent.DBRent = dbRent;
                            break;
                        }
                    }
                    List <Rent> returns = new List <Rent>();
                    foreach (RentData rent in point.Returns)
                    {
                        returns.Add(rent.DBRent);
                    }
                    customer.DBCustomer.ReturnRents(returns);
                    List <RentInfo> sellsInfo = new List <RentInfo>();
                    foreach (RentData sell in point.Sells)
                    {
                        sellsInfo.Add(new RentInfo(sell.Item.DBItem));
                    }
                    customer.DBCustomer.Buy(sellsInfo);
                }
                foreach (LostDamageItemAction action in lostDamageItemActions)
                {
                    if (action.Day != day)
                    {
                        continue;
                    }
                    VideoRentDateTime.SetTimeOfDay(action.Time);
                    if (action.Damage)
                    {
                        action.Item.DBItem.Status = MovieItemStatus.Damaged;
                    }
                    else
                    {
                        action.Item.DBItem.Status = MovieItemStatus.Lost;
                    }
                }
                percentProgress += percentPerDay;
                backgroundWorker.ReportProgress((int)percentProgress);
            }
            backgroundWorker.ReportProgress(70);
            WriteAddedItems();
            SessionHelper.CommitInBackground(session, exceptionProcesser, backgroundWorker, 100);
            VideoRentDateTime.RealTime = realTime;
        }