public void ModalValidation() { FMainDS.LoadAll(); FMainDS.DeleteAllRows(); FMainDS.SaveChanges(); FLedgerDS.CreateTestLedger(); decimal selectedRate; DateTime selectedDate; int selectedTime; // Open the screen modally on our test ledger and a from currency of GBP // This test sets up a date range TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null); DialogBoxHandler = delegate(string name, IntPtr hWnd) { ModalValidationHandler(); }; DialogResult dlgResult = mainScreen.ShowDialog(STANDARD_TEST_LEDGER_NUMBER, FStandardEffectiveDate.AddDays( -10), FStandardEffectiveDate, "GBP", 1.0m, out selectedRate, out selectedDate, out selectedTime); if (dlgResult == DialogResult.Abort) { Assert.Fail(FModalAssertResult); } // Make sure we did save Assert.AreEqual(DialogResult.OK, dlgResult); Assert.IsFalse((new ToolStripButtonTester("tbbSave", mainScreen)).Properties.Enabled); FMainDS.LoadAll(); Assert.AreEqual(2, FMainDS.ADailyExchangeRate.Rows.Count, "The data table should have 2 rows after a successful save operation"); }
public void LoadModalEmptyTable() { // Initialise data - create an empty table and our test ledger FMainDS.LoadAll(); FMainDS.DeleteAllRows(); FMainDS.SaveChanges(); FLedgerDS.CreateTestLedger(); // variables to hold the dialog result output decimal selectedRate; DateTime selectedDate; int selectedTime; // Open the screen modally on our test ledger using a 'from' currency of GBP TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null); DialogBoxHandler = delegate(string name, IntPtr hWnd) { LoadModalEmptyTableHandler(); }; DialogResult dlgResult = mainScreen.ShowDialog(STANDARD_TEST_LEDGER_NUMBER, FStandardEffectiveDate, "GBP", 1.0m, out selectedRate, out selectedDate, out selectedTime); // Check the result for any assertions if (dlgResult == DialogResult.Abort) { Assert.Fail(FModalAssertResult); } // Check we returned the correct data to the caller Assert.AreEqual(DialogResult.OK, dlgResult); Assert.AreEqual(STANDARD_RATE_OF_EXCHANGE, selectedRate); Assert.AreEqual(FStandardEffectiveDate, selectedDate); Assert.AreEqual(7200, selectedTime); // Check we did also save the result FMainDS.LoadAll(); ADailyExchangeRateRow row = (ADailyExchangeRateRow)FMainDS.ADailyExchangeRate.Rows.Find(new object[] { "GBP", STANDARD_TEST_CURRENCY, FStandardEffectiveDate, 7200 }); Assert.IsNotNull(row, "The selected exchange rate was not saved"); Assert.AreEqual(STANDARD_RATE_OF_EXCHANGE, row.RateOfExchange); }
public static void DeleteTestLedgerIfExists() { if (FLedgerDS.ALedger == null) { // we did not create one yet return; } DataView dv = new DataView(FLedgerDS.ALedger, "a_ledger_number_i=" + STANDARD_TEST_LEDGER_NUMBER.ToString(), null, DataViewRowState.CurrentRows); if (dv.Count > 0) { // exists already DataRowView row = dv[0]; row.Delete(); FLedgerDS.SaveChanges(); } }
public void LoadModalTableWithData() { // Initialse data FMainDS.LoadAll(); FMainDS.DeleteAllRows(); FMainDS.InsertStandardModalRows(); FMainDS.SaveChanges(); FLedgerDS.CreateTestLedger(); decimal selectedRate; DateTime selectedDate; int selectedTime; // Open the screen modally on our test ledger and a from currency of GBP TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null); DialogBoxHandler = delegate(string name, IntPtr hWnd) { LoadModalTableHandler(); }; DialogResult dlgResult = mainScreen.ShowDialog(STANDARD_TEST_LEDGER_NUMBER, FStandardEffectiveDate, "GBP", 1.0m, out selectedRate, out selectedDate, out selectedTime); if (dlgResult == DialogResult.Abort) { Assert.Fail(FModalAssertResult); } Assert.AreEqual(DialogResult.OK, dlgResult); Assert.AreEqual(new DateTime(1900, 7, 1), selectedDate); Assert.AreEqual(0.51m, selectedRate); }
public void GetRateForDate() { // First test is with empty data FMainDS.LoadAll(); FMainDS.DeleteAllRows(); FMainDS.SaveChanges(); FLedgerDS.CreateTestLedger(); // define our working date range DateTime dtStart = new DateTime(2000, 01, 01); DateTime dtEnd = new DateTime(2000, 12, 31); // First test is with empty data - should return 1.0m TFrmSetupDailyExchangeRate mainScreen = new TFrmSetupDailyExchangeRate(null); decimal result = mainScreen.GetLastExchangeValueOfInterval(STANDARD_TEST_LEDGER_NUMBER, dtStart, dtEnd, "GBP"); Assert.AreEqual(1.0m, result, "The result should be 1.0m when the table contains no data"); // Repeat test with data but outside the date range - again should return 1.0m FMainDS.InsertStandardModalRows(); FMainDS.SaveChanges(); mainScreen = new TFrmSetupDailyExchangeRate(null); result = mainScreen.GetLastExchangeValueOfInterval(STANDARD_TEST_LEDGER_NUMBER, dtStart, dtEnd, "GBP"); Assert.AreEqual(1.0m, result, "The result should be 1.0m because there is no data in the date range"); // Repeat again with data inside the range FMainDS.AddARow("GBP", STANDARD_TEST_CURRENCY, new DateTime(2000, 6, 1), 2.0m); FMainDS.AddARow("GBP", STANDARD_TEST_CURRENCY, new DateTime(2000, 6, 10), 2.05m); FMainDS.AddARow("GBP", STANDARD_TEST_CURRENCY, new DateTime(2000, 6, 30), 2.15m); // This is the latest FMainDS.AddARow("GBP", STANDARD_TEST_CURRENCY, new DateTime(2000, 6, 20), 2.10m); FMainDS.SaveChanges(); mainScreen = new TFrmSetupDailyExchangeRate(null); result = mainScreen.GetLastExchangeValueOfInterval(STANDARD_TEST_LEDGER_NUMBER, dtStart, dtEnd, "GBP"); Assert.AreEqual(2.15m, result); }
public static void CreateTestLedger() { FLedgerDS.LoadAll(); DataView dv = new DataView(FLedgerDS.ALedger, "a_ledger_number_i=" + STANDARD_TEST_LEDGER_NUMBER.ToString(), null, DataViewRowState.CurrentRows); if (dv.Count > 0) { // exists already return; } int NewLedgerNumber = STANDARD_TEST_LEDGER_NUMBER; ALedgerRow newRow = FLedgerDS.ALedger.NewRowTyped(true); newRow.LedgerNumber = NewLedgerNumber; newRow.LedgerName = "TestLedger"; newRow.BaseCurrency = STANDARD_TEST_CURRENCY; newRow.ForexGainsLossesAccount = "Trash"; newRow.PartnerKey = NewLedgerNumber * 10000; FLedgerDS.ALedger.Rows.Add(newRow); FLedgerDS.SaveChanges(); }