public void LoadEmptyTable() { FMainDS.LoadAll(); FMainDS.DeleteAllRows(); FMainDS.SaveChanges(); TFrmSetupCorporateExchangeRate mainScreen = new TFrmSetupCorporateExchangeRate(null); mainScreen.Show(); // 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; TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties; TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties; TtxtPetraDate dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties; CheckBox chkHideOthers = (new CheckBoxTester("chkHideOthers", mainScreen)).Properties; Assert.IsFalse(btnSave.Enabled, "The Save button should be disabled when the screen is loaded"); Assert.IsFalse(pnlDetails.Enabled, "The Details Panel should be disabled on initial load"); Assert.IsFalse(dtpEffectiveDate.Date.HasValue, "The date control should be empty on initial load"); Assert.AreEqual(1, grdDetails.Rows.Count, "The grid should be empty"); mainScreen.Close(); }
public void TestCulture() { TtxtPetraDate dtpDate = new TtxtPetraDate(); dtpDate.Name = "dtpDate"; dtpDate.DateChanged += new TPetraDateChangedEventHandler(DateChanged); dtpDate.TextChanged += new EventHandler(TextChanged); Form TestForm = new Form(); TestForm.Controls.Add(dtpDate); TestForm.Show(); TTxtPetraDateTester tester = new TTxtPetraDateTester("dtpDate"); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); tester.Properties.Text = "30-JAN-2012"; Assert.AreEqual(new DateTime(2012, 1, 30), tester.Properties.Date.Value, "date should be set, 30-JAN-2012"); tester.Properties.Text = "30-JANUARY-2012"; Assert.AreEqual(new DateTime(2012, 1, 30), tester.Properties.Date.Value, "date should be set, 30-JANUARY-2012"); tester.Properties.Text = "30-SEPTEMBER-2012"; Assert.AreEqual(new DateTime(2012, 9, 30), tester.Properties.Date.Value, "date should be set, 30-SEPTEMBER-2012"); tester.Properties.Text = "30-APR-2012"; Assert.AreEqual(new DateTime(2012, 4, 30), tester.Properties.Date.Value, "date should be set, 30-APR-2012"); tester.Properties.Text = "30-NOV-2012"; Assert.AreEqual(new DateTime(2012, 11, 30), tester.Properties.Date.Value, "date should be set, 30-NOV-2012"); }
/// <summary> /// Handler for ModalEmptyTable test /// </summary> public void LoadModalEmptyTableHandler() { // Controls ButtonTester btnNewTester = new ButtonTester("btnNew", FModalFormName); ButtonTester btnCloseTester = new ButtonTester("btnClose", FModalFormName); ButtonTester btnCancelTester = new ButtonTester("btnCancel", FModalFormName); Button btnNew = btnNewTester.Properties; Button btnClose = btnCloseTester.Properties; Button btnDelete = (new ButtonTester("btnDelete", FModalFormName)).Properties; TSgrdDataGrid grdDetails = (TSgrdDataGrid)((new TSgrdDataGridPagedTester("grdDetails", FModalFormName)).Properties); Panel pnlDetails = (new PanelTester("pnlDetails", FModalFormName)).Properties; TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", FModalFormName)).Properties; TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", FModalFormName)).Properties; TtxtPetraDate dtpDateEffective = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", FModalFormName)).Properties; TTxtNumericTextBox txtRateOfExchange = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", FModalFormName)).Properties; // These should be the states on an empty modal screen (as loaded) try { Assert.IsFalse(btnClose.Enabled); Assert.IsFalse(btnDelete.Enabled); Assert.IsFalse(dtpDateEffective.Date.HasValue); Assert.IsFalse(pnlDetails.Enabled); Assert.AreEqual(1, grdDetails.Rows.Count); // Now create a new row btnNewTester.Click(); // These should be the states after adding a new row Assert.AreEqual("GBP", cmbFromCurrency.GetSelectedString()); // GBP passed in as a ShowDialog parameter Assert.AreEqual(STANDARD_TEST_CURRENCY, cmbToCurrency.GetSelectedString()); Assert.AreEqual(FStandardEffectiveDate, dtpDateEffective.Date); Assert.IsFalse(cmbFromCurrency.Enabled); Assert.IsFalse(cmbToCurrency.Enabled); Assert.IsTrue(btnClose.Enabled); Assert.IsTrue(btnDelete.Enabled); Assert.IsTrue(pnlDetails.Enabled); Assert.AreEqual(2, grdDetails.Rows.Count); // Rate should be 0.0m - we will need to set it to something else Assert.AreEqual(0.0m, txtRateOfExchange.NumberValueDecimal); txtRateOfExchange.NumberValueDecimal = STANDARD_RATE_OF_EXCHANGE; // Save this as our rate and quit btnCloseTester.Click(); } catch (Exception ex) { // Handle the exception and abort without saving HandleModalException(ex); btnCancelTester.Properties.DialogResult = DialogResult.Abort; btnCancelTester.Click(); } }
public void EnterInvalidDates() { TtxtPetraDate dtpDate = new TtxtPetraDate(); dtpDate.Name = "dtpDate"; dtpDate.DateChanged += new TPetraDateChangedEventHandler(DateChanged); dtpDate.TextChanged += new EventHandler(TextChanged); Form TestForm = new Form(); TestForm.Controls.Add(dtpDate); TestForm.Show(); TTxtPetraDateTester tester = new TTxtPetraDateTester("dtpDate"); TextChangedCalled = 0; DateChangedCalled = 0; NumberOfMessageBoxes = 0; DialogBoxHandler = HandleMessageBox; tester.Properties.Text = "30"; Assert.AreEqual(1, NumberOfMessageBoxes, "entering an invalid date should only show a messagebox once"); Assert.IsTrue(TVerificationHelper.AreVerificationResultsIdentical(tester.Properties.DateVerificationResult, Ict.Common.Verification.TDateChecks.GetInvalidDateVerificationResult("Date", null), false, false)); TextChangedCalled = 0; DateChangedCalled = 0; NumberOfMessageBoxes = 0; DialogBoxHandler = HandleMessageBox; tester.Properties.Text = "301210000"; Assert.AreEqual(1, NumberOfMessageBoxes, "entering an invalid date should only show a messagebox once: year 10000"); DialogBoxHandler = null; NumberOfMessageBoxes = 0; DialogBoxHandler = HandleMessageBox; tester.Properties.AllowEmpty = false; tester.Properties.Text = "01-JAN-2010"; tester.Properties.Text = ""; Assert.AreEqual(1, NumberOfMessageBoxes, "entering an invalid date should only show a messagebox once: year 10000"); Assert.IsTrue(TVerificationHelper.AreVerificationResultsIdentical(tester.Properties.DateVerificationResult, new TVerificationResult(null, ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_NOUNDEFINEDDATE, CommonResourcestrings.StrInvalidDateEntered + Environment.NewLine + "{0} must not be empty.", new string[] { "'Date'" })))); DialogBoxHandler = null; }
public void Validation() { FMainDS.LoadAll(); FMainDS.DeleteAllRows(); FMainDS.SaveChanges(); TFrmSetupCorporateExchangeRate mainScreen = new TFrmSetupCorporateExchangeRate(null); mainScreen.Show(); 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; btnNew.Click(); // Set up some bad entries dtpEffectiveDate.Text = ""; txtExchangeRate.NumberValueDecimal = 0.0m; string dlgText = String.Empty; bool dlgDisplayed = false; // Click the New button and discover what validation errors we have // Note - we do not put assert's inside the delegate because we want the dialog to close. // If the dialog is left hanging this might do bad stuff to automated testing ModalFormHandler = delegate(string name, IntPtr hWnd, Form form) { MessageBoxTester tester = new MessageBoxTester(hWnd); dlgText = tester.Text; dlgDisplayed = true; tester.SendCommand(MessageBoxTester.Command.OK); }; btnNew.Click(); // Check that we did display the dialog and that we picked up the validation errors we predicted Assert.IsTrue(dlgDisplayed); Assert.IsTrue(dlgText.Contains(CommonErrorCodes.ERR_NOUNDEFINEDDATE)); Assert.IsTrue(dlgText.Contains(CommonErrorCodes.ERR_INVALIDNUMBER)); // Close without saving ModalFormHandler = delegate(string name, IntPtr hWnd, Form form) { MessageBoxTester tester = new MessageBoxTester(hWnd); tester.SendCommand(MessageBoxTester.Command.No); }; mainScreen.Close(); }
public void InvertRate() { FMainDS.LoadAll(); FMainDS.DeleteAllRows(); FMainDS.InsertStandardRows(); FMainDS.SaveChanges(); TFrmSetupCorporateExchangeRate mainScreen = new TFrmSetupCorporateExchangeRate(null); mainScreen.Show(); // 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 enabled and test that it works btnNew.Click(); Assert.IsTrue(btnInvert.Properties.Enabled); txtExchangeRate.NumberValueDecimal = 5.0m; btnInvert.Click(); Assert.AreEqual(0.2m, txtExchangeRate.NumberValueDecimal); btnInvert.Click(); Assert.AreEqual(5.0m, txtExchangeRate.NumberValueDecimal); ModalFormHandler = delegate(string name, IntPtr hWnd, Form form) { MessageBoxTester tester = new MessageBoxTester(hWnd); tester.SendCommand(MessageBoxTester.Command.OK); }; mainScreen.SaveChanges(); mainScreen.Close(); }
private bool IsMatchingRowManual(DataRow ARow) { string transactionType = ((TCmbAutoComplete)FFilterAndFindObject.FindPanelControls.FindControlByName("cmbTransactionType")).Text; if (transactionType != String.Empty) { if (!ARow["Type"].ToString().Contains(transactionType)) { return(false); } } string status = ((TCmbAutoComplete)FFilterAndFindObject.FindPanelControls.FindControlByName("cmbStatus")).Text; if (status != String.Empty) { if (!ARow["Status"].ToString().Contains(status)) { return(false); } } DateTime dt; TtxtPetraDate fromDate = (TtxtPetraDate)FFilterAndFindObject.FindPanelControls.FindControlByName("dtpDate-1"); if ((fromDate.Text != String.Empty) && DateTime.TryParse(fromDate.Text, out dt)) { if (Convert.ToDateTime(ARow["Date"]) < dt.Date) { return(false); } } TtxtPetraDate toDate = (TtxtPetraDate)FFilterAndFindObject.FindPanelControls.FindControlByName("dtpDate-2"); if ((toDate.Text != String.Empty) && DateTime.TryParse(toDate.Text, out dt)) { if (Convert.ToDateTime(ARow["Date"]) > dt.Date) { return(false); } } return(true); }
/// <summary> /// Handler for LoadModalTableWithData test /// </summary> public void LoadModalTableHandler() { // Controls ButtonTester btnCloseTester = new ButtonTester("btnClose", FModalFormName); ButtonTester btnCancelTester = new ButtonTester("btnCancel", FModalFormName); Button btnClose = btnCloseTester.Properties; Button btnDelete = (new ButtonTester("btnDelete", FModalFormName)).Properties; TSgrdDataGrid grdDetails = (TSgrdDataGrid)((new TSgrdDataGridPagedTester("grdDetails", FModalFormName)).Properties); Panel pnlDetails = (new PanelTester("pnlDetails", FModalFormName)).Properties; TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", FModalFormName)).Properties; TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", FModalFormName)).Properties; TtxtPetraDate dtpDateEffective = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", FModalFormName)).Properties; TTxtNumericTextBox txtRateOfExchange = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", FModalFormName)).Properties; // These should be the states given the standard modal data we loaded try { Assert.AreEqual("GBP", cmbFromCurrency.GetSelectedString()); // GBP passed in as a ShowDialog parameter Assert.AreEqual(STANDARD_TEST_CURRENCY, cmbToCurrency.GetSelectedString()); // The ledger currency for the ledger passed in as parameter Assert.AreEqual(new DateTime(1900, 7, 1), dtpDateEffective.Date); Assert.AreEqual(0.51m, txtRateOfExchange.NumberValueDecimal); Assert.IsFalse(cmbFromCurrency.Enabled); Assert.IsFalse(cmbToCurrency.Enabled); Assert.IsTrue(btnClose.Enabled); Assert.IsTrue(btnClose.Visible); Assert.IsTrue(btnCancelTester.Properties.Visible); Assert.IsTrue(btnDelete.Enabled); Assert.IsTrue(pnlDetails.Enabled); Assert.AreEqual(3, grdDetails.Rows.Count); // select this item and close btnCloseTester.Click(); } catch (Exception ex) { // Handle the exception and abort without saving HandleModalException(ex); btnCancelTester.Properties.DialogResult = DialogResult.Abort; btnCancelTester.Click(); } }
public void TestEvents() { TtxtPetraDate dtpDate = new TtxtPetraDate(); dtpDate.Name = "dtpDate"; dtpDate.DateChanged += new TPetraDateChangedEventHandler(DateChanged); dtpDate.TextChanged += new EventHandler(TextChanged); Form TestForm = new Form(); TestForm.Controls.Add(dtpDate); TestForm.Show(); TTxtPetraDateTester tester = new TTxtPetraDateTester("dtpDate"); TextChangedCalled = 0; DateChangedCalled = 0; tester.Properties.Text = "31-12-2012"; Assert.AreEqual(new DateTime(2012, 12, 31), tester.Properties.Date.Value, "date should be set"); Assert.AreEqual(1, DateChangedCalled, "event DateChanged should have been called once"); Assert.AreEqual(1, TextChangedCalled, "event TextChanged should have been called once"); tester.Properties.Text = "30-12-2012"; TextChangedCalled = 0; DateChangedCalled = 0; tester.Properties.Text = "31-DEC-2012"; Assert.AreEqual(new DateTime(2012, 12, 31), tester.Properties.Date.Value, "date should be set, Test With DEC"); Assert.AreEqual(1, DateChangedCalled, "event DateChanged should have been called once, Test With DEC"); Assert.AreEqual(1, TextChangedCalled, "event TextChanged should have been called once, Test With DEC"); TextChangedCalled = 0; DateChangedCalled = 0; tester.Properties.Text = "31-12-2012"; Assert.AreEqual(new DateTime(2012, 12, 31), tester.Properties.Date.Value, "date should be set, test resetting"); Assert.AreEqual(0, DateChangedCalled, "event DateChanged should not have been called, test resetting"); Assert.AreEqual(0, TextChangedCalled, "event TextChanged should not have been called, test resetting"); }
public void EditRow() { FMainDS.LoadAll(); FMainDS.DeleteAllRows(); FMainDS.InsertStandardRows(); FMainDS.SaveChanges(); TFrmSetupCorporateExchangeRate mainScreen = new TFrmSetupCorporateExchangeRate(null); mainScreen.Show(); // 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; // 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 dt1 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); //DateTime dt2 = dt1.AddMonths(1); DateTime dt3 = dt1.AddMonths(2); // Check the data first Assert.AreEqual(EffectiveCurrency(FFromCurrencyId), cmbFromCurrency.GetSelectedString()); Assert.AreEqual(EffectiveCurrency(FToCurrencyId), cmbToCurrency.GetSelectedString()); Assert.AreEqual(dt3, dtpEffectiveDate.Date); 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("BEF"); cmbToCurrency.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(dt1, dtpEffectiveDate.Date.Value); 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(dt3, dtpEffectiveDate.Date.Value); Assert.AreEqual(EffectiveRate(), txtExchangeRate.NumberValueDecimal); Assert.AreEqual(3, mainScreen.GetSelectedRowIndex()); // Repeat for the To currency cmbToCurrency.Focus(); cmbToCurrency.SetSelectedString("BEF"); 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(dt1, dtpEffectiveDate.Date.Value); 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(dt3, dtpEffectiveDate.Date.Value); Assert.AreEqual(EffectiveRate(), txtExchangeRate.NumberValueDecimal); Assert.AreEqual(3, mainScreen.GetSelectedRowIndex()); // Finally check what happens when editing the date SelectRowInGrid(5); txtExchangeRate.NumberValueDecimal = 8.0m; // Today FixUnvalidatedChanges(); SelectRowInGrid(4); txtExchangeRate.NumberValueDecimal = 9.0m; // Today + 1m FixUnvalidatedChanges(); SelectRowInGrid(3); txtExchangeRate.NumberValueDecimal = 10.0m; // Today +2m FixUnvalidatedChanges(); SelectRowInGrid(5); Assert.AreEqual(8.0m, txtExchangeRate.NumberValueDecimal); dtpEffectiveDate.Focus(); dtpEffectiveDate.Date = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)).AddMonths(6); grdDetails.Focus(); Assert.AreEqual(10.0m, txtExchangeRate.NumberValueDecimal); mainScreen.SaveChanges(); mainScreen.Close(); }
public void AddRowToTable() { FMainDS.LoadAll(); FMainDS.DeleteAllRows(); FMainDS.InsertStandardRows(); FMainDS.SaveChanges(); TFrmSetupCorporateExchangeRate mainScreen = new TFrmSetupCorporateExchangeRate(null); mainScreen.Show(); // 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; // 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 Assert.IsFalse(cmbFromCurrency.Enabled); Assert.IsFalse(cmbToCurrency.Enabled); Assert.IsTrue(dtpEffectiveDate.ReadOnly); // Check that the controls are enabled Assert.IsTrue(txtExchangeRate.Enabled); // Click the 'New' button 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"); 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 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); 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 decimal newRate = 0.667m; txtExchangeRate.NumberValueDecimal = newRate; // click the 'New' button again - this time the date should be first of next month btnNew.Click(); expectedDate = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)).AddMonths(1); // 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(newRate, txtExchangeRate.NumberValueDecimal.Value); Assert.AreEqual(FAllRowCount - 1, mainScreen.GetSelectedRowIndex()); // Save the changes and check the number of rows now 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 AddRowToEmptyTable() { FMainDS.LoadAll(); FMainDS.DeleteAllRows(); FMainDS.SaveChanges(); TFrmSetupCorporateExchangeRate mainScreen = new TFrmSetupCorporateExchangeRate(null); mainScreen.RunOnceOnActivation(); mainScreen.Show(); // 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 expectedToCurrency = "USD"; string baseCurrency = GetDefaultBaseCurrency(); if (baseCurrency == "USD") { baseCurrency = "GBP"; } DateTime expectedDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); // Check the details panel after adding the new row Assert.AreEqual(baseCurrency, cmbFromCurrency.GetSelectedString()); Assert.AreEqual(expectedToCurrency, 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(baseCurrency, cmbFromCurrency.GetSelectedString()); Assert.AreEqual(expectedToCurrency, cmbToCurrency.GetSelectedString()); Assert.AreEqual(expectedDate, dtpEffectiveDate.Date); Assert.AreEqual(2.0m, txtExchangeRate.NumberValueDecimal); // Now select the inverese row SelectRowInGrid(1); // Check the details are, in fact, the inverse Assert.AreEqual(expectedToCurrency, cmbFromCurrency.GetSelectedString()); Assert.AreEqual(baseCurrency, cmbToCurrency.GetSelectedString()); Assert.AreEqual(expectedDate, dtpEffectiveDate.Date); Assert.AreEqual(0.5m, txtExchangeRate.NumberValueDecimal); mainScreen.Close(); }
public void LoadTableContainingData() { FMainDS.LoadAll(); FMainDS.DeleteAllRows(); FMainDS.InsertStandardRows(); FMainDS.SaveChanges(); TFrmSetupCorporateExchangeRate mainScreen = new TFrmSetupCorporateExchangeRate(null); mainScreen.Show(); // 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; TCmbAutoPopulated cmbFromCurrency = (new TCmbAutoPopulatedTester("cmbDetailFromCurrencyCode", mainScreen)).Properties; TCmbAutoPopulated cmbToCurrency = (new TCmbAutoPopulatedTester("cmbDetailToCurrencyCode", mainScreen)).Properties; TtxtPetraDate dtpEffectiveDate = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", mainScreen)).Properties; CheckBox chkHideOthers = (new CheckBoxTester("chkHideOthers", mainScreen)).Properties; // Start of testing... Assert.IsFalse(btnSave.Enabled, "The Save button should be disabled when the screen is loaded"); Assert.IsTrue(pnlDetails.Enabled, "The Details Panel should be enabled on initial load"); // Check the number of rows in the grid Assert.AreEqual(FAllRowCount + 1, grdDetails.Rows.Count); FCurrentDataId = Row2DataId(1); // Check the content of the details panel matches the last item in standard data (because sorting will have put it first) Assert.AreEqual(EffectiveCurrency(FFromCurrencyId), cmbFromCurrency.GetSelectedString(), "The From currency on row 1 should be {0}", EffectiveCurrency(FFromCurrencyId)); Assert.AreEqual(EffectiveCurrency(FToCurrencyId), cmbToCurrency.GetSelectedString(), "The To currency on row 1 should be {0}", EffectiveCurrency(FToCurrencyId)); Assert.AreEqual(EffectiveDate(), dtpEffectiveDate.Date, "The effective date on row 1 should be {0}", EffectiveDate().ToString()); // Select the second row - which will be the last but one item of standard data SelectRowInGrid(2); // Check the details again for this row Assert.AreEqual(EffectiveCurrency(FFromCurrencyId), cmbFromCurrency.GetSelectedString(), "The From currency on row 2 should be {0}", EffectiveCurrency(FFromCurrencyId)); Assert.AreEqual(EffectiveCurrency(FToCurrencyId), cmbToCurrency.GetSelectedString(), "The To currency on row 2 should be {0}", EffectiveCurrency(FToCurrencyId)); Assert.AreEqual(EffectiveDate(), dtpEffectiveDate.Date, "The effective date on row 2 should be {0}", EffectiveDate().ToString()); // Now hide the other currencies chkHideOthers.Checked = true; // The number of rows in the grid should have changed Assert.AreEqual(FHiddenRowCount + 1, grdDetails.Rows.Count, "The grid should have {0} rows when the checkbox is checked", FHiddenRowCount + 1); // But the details should still be the same Assert.AreEqual(EffectiveCurrency(FFromCurrencyId), cmbFromCurrency.GetSelectedString(), "The From currency on row 2 should be {0}", EffectiveCurrency(FFromCurrencyId)); Assert.AreEqual(EffectiveCurrency(FToCurrencyId), cmbToCurrency.GetSelectedString(), "The To currency on row 2 should be {0}", EffectiveCurrency(FToCurrencyId)); Assert.AreEqual(EffectiveDate(), dtpEffectiveDate.Date, "The effective date on row 2 should be {0}", EffectiveDate().ToString()); Assert.IsFalse(cmbToCurrency.Enabled, "The To Currency should be disabled when the checkbox is checked"); // Uncheck the box and select the last row chkHideOthers.Checked = false; SelectRowInGrid(FAllRowCount); // Check the details - should be the first item of standard data Assert.AreEqual(EffectiveCurrency(FFromCurrencyId), cmbFromCurrency.GetSelectedString(), "The From currency on row {0} should be {1}", FAllRowCount, EffectiveCurrency(FFromCurrencyId)); Assert.AreEqual(EffectiveCurrency(FToCurrencyId), cmbToCurrency.GetSelectedString(), "The To currency on row {0} should be {1}", FAllRowCount, EffectiveCurrency(FToCurrencyId)); Assert.AreEqual(EffectiveDate(), dtpEffectiveDate.Date, "The effective date on row {0} should be {1}", FAllRowCount, EffectiveDate().ToString()); // Hide other To currencies again - now the selected row will have jumped higher chkHideOthers.Checked = true; Assert.AreEqual(FHiddenRowCount, mainScreen.GetSelectedRowIndex(), "When the checkbox is checked the selected row should be {0}", FHiddenRowCount); // But the details should again be the same as before the checkbox check Assert.AreEqual(EffectiveCurrency(FFromCurrencyId), cmbFromCurrency.GetSelectedString(), "The From currency on row {0} should be {1}", FHiddenRowCount, EffectiveCurrency(FFromCurrencyId)); Assert.AreEqual(EffectiveCurrency(FToCurrencyId), cmbToCurrency.GetSelectedString(), "The To currency on row {0} should be {1}", FHiddenRowCount, EffectiveCurrency(FToCurrencyId)); Assert.AreEqual(EffectiveDate(), dtpEffectiveDate.Date, "The effective date on row {0} should be {1}", FHiddenRowCount, EffectiveDate().ToString()); mainScreen.Close(); }
/// <summary> /// Method to create and show the controls required for a particular code on the specified panel. /// Currently we support the following controls: /// txt -> TextBox, /// txt -> TTxtNumericTextBox with Format=Integer as the attribute, /// cmb -> TCmbAutoComplete: content is defined in OptionalValues column: Format=yes/no turns the combo into a tri-state choice /// where the OptionalValues do not have to be False and True because the result is yes or no based on SelectedIndex. /// dtp -> TtxtPetraDate /// </summary> /// <param name="AControlCode">The code that is a primary key into the controls table</param> /// <param name="AHostPanel">The panel onto which the GUI controls will be placed</param> /// <param name="AInitialValue">The initial value for this 'setting'. The value may be a comma separated list of values.</param> /// <param name="AReadOnly">Set to true to disable the control(s) or make them read-only as appropriate.</param> /// <param name="AValidationEventHandler">An event handler that will be called on validation</param> public void ShowControls(string AControlCode, Panel AHostPanel, string AInitialValue, bool AReadOnly, EventHandler AValidationEventHandler) { // Work out the PetraUtilsObject for the form that called us TFrmPetraUtils petraBase = ((IFrmPetra)AHostPanel.TopLevelControl).GetPetraUtilsObject(); FPetraUtilsObject = (petraBase is TFrmPetraEditUtils) ? (TFrmPetraEditUtils)petraBase : null; // Set up a default view on the controls table that will tell us the controls we need for this code FDataTable.DefaultView.RowFilter = string.Format("{0}='{1}'", FCodeColumn, AControlCode); FDataTable.DefaultView.Sort = string.Format("{0} ASC, {1} ASC", FCodeColumn, FControlIndexColumn); AHostPanel.AutoScroll = (FDataTable.DefaultView.Count > 1); AHostPanel.Controls.Clear(); // Work out the value(s) that have been passed in as a comma separated list StringCollection values = StringHelper.GetCSVList(AInitialValue, ",", true); if (values.Count != FDataTable.DefaultView.Count) { return; } FCurrentHostPanel = AHostPanel; int id = 0; int vPos = 5; int tabIndex = 10; foreach (DataRowView drv in FDataTable.DefaultView) { // get the attributes as a dictionary Dictionary <string, string> attributes = new Dictionary <string, string>(); object rowValue = drv.Row[FAttributesColumn]; if ((rowValue != null) && rowValue.ToString().Contains("=")) { string[] attPairs = drv.Row[FAttributesColumn].ToString().Split(','); foreach (string attPair in attPairs) { string[] att = attPair.Split('='); if (att.Length == 2) { attributes.Add(att[0].Trim(), att[1].Trim()); } } } // See if some of the popular attributes are defined and store their values in local variables string formatAttribute = string.Empty; string allowBlankAttribute = string.Empty; string stretchAttribute = string.Empty; int widthAttribute = -1; int labelWidthAttribute = -1; if (attributes.ContainsKey("Format")) { // Use lower case formatAttribute = attributes["Format"].ToString().ToLower(); } if (attributes.ContainsKey("Width")) { widthAttribute = Convert.ToInt32(attributes["Width"]); } if (attributes.ContainsKey("LabelWidth")) { labelWidthAttribute = Convert.ToInt32(attributes["LabelWidth"]); } if (attributes.ContainsKey("AllowBlankValue")) { allowBlankAttribute = attributes["AllowBlankValue"].ToString().ToLower(); } if (attributes.ContainsKey("Stretch")) { stretchAttribute = attributes["Stretch"].ToString().ToLower(); } // create the control label Label label = new Label(); label.Name = "cLabel_" + id.ToString(); label.Text = drv.Row[FLabelColumn].ToString() + ":"; label.Location = new Point(5, vPos); label.Size = new Size((labelWidthAttribute > 0) ? labelWidthAttribute : (AHostPanel.Width / 2) - 10, 17); label.TextAlign = ContentAlignment.MiddleRight; label.Anchor = AnchorStyles.Top | AnchorStyles.Left; AHostPanel.Controls.Add(label); // Create the control // We support text boxes, numeric (integer) text boxes, combo boxes and date boxes switch (drv.Row[FControlTypeColumn].ToString().Substring(0, 3)) { case "txt": if (formatAttribute == "integer") { TTxtNumericTextBox txt = new TTxtNumericTextBox(); txt.Context = AHostPanel; txt.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.Integer; txt.Name = "cValue_" + id.ToString(); txt.Location = new Point(label.Right + 10, vPos); txt.Size = new Size((widthAttribute > 0) ? widthAttribute : 100, 22); txt.TabStop = true; txt.TabIndex = tabIndex; int iValue; if (int.TryParse(values[id], out iValue)) { txt.NumberValueInt = iValue; } txt.ReadOnly = AReadOnly; txt.Validated += AValidationEventHandler; txt.TextChanged += new EventHandler(MultiChangeEventHandler); AHostPanel.Controls.Add(txt); } else { TextBox txt = new TextBox(); txt.Name = "cValue_" + id.ToString(); txt.Location = new Point(label.Right + 10, vPos); txt.Size = new Size((widthAttribute > 0) ? widthAttribute : AHostPanel.Width - label.Width - 25, 22); txt.TabStop = true; txt.TabIndex = tabIndex; txt.Text = values[id]; txt.ReadOnly = AReadOnly; if (stretchAttribute == "horizontally") { txt.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; } txt.Validated += AValidationEventHandler; txt.TextChanged += new EventHandler(MultiChangeEventHandler); AHostPanel.Controls.Add(txt); } break; case "cmb": if (attributes.ContainsKey("List")) { TCmbAutoPopulated cmb = new TCmbAutoPopulated(); cmb.Name = "cValue_" + id.ToString(); cmb.Location = new Point(label.Right + 10, vPos); cmb.Size = new Size((widthAttribute > 0) ? widthAttribute : AHostPanel.Width - label.Width - 25, 22); cmb.TabStop = true; cmb.TabIndex = tabIndex; cmb.ListTable = (TCmbAutoPopulated.TListTableEnum)Enum.Parse(typeof(TCmbAutoPopulated.TListTableEnum), attributes["List"].ToString(), true); cmb.InitialiseUserControl(); cmb.SetSelectedString(values[id], -1); cmb.Enabled = !AReadOnly; cmb.Validated += AValidationEventHandler; cmb.SelectedValueChanged += new EventHandler(MultiChangeEventHandler); AHostPanel.Controls.Add(cmb); } else { TCmbAutoComplete cmb = new TCmbAutoComplete(); cmb.Name = "cValue_" + id.ToString(); cmb.Location = new Point(label.Right + 10, vPos); cmb.Size = new Size((widthAttribute > 0) ? widthAttribute : AHostPanel.Width - label.Width - 25, 22); cmb.TabStop = true; cmb.TabIndex = tabIndex; if (drv.Row[FOptionalValuesColumn] != null) { string[] optValues = drv.Row[FOptionalValuesColumn].ToString().Split(','); for (int i = 0; i < optValues.Length; i++) { cmb.Items.Add(optValues[i].ToString().Trim()); } } if (formatAttribute == "yes/no") { cmb.SetSelectedYesNo(values[id]); cmb.Tag = "yes/no"; } else { cmb.Text = values[id]; } if (stretchAttribute == "horizontally") { cmb.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; } cmb.AllowBlankValue = (allowBlankAttribute == "true"); cmb.Enabled = !AReadOnly; cmb.Validated += AValidationEventHandler; cmb.SelectedIndexChanged += new EventHandler(MultiChangeEventHandler); cmb.TextChanged += new EventHandler(ComboBoxTextChangeEventHandler); AHostPanel.Controls.Add(cmb); } break; case "dtp": TtxtPetraDate dtp = new TtxtPetraDate(); dtp.Name = "cValue_" + id.ToString(); dtp.Location = new Point(label.Right + 10, vPos); dtp.Size = new Size(94, 22); dtp.TabStop = true; dtp.TabIndex = tabIndex; DateTime dt; if (DateTime.TryParse(values[id], out dt)) { dtp.Date = Convert.ToDateTime(values[id]); } else { dtp.Date = null; } dtp.ReadOnly = AReadOnly; dtp.Validated += AValidationEventHandler; dtp.DateChanged += new TPetraDateChangedEventHandler(MultiChangeEventHandler); AHostPanel.Controls.Add(dtp); break; default: break; } id++; tabIndex += 10; vPos += 30; } }
/// <summary> /// Handler for the ExchangeRateUsage1 test /// </summary> public void ExchangeRateUsageHandler() { FormTester formTester = new FormTester(FModalFormName); // Controls //ButtonTester btnNewTester = new ButtonTester("btnNew", FModalFormName); ButtonTester btnCloseTester = new ButtonTester("btnClose", FModalFormName); ButtonTester btnCancelTester = new ButtonTester("btnCancel", FModalFormName); TtxtPetraDate dtpDateEffective = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", FModalFormName)).Properties; TTxtNumericTextBox txtRateOfExchange = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", FModalFormName)).Properties; try { for (int i = 7; i > 0; i--) { SelectRowInGrid(i); string Usage = ((TFrmSetupDailyExchangeRate)formTester.Properties).Usage; Console.WriteLine("Grid row {0}: rate: {1}: {2}", i, txtRateOfExchange.NumberValueDecimal.Value.ToString(), Usage); // Usage is of form "Ledger:{0} Batch:{1} Journal:{2} Status:{3} at Rate:{4} on Date:{5} at Time:{6}" Assert.IsTrue(Usage.Contains("Ledger:9997"), "Expected a reference to Ledger #9997, but was: " + Usage); switch (i) { case 1: // 0.5225 Assert.IsTrue(Usage.ToLower().Contains( "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage); Assert.IsTrue(Usage.Contains("Batch:113"), "Expected a reference to Batch 113, but was: " + Usage); Assert.IsTrue(Usage.Contains("Journal:1"), "Expected a reference to Journal 1, but was: " + Usage); Assert.IsTrue(Usage.Contains("Rate:0.5225"), "Expected a reference to a rate of 0.5225, but was: " + Usage); Assert.IsTrue(Usage.Contains("Date:2000-10-30"), "Expected a reference to a date of 2000-10-30, but was: " + Usage); Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage); break; case 2: // 0.5225 Assert.IsTrue(Usage.ToLower().Contains( "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage); Assert.IsTrue(Usage.Contains("Batch:112"), "Expected a reference to Batch 112, but was: " + Usage); Assert.IsTrue(Usage.Contains("Journal:1"), "Expected a reference to Journal 1, but was: " + Usage); Assert.IsTrue(Usage.Contains("Rate:0.5225"), "Expected a reference to a rate of 0.5225, but was: " + Usage); Assert.IsTrue(Usage.Contains("Date:2000-10-26"), "Expected a reference to a date of 2000-10-26, but was: " + Usage); Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage); break; case 3: // 0.5225 Assert.IsTrue(Usage.ToLower().Contains( "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage); Assert.IsTrue(Usage.Contains("Batch:111"), "Expected a reference to Batch 111, but was: " + Usage); Assert.IsTrue(Usage.Contains("Journal:1"), "Expected a reference to Journal 1, but was: " + Usage); Assert.IsTrue(Usage.Contains("Rate:0.5225"), "Expected a reference to a rate of 0.5225, but was: " + Usage); Assert.IsTrue(Usage.Contains("Date:2000-10-22"), "Expected a reference to a date of 2000-10-22, but was: " + Usage); Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage); break; case 4: // 0.5225 Assert.IsTrue(Usage.ToLower().Contains( "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage); Assert.IsTrue(Usage.Contains("Batch:24"), "Expected a reference to Batch 24, but was: " + Usage); Assert.IsTrue(Usage.Contains("Journal:0"), "Expected a reference to Journal 0, but was: " + Usage); Assert.IsTrue(Usage.Contains("Rate:0.5225"), "Expected a reference to a rate of 0.5225, but was: " + Usage); Assert.IsTrue(Usage.Contains("Date:2000-10-15"), "Expected a reference to a date of 2000-10-15, but was: " + Usage); Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage); break; case 5: // 0.5225 Assert.IsTrue(Usage.ToLower().Contains( "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage); Assert.IsTrue(Usage.Contains("Batch:23"), "Expected a reference to Batch 23, but was: " + Usage); Assert.IsTrue(Usage.Contains("Journal:0"), "Expected a reference to Journal 0, but was: " + Usage); Assert.IsTrue(Usage.Contains("Rate:0.5225"), "Expected a reference to a rate of 0.5225, but was: " + Usage); Assert.IsTrue(Usage.Contains("Date:2000-10-09"), "Expected a reference to a date of 2000-10-09, but was: " + Usage); Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage); break; case 6: // 0.5225 Assert.IsTrue(Usage.ToLower().Contains( "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage); Assert.IsTrue(Usage.Contains("Batch:22"), "Expected a reference to Batch 22, but was: " + Usage); Assert.IsTrue(Usage.Contains("Journal:0"), "Expected a reference to Journal 0, but was: " + Usage); Assert.IsTrue(Usage.Contains("Rate:0.5225"), "Expected a reference to a rate of 0.5225, but was: " + Usage); Assert.IsTrue(Usage.Contains("Date:2000-10-05"), "Expected a reference to a date of 2000-10-05, but was: " + Usage); Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage); break; case 7: // 0.5155 Assert.IsTrue(Usage.ToLower().Contains( "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage); Assert.IsTrue(Usage.Contains("Batch:21"), "Expected a reference to Batch 22, but was: " + Usage); Assert.IsTrue(Usage.Contains("Rate:0.5155"), "Expected a reference to a rate of 0.5155, but was: " + Usage); Assert.IsTrue(Usage.Contains("Journal:0"), "Expected a reference to Journal 0, but was: " + Usage); Assert.IsTrue(Usage.Contains("Date:2000-10-01"), "Expected a reference to a date of 2000-10-01, but was: " + Usage); Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage); break; case 8: // 0.5155 Assert.IsTrue(Usage.ToLower().Contains( "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage); Assert.IsTrue(Usage.Contains("Batch:103"), "Expected a reference to Batch 103, but was: " + Usage); Assert.IsTrue(Usage.Contains("Journal:1"), "Expected a reference to Journal 1, but was: " + Usage); Assert.IsTrue(Usage.Contains("Rate:0.5155"), "Expected a reference to a rate of 0.5155, but was: " + Usage); Assert.IsTrue(Usage.Contains("Date:2000-08-28"), "Expected a reference to a date of 2000-08-28, but was: " + Usage); Assert.IsTrue(Usage.Contains("Time:60"), "Expected a reference to Time 60, but was: " + Usage); break; case 9: // 0.5155 Assert.IsTrue(Usage.ToLower().Contains( "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage); Assert.IsTrue(Usage.Contains("Batch:17"), "Expected a reference to Batch 17, but was: " + Usage); Assert.IsTrue(Usage.Contains("Journal:0"), "Expected a reference to Journal 0, but was: " + Usage); Assert.IsTrue(Usage.Contains("Rate:0.5155"), "Expected a reference to a rate of 0.5155, but was: " + Usage); Assert.IsTrue(Usage.Contains("Date:2000-08-28"), "Expected a reference to a date of 2000-08-28, but was: " + Usage); Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage); break; case 10: // 0.5155 Assert.IsTrue(Usage.ToLower().Contains( "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage); Assert.IsTrue(Usage.Contains("Batch:102"), "Expected a reference to Batch 102, but was: " + Usage); Assert.IsTrue(Usage.Contains("Journal:1"), "Expected a reference to Journal 1, but was: " + Usage); Assert.IsTrue(Usage.Contains("Rate:0.5155"), "Expected a reference to a rate of 0.5155, but was: " + Usage); Assert.IsTrue(Usage.Contains("Date:2000-08-08"), "Expected a reference to a date of 2000-08-08, but was: " + Usage); Assert.IsTrue(Usage.Contains("Time:60"), "Expected a reference to Time 60, but was: " + Usage); break; case 11: // 0.5155 Assert.IsTrue(Usage.ToLower().Contains("status:posted"), "Expected a posted row in Gift Batch table, but was: " + Usage); Assert.IsTrue(Usage.Contains("Batch:16"), "Expected a reference to Batch 16, but was: " + Usage); Assert.IsTrue(Usage.Contains("Journal:0"), "Expected a reference to Journal 0, but was: " + Usage); Assert.IsTrue(Usage.Contains("Rate:0.5155"), "Expected a reference to a rate of 0.5155, but was: " + Usage); Assert.IsTrue(Usage.Contains("Date:2000-08-08"), "Expected a reference to a date of 2000-08-08, but was: " + Usage); Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage); break; case 12: // 0.5155 Assert.IsTrue(Usage.ToLower().Contains( "status:unposted"), "Expected an unposted row in Gift Batch table, but was: " + Usage); Assert.IsTrue(Usage.Contains("Batch:101"), "Expected a reference to Batch 101, but was: " + Usage); Assert.IsTrue(Usage.Contains("Journal:1"), "Expected a reference to Journal 1, but was: " + Usage); Assert.IsTrue(Usage.Contains("Rate:0.5155"), "Expected a reference to a rate of 0.5155, but was: " + Usage); Assert.IsTrue(Usage.Contains("Date:2000-08-08"), "Expected a reference to a date of 2000-08-08, but was: " + Usage); Assert.IsTrue(Usage.Contains("Time:60"), "Expected a reference to Time 60, but was: " + Usage); break; case 13: // 0.5155 Assert.IsTrue(Usage.ToLower().Contains("status:posted"), "Expected a posted row in Gift Batch table, but was: " + Usage); Assert.IsTrue(Usage.Contains("Batch:15"), "Expected a reference to Batch 15, but was: " + Usage); Assert.IsTrue(Usage.Contains("Journal:0"), "Expected a reference to Journal 0, but was: " + Usage); Assert.IsTrue(Usage.Contains("Rate:0.5155"), "Expected a reference to a rate of 0.5155, but was: " + Usage); Assert.IsTrue(Usage.Contains("Date:2000-08-01"), "Expected a reference to a date of 2000-08-01, but was: " + Usage); Assert.IsTrue(Usage.Contains("Time:0"), "Expected a reference to Time 0, but was: " + Usage); break; default: break; } } btnCloseTester.Click(); } catch (Exception ex) { HandleModalException(ex); btnCancelTester.Properties.DialogResult = DialogResult.Abort; btnCancelTester.Click(); } }
/// <summary> /// Handler for the GiftBatchUsage test /// </summary> public void ModalValidationHandler() { // Controls ButtonTester btnNewTester = new ButtonTester("btnNew", FModalFormName); ButtonTester btnCloseTester = new ButtonTester("btnClose", FModalFormName); ButtonTester btnCancelTester = new ButtonTester("btnCancel", FModalFormName); TtxtPetraDate dtpDateEffective = (new TTxtPetraDateTester("dtpDetailDateEffectiveFrom", FModalFormName)).Properties; TTxtNumericTextBox txtRateOfExchange = (new TTxtNumericTextBoxTester("txtDetailRateOfExchange", FModalFormName)).Properties; try { // Create a new row and set the rate btnNewTester.Click(); txtRateOfExchange.NumberValueDecimal = 2.0m; string dlgText = String.Empty; bool dlgDisplayed = false; // Set up a popup handler ModalFormHandler = delegate(string name, IntPtr hWnd, Form form) { MessageBoxTester tester = new MessageBoxTester(hWnd); dlgText = tester.Text; dlgDisplayed = true; tester.SendCommand(MessageBoxTester.Command.OK); }; // Try setting the date to the day after the end and then clicking New dtpDateEffective.Date = FStandardEffectiveDate.AddDays(1.0); btnNewTester.Click(); Assert.IsTrue(dlgDisplayed, "The date chosen for the test should have raised a validation errror"); Assert.IsTrue(dlgText.Contains(CommonErrorCodes.ERR_DATENOTINDATERANGE)); // Set up another popup handler dlgText = String.Empty; dlgDisplayed = false; ModalFormHandler = delegate(string name, IntPtr hWnd, Form form) { MessageBoxTester tester = new MessageBoxTester(hWnd); dlgText = tester.Text; dlgDisplayed = true; tester.SendCommand(MessageBoxTester.Command.OK); }; // Try setting the date to the day before the start and then clicking New dtpDateEffective.Date = FStandardEffectiveDate.AddDays(-11.0); btnNewTester.Click(); Assert.IsTrue(dlgDisplayed, "The date chosen for the test should have raised a validation errror"); Assert.IsTrue(dlgText.Contains(CommonErrorCodes.ERR_DATENOTINDATERANGE)); // Set the date to a valid date and close (and save) dtpDateEffective.Date = FStandardEffectiveDate; btnCloseTester.Click(); } catch (Exception ex) { HandleModalException(ex); btnCancelTester.Properties.DialogResult = DialogResult.Abort; btnCancelTester.Click(); } }
private bool IsMatchingRowManual(DataRow ARow) { string invoiceNumber = ((TextBox)FFilterAndFindObject.FindPanelControls.FindControlByName("txtInvoiceNumber")).Text.ToLower(); if (invoiceNumber != String.Empty) { if (!ARow["DocumentCode"].ToString().ToLower().Contains(invoiceNumber)) { return(false); } } string supplierName = ((TextBox)FFilterAndFindObject.FindPanelControls.FindControlByName("txtSupplierName")).Text.ToLower(); if (supplierName != String.Empty) { if (!ARow["PartnerShortName"].ToString().ToLower().Contains(supplierName)) { return(false); } } DateTime dt; TtxtPetraDate fromDueDate = (TtxtPetraDate)FFilterAndFindObject.FindPanelControls.FindControlByName("dtpDueDate-1"); if ((fromDueDate.Text != String.Empty) && DateTime.TryParse(fromDueDate.Text, out dt)) { if (Convert.ToDateTime(ARow["DateDue"]) < dt.Date) { return(false); } } TtxtPetraDate toDueDate = (TtxtPetraDate)FFilterAndFindObject.FindPanelControls.FindControlByName("dtpDueDate-2"); if ((toDueDate.Text != String.Empty) && DateTime.TryParse(toDueDate.Text, out dt)) { if (Convert.ToDateTime(ARow["DateDue"]) > dt.Date) { return(false); } } TtxtPetraDate fromIssueDate = (TtxtPetraDate)FFilterAndFindObject.FindPanelControls.FindControlByName("dtpIssueDate-1"); if ((fromIssueDate.Text != String.Empty) && DateTime.TryParse(fromIssueDate.Text, out dt)) { if (Convert.ToDateTime(ARow["DateIssued"]) < dt.Date) { return(false); } } TtxtPetraDate toIssueDate = (TtxtPetraDate)FFilterAndFindObject.FindPanelControls.FindControlByName("dtpIssueDate-2"); if ((toIssueDate.Text != String.Empty) && DateTime.TryParse(toIssueDate.Text, out dt)) { if (Convert.ToDateTime(ARow["DateIssued"]) >= dt.Date) { return(false); } } return(true); }
/// <summary> /// Gets the value of the current state of the controls. If there are multiple controls the value will be a comma separated list. /// </summary> /// <returns>The value formatted as a string. If there are no controls the result will be an empty string. /// If there was an error in the database specification of the controls, the result will be an empty string /// If a control value is null we set the string representation to ? which can be validated by the client.</returns> public string GetCurrentValue() { string ReturnValue = ""; if (FCurrentHostPanel == null) { return(ReturnValue); } if (FCurrentHostPanel.Controls.Count == 0) { return(CONTROL_DEFINITION_ERROR); } for (int i = 0; i < FCurrentHostPanel.Controls.Count; i++) { Control control = FCurrentHostPanel.Controls[i]; if (control is Label) { continue; } if (control is TTxtNumericTextBox) { // Numeric text box returns ? if the entry is null TTxtNumericTextBox txt = (TTxtNumericTextBox)control; switch (txt.ControlMode) { case TTxtNumericTextBox.TNumericTextBoxMode.Integer: ReturnValue += ((txt.NumberValueInt.HasValue ? txt.NumberValueInt.ToString() : "?") + ","); break; default: break; } } else if (control is TextBox) { ReturnValue += (((TextBox)control).Text + ","); } if (control is TCmbAutoPopulated) { // Returns ? if the selected index is -1 TCmbAutoPopulated cmb = (TCmbAutoPopulated)control; string s = cmb.GetSelectedString(); ReturnValue += ((s.Length == 0 ? "?" : s) + ","); } if (control is TCmbAutoComplete) { TCmbAutoComplete cmb = (TCmbAutoComplete)control; if (Convert.ToString(control.Tag) == "yes/no") { ReturnValue += (cmb.GetSelectedYesNo() + ","); } else { // Returns ? if the selected index is -1 string s = cmb.GetSelectedString(); ReturnValue += ((s.Length == 0 ? "?" : s) + ","); } } if (control is TtxtPetraDate) { // Returns ? where the date value is null TtxtPetraDate txt = (TtxtPetraDate)control; ReturnValue += ((txt.Date.HasValue ? txt.Date.Value.ToString("yyyy-MM-dd") : "?") + ","); } } // Remove the trailing comma we added return(ReturnValue.Trim(',')); }