public void DoPairTest() { Dictionary <CurrencyName, double> currencies = new Dictionary <CurrencyName, double>(); List <Currency> CurrList = new List <Currency>(); CurrList.Add(new Currency(CurrencyName.UAH, 500)); CurrList.Add(new Currency(CurrencyName.UAH, 100)); CurrList.Add(new Currency(CurrencyName.Dollar, 100)); CurrList.Add(new Currency(CurrencyName.Euro, 200)); CurrList.Add(new Currency(CurrencyName.Euro, 100)); currencies = PairOfCurrency.DoPair(CurrList); foreach (var i in currencies) { if (i.Key == CurrencyName.UAH) { Assert.AreEqual(i.Value, 600); } if (i.Key == CurrencyName.Dollar) { Assert.AreEqual(i.Value, 100); } if (i.Key == CurrencyName.Euro) { Assert.AreEqual(i.Value, 300); } } }
static void Main(string[] args) { int choice; Dictionary <CurrencyName, double> currencies = new Dictionary <CurrencyName, double>(); Dictionary <CurrencyName, double> resultOfConversion = new Dictionary <CurrencyName, double>(); Currency cur = new Currency(); List <Currency> lcur = new List <Currency>(); Console.WriteLine("-==All list==-"); //// try { cur.Read(lcur); cur.ShowALL(lcur); //// Console.WriteLine(); Console.WriteLine("-==Only грн==-"); //// cur.ShowUAN(lcur); Console.WriteLine("-==By pairs==-"); currencies = PairOfCurrency.DoPair(lcur); File_manager.Save("../../Result.txt", currencies); Console.WriteLine("-==Succesfully saved to file==-"); Console.WriteLine("Choose to what currency convert all money \n1 for Dollar, 2 - Euro and 3 for UAH:"); choice = Convert.ToInt32(Console.ReadLine()); if (choice == 1) { resultOfConversion = Conversion.To(currencies, CurrencyName.Dollar); File_manager.Save("../../ResultOfConversion.txt", resultOfConversion); } else if (choice == 2) { resultOfConversion = Conversion.To(currencies, CurrencyName.Euro); File_manager.Save("../../ResultOfConversion.txt", resultOfConversion); } else if (choice == 3) { resultOfConversion = Conversion.To(currencies, CurrencyName.UAH); File_manager.Save("../../ResultOfConversion.txt", resultOfConversion); } else { throw new ArgumentNullException("Wrong choice of conversion!"); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); ////Console.ReadKey(); } Console.ReadKey(); ////Testing }
public void ConvertToHryvniaTest() { Dictionary <CurrencyName, double> result = new Dictionary <CurrencyName, double>(); Dictionary <CurrencyName, double> currencies = new Dictionary <CurrencyName, double>(); List <Currency> list = new List <Currency>(); list.Add(new Currency(CurrencyName.Euro, 100)); list.Add(new Currency(CurrencyName.Euro, 200)); list.Add(new Currency(CurrencyName.Dollar, 100)); list.Add(new Currency(CurrencyName.UAH, 1000)); list.Add(new Currency(CurrencyName.UAH, 100)); list.Add(new Currency(CurrencyName.Dollar, 200)); currencies = PairOfCurrency.DoPair(list); result = Conversion.To(currencies, CurrencyName.UAH); foreach (var i in result) { Assert.AreEqual(i.Key, CurrencyName.UAH); Assert.AreEqual(Math.Round(i.Value, 2), 19352); } }