Ejemplo n.º 1
0
        public void TestCase2()
        {
            //Making all the card objects
            var card1 = new Card(NamedCardType.Visa, 100);
            var card2 = new Card(NamedCardType.Discover, 100);

            var card3 = new Card(NamedCardType.MasterCard, 100);

            //Putting the cards into the appropriate wallet
            var wallet1 = new Wallet();

            wallet1.Add(card1);
            wallet1.Add(card2);

            var wallet2 = new Wallet();

            wallet2.Add(card3);

            //Giving the wallets to person
            var person1 = new Person();

            person1.Add(wallet1);
            person1.Add(wallet2);

            //Testing the Interest
            Assert.AreEqual(16, person1.Interest);
            Assert.AreEqual(10, card1.Interest);
            Assert.AreEqual(1, card2.Interest);
            Assert.AreEqual(5, card3.Interest);
        }
Ejemplo n.º 2
0
        public void BankExchange(BankRefillEventArgs e, IMoneyHolder bank)
        {
            //TODO this is not even close to robust enough; needs to be able to convert to multiple types of coins
            while (e.Quarters > 0 && Wallet.Quarters >= 4 && bank.Dollars >= 1)
            {
                bank.Add(Wallet, 0, 0, 0, 4, 0);
                Wallet.Add(bank, 0, 0, 0, 0, 1);
                e.Quarters -= 4;
            }

            while (e.Dimes > 0 && Wallet.Dimes >= 2 && Wallet.Nickels >= 1 && bank.Quarters >= 1)
            {
                bank.Add(Wallet, 0, 1, 2, 0, 0);
                Wallet.Add(bank, 0, 0, 0, 1, 0);
                e.Dimes   -= 2;
                e.Nickels -= 1;
            }

            while (e.Nickels > 0 && Wallet.Nickels >= 2 && bank.Dimes >= 1)
            {
                bank.Add(Wallet, 0, 2, 0, 0, 0);
                Wallet.Add(bank, 0, 0, 1, 0, 0);
                e.Nickels -= 2;
            }

            while (e.Pennies > 0 && Wallet.Pennies >= 5 && bank.Nickels >= 1)
            {
                bank.Add(Wallet, 5, 0, 0, 0, 0);
                Wallet.Add(bank, 0, 1, 0, 0, 0);
                e.Pennies -= 5;
            }
            //TODO call bank exchange if it can't do an exchange?
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Пользователь запрашивает сдачу
        /// </summary>
        /// <returns></returns>
        public JsonResult GetChange()
        {
            List <Coin> coins = vwWallet.ReturnCache();

            userWallet.Add(coins);
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 4
0
        public void AddCredtisToWallet_Should_IncreaseBallance(List <Credit> credits)
        {
            var wallet           = new Wallet(null);
            var totalCreditValue = credits.Sum(c => c.Value);

            wallet.Add(credits);

            Assert.Equal(totalCreditValue, wallet.GetBalance());
        }
Ejemplo n.º 5
0
        public void AddCreditToWallet_Should_IncreaseBalance(int creditValue)
        {
            var wallet = new Wallet(null);
            var credit = new Credit(creditValue);

            wallet.Add(credit);

            Assert.Equal(credit.Value, wallet.GetBalance());
        }
Ejemplo n.º 6
0
        public void AvailableCreditValues_Should_ReturnAllDistinctCoinValuesTheWalletContains()
        {
            var wallet = new Wallet(null);

            wallet.Add(new List <Credit>()
            {
                new Credit(10), new Credit(10), new Credit(50), new Credit(100)
            });

            var availableCoinValues = wallet.AvailableCoinValues.ToList();

            Assert.Contains(10, availableCoinValues);
            Assert.Contains(50, availableCoinValues);
            Assert.Contains(100, availableCoinValues);
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            try
            {
                Wallet <Bill> wallet = new Wallet <Bill>();
                for (int i = 0; i < 10; i++)
                {
                    wallet.Add(new Bill(5));
                }
                for (int i = 0; i < 50; i++)
                {
                    wallet.Add(new Bill(10));
                }
                for (int i = 0; i < 10; i++)
                {
                    wallet.Add(new Bill(20));
                }
                for (int i = 0; i < 20; i++)
                {
                    wallet.Add(new Bill(100));
                }
                for (int i = 0; i < 111; i++)    // for (int i = 0; i < 112; i++)
                {
                    wallet.Add(new Bill(100));
                }

                var binFormatted = new BinaryFormatter();

                using (var file = new FileStream("file.bin", FileMode.OpenOrCreate))
                {
                    binFormatted.Serialize(file, wallet);
                }

                //var XMLFormatted = new XmlSerializer(typeof(Wallet<Bill>));

                //using (var file = new FileStream("file.xml", FileMode.OpenOrCreate))
                //{

                //    XMLFormatted.Serialize(file, wallet);
                //    Console.WriteLine("Объект сериализован");
                //}

                //var jsonFormatted = new DataContractJsonSerializer(typeof(Wallet<Bill>));

                //using (var file = new FileStream("file.json", FileMode.Create))
                //{

                //    jsonFormatted.WriteObject(file, wallet);
                //}

                wallet.Count();
                wallet.Remove();
                Console.WriteLine("_______________________");
                wallet.Count();
                Console.WriteLine(wallet.ToString());
            }
            catch (ToMuchMoney err)
            {
                Console.WriteLine(err.Message);
            }
            catch (NoBillWallet err)
            {
                Console.WriteLine(err.Message);
            }
            catch (Error err)
            {
                Console.WriteLine(err.Message);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Инициализатор сервис в соответствии с условиями задания
        /// </summary>
        /// <returns></returns>
        static VendingMachineService.Service1 GetInitializedServiceInstance()
        {
            #region
            var content = new VendingMachineService.VendingMachineContent();
            content.Add((int)Товары.Чай, "Чай", 13, 10);
            content.Add((int)Товары.Кофе, "Кофе", 18, 20);
            content.Add((int)Товары.Кофе_с_молоком, "Кофе с молоком", 21, 20);
            content.Add((int)Товары.Сок, "Сокъ", 35, 15);
            #endregion

            #region
            var userWallet = new Wallet();
            userWallet.Add(1, 10);
            userWallet.Add(2, 30);
            userWallet.Add(5, 20);
            userWallet.Add(10, 15);
            #endregion

            #region
            var machineWallet = new Wallet();
            machineWallet.Add(1, 100);
            machineWallet.Add(2, 100);
            machineWallet.Add(5, 100);
            machineWallet.Add(10, 100);
            #endregion

            var service = new VendingMachineService.Service1();

            service.Initialize(content, machineWallet, userWallet);

            return service;
        }