public void InvertRate() { FMainDS.LoadAll(); FMainDS.DeleteAllRows(); FMainDS.InsertStandardRows(); FMainDS.SaveChanges(); TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null); mainScreen.Show(); mainScreen.ShowUnusedRates(); // Toolstrip ToolStripButton btnSave = (new ToolStripButtonTester("tbbSave", mainScreen)).Properties; // Grid TSgrdDataGrid grdDetails = (TSgrdDataGrid)(new TSgrdDataGridPagedTester("grdDetails", mainScreen)).Properties; // Panel and controls Panel pnlDetails = (new PanelTester("pnlDetails", mainScreen)).Properties; ButtonTester btnNew = new ButtonTester("btnNew", mainScreen); TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties; TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties; TtxtPetraDate dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties; TTxtNumericTextBox txtExchangeRate = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen)).Properties; ButtonTester btnInvert = new ButtonTester("btnInvertExchangeRate", mainScreen); // Select the first row in the grid. New rows should be based on data row 5 SelectRowInGrid(1, 5); // Check that Invert is enabled, then add one new row and check it is also enabled Assert.IsTrue(btnInvert.Properties.Enabled); btnNew.Click(); Assert.IsTrue(btnInvert.Properties.Enabled); txtExchangeRate.NumberValueDecimal = 2.0m; btnInvert.Click(); Assert.AreEqual(0.5m, txtExchangeRate.NumberValueDecimal); btnInvert.Click(); Assert.AreEqual(2.0m, txtExchangeRate.NumberValueDecimal); mainScreen.SaveChanges(); mainScreen.Close(); }
public void AddRowToTable() { FMainDS.LoadAll(); FMainDS.DeleteAllRows(); FMainDS.InsertStandardRows(); FMainDS.SaveChanges(); TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null); mainScreen.Show(); mainScreen.ShowUnusedRates(); // Toolstrip ToolStripButton btnSave = (new ToolStripButtonTester("tbbSave", mainScreen)).Properties; // Grid TSgrdDataGrid grdDetails = (TSgrdDataGrid)(new TSgrdDataGridPagedTester("grdDetails", mainScreen)).Properties; // Panel and controls Panel pnlDetails = (new PanelTester("pnlDetails", mainScreen)).Properties; ButtonTester btnNew = new ButtonTester("btnNew", mainScreen); TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties; TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties; TtxtPetraDate dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties; TTxtNumericTextBox txtExchangeRate = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen)).Properties; TextBox txtTimeEffective = (new TextBoxTester("txtDetailTimeEffectiveFrom", mainScreen)).Properties; // Select the bottom row - when we get a new row it should be based on StandardData[1] SelectRowInGrid(FAllRowCount, 1); // Check that the controls are disabled. But the exchange rate itself can be edited because the rows are unused. Assert.IsFalse(cmbFromCurrency.Enabled); Assert.IsFalse(cmbToCurrency.Enabled); Assert.IsFalse(dtpEffectiveDate.Enabled); Assert.IsTrue(txtExchangeRate.Enabled); Assert.IsFalse(btnSave.Enabled, "The Save button should be disabled when the screen is loaded"); // Click the 'New' button btnNew.Click(); Assert.IsTrue(btnSave.Enabled, "The Save button should be enabled after adding a new row"); Assert.IsTrue(cmbFromCurrency.Enabled); Assert.IsTrue(cmbToCurrency.Enabled); Assert.IsTrue(dtpEffectiveDate.Enabled); Assert.IsTrue(txtExchangeRate.Enabled); // The effective date should be 1st of current month DateTime expectedDate = DateTime.Today; Assert.AreEqual(EffectiveCurrency(FFromCurrencyId), cmbFromCurrency.GetSelectedString()); Assert.AreEqual(EffectiveCurrency(FToCurrencyId), cmbToCurrency.GetSelectedString()); Assert.AreEqual(expectedDate, dtpEffectiveDate.Date); Assert.AreEqual(EffectiveRate(), txtExchangeRate.NumberValueDecimal.Value); // The row number of the new row should be at row 7 Assert.AreEqual(FAllRowCount - 1, mainScreen.GetSelectedRowIndex()); // Change the rate to a new value - more than 10% different decimal newRate = 0.667m; txtExchangeRate.NumberValueDecimal = newRate; // click the 'New' button again - this time the date should be the same but the time should be 7800 ModalFormHandler = delegate(string name, IntPtr hWnd, Form form) { MessageBoxTester tester = new MessageBoxTester(hWnd); tester.SendCommand(MessageBoxTester.Command.No); }; btnNew.Click(); string expectedTime = "02:10"; // The details should be the same as before except for the new date and the rate being what we just set Assert.AreEqual(EffectiveCurrency(FFromCurrencyId), cmbFromCurrency.GetSelectedString()); Assert.AreEqual(EffectiveCurrency(FToCurrencyId), cmbToCurrency.GetSelectedString()); Assert.AreEqual(expectedDate, dtpEffectiveDate.Date); Assert.AreEqual(expectedTime, txtTimeEffective.Text); Assert.AreEqual(newRate, txtExchangeRate.NumberValueDecimal.Value); Assert.AreEqual(FAllRowCount - 1, mainScreen.GetSelectedRowIndex()); // Save the changes and check the number of rows now (we will get our rate alert warning dialog again) ModalFormHandler = delegate(string name, IntPtr hWnd, Form form) { MessageBoxTester tester = new MessageBoxTester(hWnd); tester.SendCommand(MessageBoxTester.Command.No); }; mainScreen.SaveChanges(); Assert.IsFalse(btnSave.Enabled, "The Save button should be disabled after the new row has been saved"); Assert.AreEqual(13, grdDetails.Rows.Count, "There should be 12 rows in the grid after saving 2 new rows"); mainScreen.Close(); }
public void EditRow() { FMainDS.LoadAll(); FMainDS.DeleteAllRows(); FMainDS.InsertStandardRows(); FMainDS.SaveChanges(); TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null); mainScreen.Show(); mainScreen.ShowUnusedRates(); // Toolstrip ToolStripButton btnSave = (new ToolStripButtonTester("tbbSave", mainScreen)).Properties; // Grid TSgrdDataGrid grdDetails = (TSgrdDataGrid)(new TSgrdDataGridPagedTester("grdDetails", mainScreen)).Properties; // Panel and controls Panel pnlDetails = (new PanelTester("pnlDetails", mainScreen)).Properties; ButtonTester btnNew = new ButtonTester("btnNew", mainScreen); TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties; TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties; TtxtPetraDate dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties; TTxtNumericTextBox txtExchangeRate = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen)).Properties; TextBox txtTimeEffective = (new TextBoxTester("txtDetailTimeEffectiveFrom", mainScreen)).Properties; // Select the first row in the grid. New rows should be based on data row 5 SelectRowInGrid(1, 5); // Add three rows btnNew.Click(); btnNew.Click(); btnNew.Click(); DateTime expectedDate = DateTime.Today; string expectedT1 = "02:00"; //string expectedT2 = "02:10"; string expectedT3 = "02:20"; // Check the data first Assert.AreEqual(EffectiveCurrency(FFromCurrencyId), cmbFromCurrency.GetSelectedString()); Assert.AreEqual(EffectiveCurrency(FToCurrencyId), cmbToCurrency.GetSelectedString()); Assert.AreEqual(expectedDate, dtpEffectiveDate.Date); Assert.AreEqual(expectedT3, txtTimeEffective.Text); Assert.AreEqual(EffectiveRate(), txtExchangeRate.NumberValueDecimal.Value); Assert.AreEqual(3, mainScreen.GetSelectedRowIndex()); // Focus on the from currency, then change it to 'BEF' cmbFromCurrency.Focus(); cmbFromCurrency.SetSelectedString(STANDARD_TEST_CURRENCY); cmbToCurrency.Focus(); // Now check the date and rate. Time should be back to O2:00 and rate should be 0.00 because this currency has never been used Assert.AreEqual(expectedDate, dtpEffectiveDate.Date.Value); Assert.AreEqual(expectedT1, txtTimeEffective.Text); Assert.AreEqual(0.0m, txtExchangeRate.NumberValueDecimal); Assert.AreEqual(1, mainScreen.GetSelectedRowIndex()); // Reset the currency and confirm we go back to where we were cmbFromCurrency.Focus(); cmbFromCurrency.SetSelectedString(EffectiveCurrency(FFromCurrencyId)); cmbToCurrency.Focus(); Assert.AreEqual(expectedDate, dtpEffectiveDate.Date.Value); Assert.AreEqual(expectedT3, txtTimeEffective.Text); Assert.AreEqual(EffectiveRate(), txtExchangeRate.NumberValueDecimal); Assert.AreEqual(3, mainScreen.GetSelectedRowIndex()); // Repeat for the To currency cmbToCurrency.Focus(); cmbToCurrency.SetSelectedString(STANDARD_TEST_CURRENCY); dtpEffectiveDate.Focus(); // Now check the date and rate. Date should be back to this month and rate should be 0.00 because this currency has never been used Assert.AreEqual(expectedDate, dtpEffectiveDate.Date.Value); Assert.AreEqual(expectedT1, txtTimeEffective.Text); Assert.AreEqual(0.0m, txtExchangeRate.NumberValueDecimal); Assert.AreEqual(1, mainScreen.GetSelectedRowIndex()); // Reset the currency and confirm we go back to where we were cmbToCurrency.Focus(); cmbToCurrency.SetSelectedString(EffectiveCurrency(FToCurrencyId)); dtpEffectiveDate.Focus(); Assert.AreEqual(expectedDate, dtpEffectiveDate.Date.Value); Assert.AreEqual(expectedT3, txtTimeEffective.Text); Assert.AreEqual(EffectiveRate(), txtExchangeRate.NumberValueDecimal); Assert.AreEqual(3, mainScreen.GetSelectedRowIndex()); // Finally check what happens when editing the date SelectRowInGrid(5); txtExchangeRate.NumberValueDecimal = 1.95m; // 02:00 today FixUnvalidatedChanges(); SelectRowInGrid(4); txtExchangeRate.NumberValueDecimal = 1.96m; dtpEffectiveDate.Date = DateTime.Today.AddDays(1); // 02.00 tomorrow FixUnvalidatedChanges(); SelectRowInGrid(3); txtExchangeRate.NumberValueDecimal = 1.97m; dtpEffectiveDate.Date = DateTime.Today.AddDays(2); // 02:00 next day FixUnvalidatedChanges(); SelectRowInGrid(5); Assert.AreEqual(1.95m, txtExchangeRate.NumberValueDecimal); dtpEffectiveDate.Focus(); dtpEffectiveDate.Date = DateTime.Today.AddDays(10); grdDetails.Focus(); Assert.AreEqual(1.97m, txtExchangeRate.NumberValueDecimal); Assert.AreEqual("02:00", txtTimeEffective.Text); mainScreen.SaveChanges(); mainScreen.Close(); }
public void AddRowToEmptyTable() { FMainDS.LoadAll(); FMainDS.DeleteAllRows(); FMainDS.SaveChanges(); TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null); mainScreen.Show(); mainScreen.ShowUnusedRates(); // Toolstrip ToolStripButton btnSave = (new ToolStripButtonTester("tbbSave", mainScreen)).Properties; // Grid TSgrdDataGrid grdDetails = (TSgrdDataGrid)(new TSgrdDataGridPagedTester("grdDetails", mainScreen)).Properties; // Panel and controls Panel pnlDetails = (new PanelTester("pnlDetails", mainScreen)).Properties; ButtonTester btnNew = new ButtonTester("btnNew", mainScreen); TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties; TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties; TtxtPetraDate dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties; TTxtNumericTextBox txtExchangeRate = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", mainScreen)).Properties; Assert.IsFalse(btnSave.Enabled, "The Save button should be disabled when the screen is loaded"); btnNew.Click(); Assert.IsTrue(btnSave.Enabled, "The Save button should be enabled after adding a new row"); // Work out our expectations string baseCurrency = GetDefaultBaseCurrency(); string expectedFromCurrency = "USD"; if (baseCurrency == "USD") { expectedFromCurrency = "GBP"; } DateTime expectedDate = DateTime.Today; // Check the details panel after adding the new row Assert.AreEqual(expectedFromCurrency, cmbFromCurrency.GetSelectedString()); Assert.AreEqual(baseCurrency, cmbToCurrency.GetSelectedString()); Assert.AreEqual(expectedDate, dtpEffectiveDate.Date); Assert.AreEqual(0.0m, txtExchangeRate.NumberValueDecimal); // Set a valid exchange rate and save txtExchangeRate.NumberValueDecimal = 2.0m; mainScreen.SaveChanges(); Assert.IsFalse(btnSave.Enabled, "The Save button should be disabled after the new row has been saved"); // Check the row count in the grid Assert.AreEqual(3, grdDetails.Rows.Count, "There should be 2 rows in the grid after saving a new row"); // Even though an inverse row has been added we should still be highlighting the newly added row Assert.AreEqual(expectedFromCurrency, cmbFromCurrency.GetSelectedString()); Assert.AreEqual(baseCurrency, cmbToCurrency.GetSelectedString()); Assert.AreEqual(expectedDate, dtpEffectiveDate.Date); Assert.AreEqual(2.0m, txtExchangeRate.NumberValueDecimal); // Now select the inverese row SelectRowInGrid(2); // Check the details are, in fact, the inverse Assert.AreEqual(baseCurrency, cmbFromCurrency.GetSelectedString()); Assert.AreEqual(expectedFromCurrency, cmbToCurrency.GetSelectedString()); Assert.AreEqual(expectedDate, dtpEffectiveDate.Date); Assert.AreEqual(0.5m, txtExchangeRate.NumberValueDecimal); mainScreen.Close(); }