//create new ExchangeRateItem for dgExchangeRate private ExchangeRateItem InitializeNewExchangeRateItem(int ID, Tuple <string, string> rateBuySell) { var bankID = BankID.Create(ID); var newExchangeRateItem = new ExchangeRateItem(ID, exchangeRate.BanksInfo[bankID].Name, rateBuySell.Item1, rateBuySell.Item2); //Item1 - buy rate, Item2 - sell rate return(newExchangeRateItem); }
//save button clicked private void btnSave_Click(object sender, RoutedEventArgs e) { try { var bankID = BankID.Create(Convert.ToInt32(txID.Text)); //read id from txID var bankName = BankName.Create(txName.Text); //read name from txName var bankURI = BankURI.Create(txURI.Text); //read URI from txURI var bankPattern = BankPattern.Create(txPattern.Text); //read pattern from txPattern var bankBuyIndex = BankIndex.Create(Convert.ToInt32(txBuyIndex.Text)); //read BuyIndex from txBuyIndex var bankSellIndex = BankIndex.Create(Convert.ToInt32(txSellIndex.Text)); //read SellIndex from txSellIndex if (oper == Operations.Edit) //if window in "edit mode" { MainWindow.exchangeRate.RemoveBankInfo(this.bankInfo.ID); //remove bankinfo from list FileHelper.DeleteFromFile(this.bankInfo); //remove bankinfo from file } var bankInfo = CreateBankInfo(bankID, bankName, bankURI, bankPattern, bankBuyIndex, bankSellIndex); MainWindow.exchangeRate.AddBankInfo(bankInfo); //save bankinfo in list FileHelper.WriteInFile(bankInfo); //save bankinfo in file this.DialogResult = true; this.Close(); //close file } catch (Exception excep) { MessageBox.Show(excep.Message); } }
private void Menu_EditBank_Click(object sender, RoutedEventArgs e) { var selectedItem = dgExchangeRate.SelectedItem as ExchangeRateItem; if (!ReferenceEquals(selectedItem, null)) { try { var selectedID = BankID.Create(selectedItem.ID); var addWindow = new AddEditWindow(exchangeRate.BanksInfo[selectedID]); if (addWindow.ShowDialog() == true) { UpdateDataGrid(); } } catch (Exception except) { MessageBox.Show(except.Message); } } else { MessageBox.Show("Click on item that needed to be edit"); } }
public void CreateBankID_GreaterBorderValue() { Int64 borderValue = unchecked (int.MaxValue + 1); var actual = BankID.Create(Convert.ToInt32(borderValue)); Assert.AreEqual(borderValue, actual); }
public void CreateBankID_NormalValue() { var expected = 0; var actual = BankID.Create(0); Assert.AreEqual(expected, actual); }
public void ConvertBankID_ToString() { var expected = "1"; var actual = BankID.Create(1).ToString(); Assert.AreEqual(expected, actual); }
public void CreateBankID_BorderValue() { var borderValue = int.MaxValue; var actual = BankID.Create(borderValue); Assert.AreEqual(borderValue, actual); }
public void GetSellRate() { string expected = "2740.00"; //check on web-site sell exchange rate (USD) var neededBankID = BankID.Create(1); string actual = exchangeRate.GetSellRate(neededBankID).Result; //get sell rate from web-site Assert.AreEqual(expected, actual); }
public void GetBuyRate() { string expected = "2685.00"; //check on web-site buy exchange rate (USD) var neededBankID = BankID.Create(1); string actual = exchangeRate.GetBuyRate(neededBankID).Result; //get buy rate from web-site Assert.AreEqual(expected, actual); }
public void GetBuySellRate() { var expected = new Tuple <string, string>("2685.00", "2740.00"); //check on web-site buy and sell exchange rate (USD) var neededBankID = BankID.Create(1); var actual = exchangeRate.GetBuySellRate(neededBankID).Result; //get buy and sell rate from web-site Assert.AreEqual(expected, actual); }
public static void InitializeClass(TestContext testContext) { BankID bankID = BankID.Create(1); BankName bankName = BankName.Create("Ощадбанк"); BankURI bankURI = BankURI.Create("https://www.oschadbank.ua/ru/private/currency/currency_rates/"); BankPattern pattern = BankPattern.Create(@"<td class=""text-right"">(\d+\.\d+)</td>"); BankIndex buyIndex = BankIndex.Create(1); BankIndex sellIndex = BankIndex.Create(2); exchangeRateItem = new BankInfo(bankID, bankName, bankURI, pattern, buyIndex, sellIndex); //initialize BankInfo item exchangeRate = new ExchangeRate(); //initialize ExchangeRate class }
public static void Initialize(TestContext testContext) { File.Delete("BanksInfo.csv"); //delete file if it exist var bankID = BankID.Create(1); var bankName = BankName.Create("Укргазбанк"); var bankURI = BankURI.Create("https://www.ukrgasbank.com/"); var bankPattern = BankPattern.Create(@"<td class=""val"">(\d+\.\d+)</td>"); var bankBuyIndex = BankIndex.Create(0); var bankSellIndex = BankIndex.Create(1); bankInfo = new BankInfo(bankID, bankName, bankURI, bankPattern, bankBuyIndex, bankSellIndex); bankInfo2 = new BankInfo(BankID.Create(2), bankName, bankURI, bankPattern, bankBuyIndex, bankSellIndex); }
private void dgExchangeRate_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { var selectedItem = dgExchangeRate.SelectedItem as ExchangeRateItem; if (!ReferenceEquals(selectedItem, null)) { try { var selectedID = BankID.Create(selectedItem.ID); var editWindow = new AddEditWindow(exchangeRate.BanksInfo[selectedID]); if (editWindow.ShowDialog() == true) { UpdateDataGrid(); } } catch (Exception excep) { MessageBox.Show(excep.Message); } } }
private static BankInfo CreateBankInfo(string lineFromFile) { var items = lineFromFile.Split(','); items = items.Select(x => x.Trim()).ToArray(); //remove spaces in words items = items.Where(x => !String.IsNullOrEmpty(x)).ToArray(); //remove empty items if (items.Length == 6) { BankID bankID = BankID.Create(Convert.ToInt32(items[0])); BankName bankName = BankName.Create(items[1]); BankURI bankURI = BankURI.Create(items[2]); BankPattern bankPattern = BankPattern.Create(items[3]); BankIndex bankBuy = BankIndex.Create(Convert.ToInt32(items[4])); BankIndex bankSell = BankIndex.Create(Convert.ToInt32(items[5])); return(new BankInfo(bankID, bankName, bankURI, bankPattern, bankBuy, bankSell)); } else { throw new Exception("Wrong data in file"); } }
public void CreateBankID_LessThanZero() { var bankID = BankID.Create(-1); }