Exemplo n.º 1
0
        public void ChargeAccounts()
        {
            var cashAccount = new Account(Session)
            {
                Type = AccountTypeEnum.Cash
            };

            Session.CommitChanges();
            Andrew.DepositAmount(30);
            Session.CommitChanges();
            Alex.DepositAmount(30);
            Session.CommitChanges();
            Assert.IsTrue(cashAccount.Balance == -60);
            VideoRentDateTime.AddMonths(1);
            Andrew.DebitMembershipFee(30);
            Session.CommitChanges();
            VideoRentDateTime.AddMonths(1);
            Andrew.DepositAmount(30);
            Session.CommitChanges();
            Andrew.DebitMembershipFee(30);
            Session.CommitChanges();
            VideoRentDateTime.AddMonths(1);
            Andrew.DebitMembershipFee(30);
            Session.CommitChanges();
            Assert.IsTrue(Andrew.IsMembershipDebter);
            Assert.IsTrue(GetMonths(VideoRentDateTime.Now - Andrew.LastPayDate()) == 3);
            Assert.IsFalse(Alex.IsMembershipDebter);
            Assert.IsTrue(cashAccount.Balance == 0);
            Assert.IsTrue(Andrew.Accounts[0].Balance == -30);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public void CheckMemberships()
        {
            var acustomer = CreateCustomer(Session, "x", "y");

            VideoRentDateTime.AddMonths(1);
            Session.CommitChanges();
            var cashAccount = new CashAccount(Session);

            acustomer.DepositAmount(15);
            Session.CommitChanges();
            Assert.IsTrue(acustomer.Accounts[0].Balance == 15);
            VideoRentDateTime.AddMonths(1);
            Assert.IsTrue(GetMonths(VideoRentDateTime.Now - acustomer.Membership.StartDate) == 2);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
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;
        }