public void TestCoinValue()
        {
            CurrencyRepo  repo = new CurrencyRepo();
            ViewModelRepo vm   = new ViewModelRepo(repo);

            string defaultValue = vm.CoinValue; //get start count

            ICoin quarter = new Quarter();      //make and add quarter

            repo.AddCoin(quarter);

            string valueAfterQuarter = vm.CoinValue;//get count after adding quarter

            ICoin penny  = new Penny();
            ICoin dollar = new DollarCoin();
            ICoin nickel = new Nickel();
            ICoin dime   = new Dime();

            repo.AddCoin(penny);
            repo.AddCoin(dollar);
            repo.AddCoin(nickel);
            repo.AddCoin(dime);

            string valueAfterOneOfEachCoin = vm.CoinValue;

            Assert.AreEqual("Repo Value: 0", defaultValue);
            Assert.AreEqual("Repo Value: 0.25", valueAfterQuarter);
            Assert.AreEqual("Repo Value: 1.41", valueAfterOneOfEachCoin);
        }
        public void TestCoinCount()
        {
            CurrencyRepo  repo = new CurrencyRepo();
            ViewModelRepo vm   = new ViewModelRepo(repo);

            string defaultCount = vm.CoinCount; //get start count

            ICoin quarter = new Quarter();      //make and add quarter

            repo.AddCoin(quarter);

            string countAfterOneCoin = vm.CoinCount;//get count after adding quarter

            ICoin penny  = new Penny();
            ICoin dollar = new DollarCoin();
            ICoin nickel = new Nickel();
            ICoin dime   = new Dime();

            repo.AddCoin(penny);
            repo.AddCoin(dollar);
            repo.AddCoin(nickel);
            repo.AddCoin(dime);

            string countAfterOneOfEachCoin = vm.CoinCount;

            Assert.AreEqual("Coins: 0", defaultCount);
            Assert.AreEqual("Coins: 1", countAfterOneCoin);
            Assert.AreEqual("Coins: 5", countAfterOneOfEachCoin);
        }
Exemplo n.º 3
0
        //deserialize and load a repo from a file
        private void ExecuteCommandLoad(object parameter)
        {
            IFormatter   formatter = new BinaryFormatter();
            Stream       stream    = new FileStream(@"...\Repo.txt", FileMode.Open, FileAccess.Read);
            CurrencyRepo temp      = (CurrencyRepo)formatter.Deserialize(stream);

            stream.Close();
            //makes sure that the coins are added to the global repo so that the other window/view model can
            //see the coins add in this window
            foreach (ICoin c in temp.Coins)
            {
                repo.AddCoin(c);
            }
            //reduce the number of coins when the repo is loaded
            repo.ReduceCoins();
            RaisePropertyChanged("TotalAmount");
        }
        private void ButtonAddCoin_Click(object sender, RoutedEventArgs e)
        {
            Coin tempC = new Penny();

            switch (CoinList.SelectionBoxItem)
            {
            case "Penny":
            {
                tempC = new Penny();
                break;
            }

            case "Nickel":
            {
                tempC = new Nickel();
                break;
            }

            case "Dime":
            {
                tempC = new Dime();
                break;
            }

            case "Quarter":
            {
                tempC = new Quarter();
                break;
            }

            case "Half Dollar":
            {
                tempC = new HalfDollar();
                break;
            }

            case "Dollar Coin":
            {
                tempC = new DollarCoin();
                break;
            }
            }

            repo.AddCoin(tempC);


            ViewModelRepo    = new ViewModelCreateCurrencyRepo(repo);
            this.DataContext = ViewModelRepo;

            string value = Convert.ToString(repo.TotalValue());

            labelRepoValueDisplay.Content = "$" + value;
        }
Exemplo n.º 5
0
        public void RemoveCoinTest()
        {
            //Arrange
            int coinCountOrig, coinCountAfterPenny, coinCountAfterFiveMorePennies;
            int numPennies = 5;


            Double valueOrig, valueAfterPenny, valueAfterFiveMorePennies;
            Double valueAfterNickel, valueAfterDime, valueAfterQuarter, valueAfterDollar;

            repo = new CurrencyRepo();  //reset repo

            //add some coins
            repo.AddCoin(penny);

            for (int i = 0; i < numPennies; i++)
            {
                repo.AddCoin(penny);
            }
            repo.AddCoin(nickel);
            repo.AddCoin(dime);
            repo.AddCoin(quarter);
            repo.AddCoin(dollarCoin);

            //Act
            coinCountOrig = repo.GetCoinCount();
            valueOrig     = repo.TotalValue();
            repo.RemoveCoin(penny);
            coinCountAfterPenny = repo.GetCoinCount();
            valueAfterPenny     = repo.TotalValue();

            for (int i = 0; i < numPennies; i++)
            {
                repo.RemoveCoin(penny);
            }
            coinCountAfterFiveMorePennies = repo.GetCoinCount();
            valueAfterFiveMorePennies     = repo.TotalValue();

            repo.RemoveCoin(nickel);
            valueAfterNickel = repo.TotalValue();
            repo.RemoveCoin(dime);
            valueAfterDime = repo.TotalValue();
            repo.RemoveCoin(quarter);
            valueAfterQuarter = repo.TotalValue();
            repo.RemoveCoin(dollarCoin);
            valueAfterDollar = repo.TotalValue();


            //Assert
            Assert.AreEqual(coinCountOrig - 1, coinCountAfterPenny);
            Assert.AreEqual(coinCountAfterPenny - numPennies, coinCountAfterFiveMorePennies);

            Assert.AreEqual(valueOrig - penny.MonetaryValue, valueAfterPenny);
            Assert.AreEqual(valueAfterPenny - (numPennies * penny.MonetaryValue), valueAfterFiveMorePennies);

            //Assert.AreEqual(valueAfterFiveMorePennies - nickel.MonetaryValue, valueAfterNickel); //HUH? 1.35 != 1.35 both are double?
            Assert.AreEqual(valueAfterNickel - dime.MonetaryValue, valueAfterDime);
            Assert.AreEqual(valueAfterDime - quarter.MonetaryValue, valueAfterQuarter);
            Assert.AreEqual(valueAfterQuarter - dollarCoin.MonetaryValue, valueAfterDollar);
        }
Exemplo n.º 6
0
        public void AddCoinTest()
        {
            //Arrange
            int coinCountOrig, coinCountAfterPenny, coinCountAfterFiveMorePennies;
            int numPennies = 5;


            Double valueOrig, valueAfterPenny, valueAfterFiveMorePennies;
            Double valueAfterNickel, valueAfterDime, valueAfterQuarter, valueAfterDollar;

            //Act
            coinCountOrig = repo.GetCoinCount();
            valueOrig     = repo.TotalValue();

            repo.AddCoin(penny);
            coinCountAfterPenny = repo.GetCoinCount();
            valueAfterPenny     = repo.TotalValue();

            for (int i = 0; i < numPennies; i++)
            {
                repo.AddCoin(penny);
            }
            coinCountAfterFiveMorePennies = repo.GetCoinCount();
            valueAfterFiveMorePennies     = repo.TotalValue();

            repo.AddCoin(nickel);
            valueAfterNickel = repo.TotalValue();
            repo.AddCoin(dime);
            valueAfterDime = repo.TotalValue();
            repo.AddCoin(quarter);
            valueAfterQuarter = repo.TotalValue();
            repo.AddCoin(dollarCoin);
            valueAfterDollar = repo.TotalValue();


            //Assert
            Assert.AreEqual(coinCountOrig + 1, coinCountAfterPenny);
            Assert.AreEqual(coinCountAfterPenny + numPennies, coinCountAfterFiveMorePennies);

            Assert.AreEqual(valueOrig + penny.MonetaryValue, valueAfterPenny);
            Assert.AreEqual(valueAfterPenny + (numPennies * penny.MonetaryValue), valueAfterFiveMorePennies);

            Assert.AreEqual(valueAfterFiveMorePennies + nickel.MonetaryValue, valueAfterNickel);
            Assert.AreEqual(valueAfterNickel + dime.MonetaryValue, valueAfterDime);
            Assert.AreEqual(valueAfterDime + quarter.MonetaryValue, valueAfterQuarter);
            Assert.AreEqual(valueAfterQuarter + dollarCoin.MonetaryValue, valueAfterDollar);
        }
        public ActionResult Add(string id, IFormCollection collection, [FromServices] CurrencyRepo repo)
        {
            try
            {
                string selectedValue = Request.Form["selectedCoinToAdd"];
                switch (selectedValue)
                {
                case "Penny":
                    repo.AddCoin(new Penny());
                    break;

                case "Nickel":
                    repo.AddCoin(new Nickel());
                    break;

                case "Dime":
                    repo.AddCoin(new Dime());
                    break;

                case "Quarter":
                    repo.AddCoin(new Quarter());
                    break;

                case "Half Dollar":
                    repo.AddCoin(new HalfDollar());
                    break;

                case "Dollar Coin":
                    repo.AddCoin(new DollarCoin());
                    break;
                }
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }