public void TotalAmountFromCustomerShouldEqualTotalAmount(int pen, int nick, int dimes, int quart, int hd, int dol, int ones, int twos, int fives, int tens, int twen, int fift, int hund)
        {
            CashDrawer.ResetDrawer();

            double total = (pen * 0.01) + (nick * 0.05) + (dimes * 0.1) + (quart * 0.25) + (hd * 0.5) + (dol * 1) + (ones * 1) + (twos * 2) + (fives * 5) + (tens * 10) + (twen * 20) + (fift * 50) + (hund * 100);

            total = Math.Round(total, 2);
            var rvm = new RegisterViewModel();

            rvm.PenniesFromCustomer     = pen;
            rvm.NickelsFromCustomer     = nick;
            rvm.DimesFromCustomer       = dimes;
            rvm.QuartersFromCustomer    = quart;
            rvm.HalfDollarsFromCustomer = hd;
            rvm.DollarsFromCustomer     = dol;
            rvm.OnesFromCustomer        = ones;
            rvm.TwosFromCustomer        = twos;
            rvm.FivesFromCustomer       = fives;
            rvm.TensFromCustomer        = tens;
            rvm.TwentiesFromCustomer    = twen;
            rvm.FiftiesFromCustomer     = fift;
            rvm.HundredsFromCustomer    = hund;

            Assert.Equal(Math.Round(rvm.TotalAmountFromCustomer(), 2), total);
        }
        public void MakeChangeShouldReturnCorrectChange(double change, double total, int pen, int nick, int dimes, int quart, int hd, int dol, int ones, int twos, int fives, int tens, int twen, int fift, int hund)
        {
            CashDrawer.ResetDrawer();

            var rvm = new RegisterViewModel();

            rvm.PenniesFromCustomer     = pen;
            rvm.NickelsFromCustomer     = nick;
            rvm.DimesFromCustomer       = dimes;
            rvm.QuartersFromCustomer    = quart;
            rvm.HalfDollarsFromCustomer = hd;
            rvm.DollarsFromCustomer     = dol;
            rvm.OnesFromCustomer        = ones;
            rvm.TwosFromCustomer        = twos;
            rvm.FivesFromCustomer       = fives;
            rvm.TensFromCustomer        = tens;
            rvm.TwentiesFromCustomer    = twen;
            rvm.FiftiesFromCustomer     = fift;
            rvm.HundredsFromCustomer    = hund;

            rvm.MakeChange(total);

            double actualChange = (rvm.PenniesAsChange * 0.01) + (rvm.NickelsAsChange * 0.05) + (rvm.DimesAsChange * 0.1) +
                                  (rvm.QuartersAsChange * 0.25) + (rvm.HalfDollarsAsChange * 0.5) + (rvm.DollarsAsChange * 1) +
                                  (rvm.OnesAsChange * 1) + (rvm.TwosAsChange * 2) + (rvm.FivesAsChange * 5) + (rvm.TensAsChange * 10) +
                                  (rvm.TwentiesAsChange * 20) + (rvm.FiftiesAsChange * 50) + (rvm.HundredsAsChange * 100);

            Assert.Equal(change, actualChange);
        }
        public void ShouldCalculateCorrectChange(double changeDue, int payment)
        {
            CashDrawer.ResetDrawer();
            Order                 order = new Order();
            BriarheartBurger      bb    = new BriarheartBurger();
            MarkarthMilk          mm    = new MarkarthMilk();
            DragonbornWaffleFries dwf   = new DragonbornWaffleFries();

            order.Add(bb);
            order.Add(mm);
            order.Add(dwf);
            CashRegisterViewModel crv = new CashRegisterViewModel(order, null);

            crv.ChangeOwedToCustomer();
            crv.PaymentHundreds = payment;

            Assert.Equal(changeDue, Math.Round(crv.ChangeDue, 2));
            Assert.Equal(0, crv.ChangeHundreds);
            Assert.Equal(0, crv.ChangeFifties);
            Assert.Equal(4, crv.ChangeTwenties);
            Assert.Equal(1, crv.ChangeTens);
            Assert.Equal(0, crv.ChangeFives);
            Assert.Equal(0, crv.ChangeTwos);
            Assert.Equal(1, crv.ChangeOnes);
            Assert.Equal(0, crv.ChangeDollarCoins);
            Assert.Equal(0, crv.ChangeHalfDollars);
            Assert.Equal(1, crv.ChangeQuarters);
            Assert.Equal(0, crv.ChangeDimes);
            Assert.Equal(0, crv.ChangeNickles);
            Assert.Equal(2, crv.ChangePennies);
        }
        public void SettingBillsShouldNotifyProperties()
        {
            CashDrawer.ResetDrawer();
            var ord = new Order();

            ord.Add(new PhillyPoacher());
            var cvm = new CashViewModel(ord);

            Assert.PropertyChanged(cvm, "Pennies", () =>
            {
                cvm.Pennies += 1;
            });
            Assert.PropertyChanged(cvm, "AmountTendered", () =>
            {
                cvm.Ones += 1;
            });
            Assert.PropertyChanged(cvm, "AmountDue", () =>
            {
                cvm.Nickels += 1;
            });
            Assert.PropertyChanged(cvm, "AmountOwed", () =>
            {
                cvm.Twenties += 1;
            });
            Assert.PropertyChanged(cvm, "FiftiesOwed", () =>
            {
                cvm.Fifties += 1;
            });
        }
Beispiel #5
0
 /// <summary>
 /// Event handler for finalizing the sale
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void FinalizeSaleClick(object sender, RoutedEventArgs e)
 {
     cmv.FinalizeCashTransaction(); //opens drawer
     cmv.PrintReceipt();
     CashDrawer.ResetDrawer();
     DataContext = new Order();
 }
        public void QuarterShouldBeQuater()
        {
            CashDrawer.OpenDrawer();
            RegisterFunction register = new RegisterFunction(new Order());

            Assert.Equal(register.Quarters, CashDrawer.Quarters);
            CashDrawer.ResetDrawer();
        }
        public void HundredsShouldBeHundreds()
        {
            CashDrawer.OpenDrawer();
            RegisterFunction register = new RegisterFunction(new Order());

            Assert.Equal(register.Hundreds, CashDrawer.Hundreds);
            CashDrawer.ResetDrawer();
        }
        public void OnesShouldBeOnes()
        {
            CashDrawer.OpenDrawer();
            RegisterFunction register = new RegisterFunction(new Order());

            Assert.Equal(register.Ones, CashDrawer.Ones);
            CashDrawer.ResetDrawer();
        }
        public void DollarCoinShouldBeDollarCoin()
        {
            CashDrawer.OpenDrawer();
            RegisterFunction register = new RegisterFunction(new Order());

            Assert.Equal(register.DollarCoin, CashDrawer.Dollars);
            CashDrawer.ResetDrawer();
        }
        public void ShouldBeAssignableFromINotifyPropertyChanged()
        {
            CashDrawer.ResetDrawer();
            var cvm = new CashViewModel(new Order());

            CashDrawer.ResetDrawer();
            Assert.IsAssignableFrom <INotifyPropertyChanged>(cvm);
        }
        public void HalfCoinShouldBeHalfCoins()
        {
            CashDrawer.OpenDrawer();
            RegisterFunction register = new RegisterFunction(new Order());

            Assert.Equal(register.HalfDollars, CashDrawer.HalfDollars);
            CashDrawer.ResetDrawer();
        }
        public void ShouldReturnCorrectChangeAmount()
        {
            CashDrawer.ResetDrawer();
            CashModelView cmv    = new CashModelView(new Order());
            double        total  = cmv.AmountDueTextBlock;
            double        change = total * -1;

            Assert.Equal(cmv.ChangeOwedTextBlock, change);
        }
Beispiel #13
0
        public CashControl(OrderControl order)
        {
            InitializeComponent();
            oc = order;
            CashDrawer.ResetDrawer();
            //(DataContext as RoundRegisterModelView).TotalValueChanged += new EventHandler(updateTotal);
            //Total.Text = String.Format("Enter cash to pay the Order Total: {0:C}", oc.T);
//          GoalTotalText.Text = String.Format("Cash entered so far: {0:C}", (DataContext as RoundRegisterModelView).TotalValue);
        }
        public void CallingSetChangeBlocksNotifiesMoneyAsChangeProperties()
        {
            CashDrawer.ResetDrawer();
            CashModelView cmv = new CashModelView(new Order());

            cmv.AmountDueTextBlock = -186.91; //1 of every money type (negative)

            Assert.PropertyChanged(cmv, "PenniesAsChange", () =>
            {
                cmv.SetChangeBlocks();
            });
            Assert.PropertyChanged(cmv, "NicklesAsChange", () =>
            {
                cmv.SetChangeBlocks();
            });
            Assert.PropertyChanged(cmv, "DimesAsChange", () =>
            {
                cmv.SetChangeBlocks();
            });
            Assert.PropertyChanged(cmv, "QuartersAsChange", () =>
            {
                cmv.SetChangeBlocks();
            });
            Assert.PropertyChanged(cmv, "HalfDollarsAsChange", () =>
            {
                cmv.SetChangeBlocks();
            });
            Assert.PropertyChanged(cmv, "OnesAsChange", () =>
            {
                cmv.SetChangeBlocks();
            });
            Assert.PropertyChanged(cmv, "TwosAsChange", () =>
            {
                cmv.SetChangeBlocks();
            });
            Assert.PropertyChanged(cmv, "FivesAsChange", () =>
            {
                cmv.SetChangeBlocks();
            });
            Assert.PropertyChanged(cmv, "TensAsChange", () =>
            {
                cmv.SetChangeBlocks();
            });
            Assert.PropertyChanged(cmv, "TwentysAsChange", () =>
            {
                cmv.SetChangeBlocks();
            });
            Assert.PropertyChanged(cmv, "FiftysAsChange", () =>
            {
                cmv.SetChangeBlocks();
            });
            Assert.PropertyChanged(cmv, "HundredsAsChange", () =>
            {
                cmv.SetChangeBlocks();
            });
        }
        public void ChangingChangeOwedTextBlockNotifiesChangeOwedTextBlock()
        {
            CashDrawer.ResetDrawer();
            CashModelView cmv = new CashModelView(new Order());

            Assert.PropertyChanged(cmv, "ChangeOwedTextBlock", () =>
            {
                cmv.ChangeOwedTextBlock = 1;
            });
        }
        public void AddingMoneyToDrawerNotifiesMoneyProperties()
        {
            CashDrawer.ResetDrawer();
            CashModelView cmv = new CashModelView(new Order());

            Assert.PropertyChanged(cmv, "PenniesInDrawer", () =>
            {
                cmv.PenniesInDrawer += 1;
            });
            Assert.PropertyChanged(cmv, "NicklesInDrawer", () =>
            {
                cmv.NicklesInDrawer += 1;
            });
            Assert.PropertyChanged(cmv, "DimesInDrawer", () =>
            {
                cmv.DimesInDrawer += 1;
            });
            Assert.PropertyChanged(cmv, "QuartersInDrawer", () =>
            {
                cmv.QuartersInDrawer += 1;
            });
            Assert.PropertyChanged(cmv, "HalfDollarsInDrawer", () =>
            {
                cmv.HalfDollarsInDrawer += 1;
            });
            Assert.PropertyChanged(cmv, "OnesInDrawer", () =>
            {
                cmv.OnesInDrawer += 1;
            });
            Assert.PropertyChanged(cmv, "TwosInDrawer", () =>
            {
                cmv.TwosInDrawer += 1;
            });
            Assert.PropertyChanged(cmv, "FivesInDrawer", () =>
            {
                cmv.FivesInDrawer += 1;
            });
            Assert.PropertyChanged(cmv, "TensInDrawer", () =>
            {
                cmv.TensInDrawer += 1;
            });
            Assert.PropertyChanged(cmv, "TwentysInDrawer", () =>
            {
                cmv.TwentysInDrawer += 1;
            });
            Assert.PropertyChanged(cmv, "FiftysInDrawer", () =>
            {
                cmv.FiftysInDrawer += 1;
            });
            Assert.PropertyChanged(cmv, "HundredsInDrawer", () =>
            {
                cmv.HundredsInDrawer += 1;
            });
        }
        public void ChangingMoneyFromCustomerNotifiesAmountDueTextBlockProperty()
        {
            CashDrawer.ResetDrawer();
            CashModelView cmv = new CashModelView(new Order());

            Assert.PropertyChanged(cmv, "AmountDueTextBlock", () =>
            {
                cmv.PenniesFromCustomer += 1;
            });
            Assert.PropertyChanged(cmv, "AmountDueTextBlock", () =>
            {
                cmv.NicklesFromCustomer += 1;
            });
            Assert.PropertyChanged(cmv, "AmountDueTextBlock", () =>
            {
                cmv.DimesFromCustomer += 1;
            });
            Assert.PropertyChanged(cmv, "AmountDueTextBlock", () =>
            {
                cmv.QuartersFromCustomer += 1;
            });
            Assert.PropertyChanged(cmv, "AmountDueTextBlock", () =>
            {
                cmv.HalfDollarsFromCustomer += 1;
            });
            Assert.PropertyChanged(cmv, "AmountDueTextBlock", () =>
            {
                cmv.OnesFromCustomer += 1;
            });
            Assert.PropertyChanged(cmv, "AmountDueTextBlock", () =>
            {
                cmv.TwosFromCustomer += 1;
            });
            Assert.PropertyChanged(cmv, "AmountDueTextBlock", () =>
            {
                cmv.FivesFromCustomer += 1;
            });
            Assert.PropertyChanged(cmv, "AmountDueTextBlock", () =>
            {
                cmv.TensFromCustomer += 1;
            });
            Assert.PropertyChanged(cmv, "AmountDueTextBlock", () =>
            {
                cmv.TwentysFromCustomer += 1;
            });
            Assert.PropertyChanged(cmv, "AmountDueTextBlock", () =>
            {
                cmv.FiftysFromCustomer += 1;
            });
            Assert.PropertyChanged(cmv, "AmountDueTextBlock", () =>
            {
                cmv.HundredsFromCustomer += 1;
            });
        }
        public void AmountDueIsCorrect()
        {
            CashDrawer.OpenDrawer();
            Order order = new Order();

            order.Add(new AretinoAppleJuice());
            RegisterFunction register = new RegisterFunction(order);

            Assert.Equal(register.AmountDue, register.Total);
            CashDrawer.ResetDrawer();
        }
        public void ChangeOwedIsCorrect()
        {
            CashDrawer.OpenDrawer();
            Order order = new Order();

            order.Add(new AretinoAppleJuice());
            RegisterFunction register = new RegisterFunction(order);

            Assert.Equal(0, register.AmountOwe);
            CashDrawer.ResetDrawer();
        }
        public void AmountTenderedShouldBeCorrect()
        {
            CashDrawer.ResetDrawer();
            var cvm = new CashViewModel(new Order());

            cvm.Hundreds += 1;
            cvm.Twos     += 2;
            cvm.Quarters += 1;
            cvm.Nickels  += 1;
            cvm.Pennies  += 4;
            Assert.Equal(104.34, cvm.AmountTendered);
        }
        public void AddingBillsDecreasesAmountDue()
        {
            CashDrawer.ResetDrawer();
            var ord = new Order();

            ord.Add(new BriarheartBurger());
            var cvm = new CashViewModel(ord);

            cvm.Ones += 4;
            double expected = Math.Round(ord.Total - 4.0, 2);

            Assert.Equal(expected, cvm.AmountDue);
        }
        public void CorrectChangeShouldBeReturned()
        {
            CashDrawer.ResetDrawer();
            var ord = new Order();

            ord.Add(new DoubleDraugr());
            var cvm = new CashViewModel(ord);

            cvm.Twenties += 1;
            double expected = Math.Round(20.00 - ord.Total, 2);

            Assert.Equal(expected, cvm.AmountOwed);
        }
        public void HalfDollarsInDrawerShouldBeEqualToCashDrawer()
        {
            CashDrawer.ResetDrawer();
            var rvm = new RegisterViewModel();

            Assert.Equal(CashDrawer.HalfDollars, rvm.HalfDollarsInDrawer);

            rvm.HalfDollarsInDrawer = 203;
            Assert.Equal(CashDrawer.HalfDollars, rvm.HalfDollarsInDrawer);

            CashDrawer.HalfDollars = 92;
            Assert.Equal(CashDrawer.HalfDollars, rvm.HalfDollarsInDrawer);
        }
        public void NickelsInDrawerShouldBeEqualToCashDrawer()
        {
            CashDrawer.ResetDrawer();
            var rvm = new RegisterViewModel();

            Assert.Equal(CashDrawer.Nickels, rvm.NickelsInDrawer);

            rvm.NickelsInDrawer = 203;
            Assert.Equal(CashDrawer.Nickels, rvm.NickelsInDrawer);

            CashDrawer.Nickels = 92;
            Assert.Equal(CashDrawer.Nickels, rvm.NickelsInDrawer);
        }
        public void ChangingAmountDueTextBlockNotifiesChangeAndAmountProperties()
        {
            CashDrawer.ResetDrawer();
            CashModelView cmv = new CashModelView(new Order());

            Assert.PropertyChanged(cmv, "AmountDueTextBlock", () =>
            {
                cmv.AmountDueTextBlock = 1;
            });
            Assert.PropertyChanged(cmv, "ChangeOwedTextBlock", () =>
            {
                cmv.AmountDueTextBlock = 2;
            });
        }
 public void Dispose()
 {
     // Reset the cash drawer between each test
     // Initial values are:
     // 5 twenties
     // 10 tens
     // 4 fives
     // 20 ones
     // 80 quarters
     // 100 dimes
     // 80 nickels
     // 200 pennies
     CashDrawer.ResetDrawer();
 }
        public void MakeChangeShouldUpdateChangeOwed()
        {
            CashDrawer.ResetDrawer();

            var rvm = new RegisterViewModel();

            rvm.OnesFromCustomer = 2;

            rvm.MakeChange(1.73);
            Assert.Equal(0.27, rvm.ChangeOwed);

            rvm.OnesFromCustomer = 1;
            rvm.MakeChange(1.73);
            Assert.Equal(0, rvm.ChangeOwed);
        }
        public void FinalizeSaleShouldUpdateRegister(int payment)
        {
            CashDrawer.ResetDrawer();
            Order                 order = new Order();
            BriarheartBurger      bb    = new BriarheartBurger();
            MarkarthMilk          mm    = new MarkarthMilk();
            DragonbornWaffleFries dwf   = new DragonbornWaffleFries();

            order.Add(bb);
            order.Add(mm);
            order.Add(dwf);
            CashRegisterViewModel crv = new CashRegisterViewModel(order, null);

            crv.PaymentHundreds = payment;
            crv.ChangeOwedToCustomer();
            crv.FinializeSale();

            Assert.Equal(1, crv.RegisterHundreds);
            Assert.Equal(0, crv.RegisterFifties);
            Assert.Equal(1, crv.RegisterTwenties);
            Assert.Equal(9, crv.RegisterTens);
            Assert.Equal(4, crv.RegisterFives);
            Assert.Equal(0, crv.RegisterTwos);
            Assert.Equal(19, crv.RegisterOnes);
            Assert.Equal(0, crv.RegisterDollarCoin);
            Assert.Equal(0, crv.RegisterHalfDollars);
            Assert.Equal(79, crv.RegisterQuarters);
            Assert.Equal(100, crv.RegisterDimes);
            Assert.Equal(80, crv.RegisterNickels);
            Assert.Equal(198, crv.RegisterPennies);
            Assert.Equal(0, crv.PaymentHundreds);
            Assert.Equal(0, crv.PaymentFifties);
            Assert.Equal(0, crv.PaymentTwenites);
            Assert.Equal(0, crv.PaymentTens);
            Assert.Equal(0, crv.PaymentFives);
            Assert.Equal(0, crv.PaymentTwos);
            Assert.Equal(0, crv.PaymentOnes);
            Assert.Equal(0, crv.PaymentDollarCoins);
            Assert.Equal(0, crv.PaymentHalfDollars);
            Assert.Equal(0, crv.PaymentQuarters);
            Assert.Equal(0, crv.PaymentDimes);
            Assert.Equal(0, crv.PaymentNickels);
            Assert.Equal(0, crv.PaymentPennies);
        }
        public void MakeChangeShouldUpdateValidSale()
        {
            CashDrawer.ResetDrawer();

            var rvm = new RegisterViewModel();

            rvm.OnesFromCustomer = 2;

            Assert.False(rvm.ValidSale);

            // Ensure that there is always enough to make change
            rvm.PenniesInDrawer = 200;

            rvm.MakeChange(1.73);
            Assert.True(rvm.ValidSale);

            rvm.MakeChange(99999999);
            Assert.False(rvm.ValidSale);
        }
        public void ChangeShouldStartAtZero()
        {
            CashDrawer.OpenDrawer();
            RegisterFunction register = new RegisterFunction(new Order());

            Assert.Equal(0, register.ChangeDimes);
            Assert.Equal(0, register.ChangeDollarCoin);
            Assert.Equal(0, register.ChangeFifties);
            Assert.Equal(0, register.ChangeFives);
            Assert.Equal(0, register.ChangeHalfDollars);
            Assert.Equal(0, register.ChangeHundreds);
            Assert.Equal(0, register.ChangeNickles);
            Assert.Equal(0, register.ChangeOnes);
            Assert.Equal(0, register.ChangePennies);
            Assert.Equal(0, register.ChangeQuarters);
            Assert.Equal(0, register.ChangeTens);
            Assert.Equal(0, register.ChangeTwenties);
            Assert.Equal(0, register.ChangeTwos);
            CashDrawer.ResetDrawer();
        }