public void When_copying_record_will_create_new_object() { // Arrange var original_date = DateTime.Today; var original_unreconciled_amount = 12.34; var original_description = "Description"; var original_reconciled_amount = 56.78; var cred_card1_in_out_record = new CredCard1InOutRecord { Date = original_date, Unreconciled_amount = original_unreconciled_amount, Description = original_description, Reconciled_amount = original_reconciled_amount }; cred_card1_in_out_record.Update_source_line_for_output(','); var original_source_line = cred_card1_in_out_record.OutputSourceLine; // Act var copied_record = (CredCard1InOutRecord)cred_card1_in_out_record.Copy(); copied_record.Date = copied_record.Date.AddDays(1); copied_record.Unreconciled_amount = copied_record.Unreconciled_amount + 1; copied_record.Description = copied_record.Description + "something else"; copied_record.Reconciled_amount = copied_record.Reconciled_amount + 1; copied_record.Update_source_line_for_output(','); // Assert Assert.AreEqual(original_date, cred_card1_in_out_record.Date); Assert.AreEqual(original_unreconciled_amount, cred_card1_in_out_record.Unreconciled_amount); Assert.AreEqual(original_description, cred_card1_in_out_record.Description); Assert.AreEqual(original_reconciled_amount, cred_card1_in_out_record.Reconciled_amount); Assert.AreEqual(original_source_line, cred_card1_in_out_record.OutputSourceLine); }
public void Will_populate_zero_amounts_as_empty_cells_for_cred_card1_in_out_record() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord { Unreconciled_amount = 0, Reconciled_amount = 0 }; var cells = _spreadsheet.Current_cells("CredCard"); var last_row_number = _spreadsheet.Last_row_number("CredCard"); var previous_record = new CredCard1InOutRecord(); previous_record.Read_from_spreadsheet_row(_spreadsheet.Read_last_row("CredCard")); // Act cred_card1_in_out_record.Populate_spreadsheet_row(cells, last_row_number); var new_row = _spreadsheet.Read_last_row("CredCard"); // Assert Assert.AreEqual(null, new_row.Read_cell(1)); Assert.AreEqual(null, new_row.Read_cell(4)); // Clean up previous_record.Populate_spreadsheet_row(cells, last_row_number); }
public void Will_populate_cred_card1_in_out_record_cells() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord { Date = new DateTime(year: 2017, month: 4, day: 1), Unreconciled_amount = 22.22, Description = "New description which will overwrite what's normally there.", Reconciled_amount = 9999.56 }; var cells = _spreadsheet.Current_cells("CredCard"); var last_row_number = _spreadsheet.Last_row_number("CredCard"); var previous_record = new CredCard1InOutRecord(); previous_record.Read_from_spreadsheet_row(_spreadsheet.Read_last_row("CredCard")); // Act cred_card1_in_out_record.Populate_spreadsheet_row(cells, last_row_number); var new_row = _spreadsheet.Read_last_row("CredCard"); // Assert Assert.AreEqual(cred_card1_in_out_record.Date, DateTime.FromOADate((double)new_row.Read_cell(0))); Assert.AreEqual(cred_card1_in_out_record.Unreconciled_amount, (Double)new_row.Read_cell(1)); Assert.AreEqual(cred_card1_in_out_record.Description, (String)new_row.Read_cell(3)); Assert.AreEqual(cred_card1_in_out_record.Reconciled_amount, (Double)new_row.Read_cell(4)); // Clean up previous_record.Populate_spreadsheet_row(cells, last_row_number); }
public void Can_delete_specified_rows() { // Arrange var sheet_name = TestSheetNames.Cred_card; var test_record = new CredCard1InOutRecord(); string csv_line = String.Format("19/12/2016^£12.34^^Bantams^£33.44^"); test_record.Load(csv_line); var last_row = new CredCard1InOutRecord(); string expected_last_row = "27/04/2018,£5.10,,\"pintipoplication\",\"£10,567.89\","; var initial_last_row_number = _excelSpreadsheet.Last_row_number(sheet_name); _excelSpreadsheet.Append_csv_record(sheet_name, test_record); _excelSpreadsheet.Append_csv_record(sheet_name, test_record); // Act _excelSpreadsheet.Delete_specified_rows(sheet_name, 12, 13); // Assert var new_last_row = _excelSpreadsheet.Read_last_row_as_csv(sheet_name, last_row); var new_last_row_number = _excelSpreadsheet.Last_row_number(sheet_name); Assert.AreEqual(new_last_row_number, initial_last_row_number); Assert.AreEqual(expected_last_row, new_last_row); }
public void Will_append_csv_record_to_specified_worksheet() { // Arrange var sheet_name = TestSheetNames.Cred_card1; var cred_card1_in_out_record = new CredCard1InOutRecord { Date = new DateTime(year: 2017, month: 4, day: 19), Unreconciled_amount = 1234.56, Matched = true, Description = "description", Reconciled_amount = 356.29 }; var initial_last_row_number = _excelSpreadsheet.Last_row_number(sheet_name); // Act _excelSpreadsheet.Append_csv_record(sheet_name, cred_card1_in_out_record); var new_row = _excelSpreadsheet.Read_last_row(sheet_name); var new_row_number = _excelSpreadsheet.Last_row_number(sheet_name); // Clean up _excelSpreadsheet.Remove_last_row(sheet_name); // Assert Assert.AreEqual(cred_card1_in_out_record.Date, DateTime.FromOADate((double)new_row.Read_cell(CredCard1InOutRecord.DateIndex))); Assert.AreEqual(cred_card1_in_out_record.Unreconciled_amount, (Double)new_row.Read_cell(CredCard1InOutRecord.UnreconciledAmountIndex)); Assert.AreEqual("x", (String)new_row.Read_cell(CredCard1InOutRecord.MatchedIndex)); Assert.AreEqual(cred_card1_in_out_record.Description, (String)new_row.Read_cell(CredCard1InOutRecord.DescriptionIndex)); Assert.AreEqual(cred_card1_in_out_record.Reconciled_amount, (Double)new_row.Read_cell(CredCard1InOutRecord.ReconciledAmountIndex)); Assert.AreEqual(initial_last_row_number + 1, new_row_number); }
private void Assert_direct_debit_details_are_correct( CredCard1InOutRecord cred_card1_in_out_record, DateTime expected_date, double expected_amount, string expected_description) { Assert.AreEqual(expected_description, cred_card1_in_out_record.Description); Assert.AreEqual(expected_date, cred_card1_in_out_record.Date); Assert.AreEqual(expected_amount, cred_card1_in_out_record.Unreconciled_amount); }
public void Should_be_able_to_cope_with_empty_input() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); string csv_line = String.Empty; // Act cred_card1_in_out_record.Load(csv_line); // Assert Assert.AreEqual(0, cred_card1_in_out_record.Reconciled_amount); }
public void Will_add_default_description_if_description_is_unpopulated() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); string csv_line = "19/12/2016^£123.55^^^"; // Act cred_card1_in_out_record.Load(csv_line); // Assert Assert.AreEqual("Source record had no description", cred_card1_in_out_record.Description); }
public void Can_read_amount_containing_comma_from_csv() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); string csv_line = "19/12/2016^£5,678.99^^ZZZSpecialDescription017^"; // Act cred_card1_in_out_record.Load(csv_line); // Assert Assert.AreEqual(5678.99, cred_card1_in_out_record.Unreconciled_amount); }
public void Can_cope_with_empty_reconciled_amount() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); string csv_line = String.Format("19/12/2016^£7.99^^ZZZSpecialDescription017^"); // Act cred_card1_in_out_record.Load(csv_line); // Assert Assert.AreEqual(0, cred_card1_in_out_record.Reconciled_amount); }
public void M_WhenAddingAnnualBudgetedDataToSpreadsheet_WillOrderResultsByDate() { // Arrange var budget_item_list_data = new BudgetItemListData { Sheet_name = MainSheetNames.Budget_out, Start_divider = Dividers.Cred_card1, End_divider = Dividers.Cred_card2, First_column_number = 2, Last_column_number = 5 }; var first_month = 12; var last_month = 3; var mock_spreadsheet_repo = new Mock <ISpreadsheetRepo>(); var budget_data_setup = When_adding_budgeted_data_to_spreadsheet <CredCard1InOutRecord>( first_month, last_month, mock_spreadsheet_repo, budget_item_list_data); var mock_cred_card1_in_out_file_io = new Mock <IFileIO <CredCard1InOutRecord> >(); mock_cred_card1_in_out_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)) .Returns(new List <CredCard1InOutRecord> { new CredCard1InOutRecord { Date = new DateTime(budget_data_setup.BudgetingMonths.Start_year, first_month, 10) }, new CredCard1InOutRecord { Date = new DateTime(budget_data_setup.BudgetingMonths.Start_year, first_month, 4) }, new CredCard1InOutRecord { Date = new DateTime(budget_data_setup.BudgetingMonths.Start_year, first_month, 25) } }); var pending_file = new CSVFile <CredCard1InOutRecord>(mock_cred_card1_in_out_file_io.Object); pending_file.Load(); var spreadsheet = new Spreadsheet(mock_spreadsheet_repo.Object); // Act spreadsheet.Add_budgeted_annual_data_to_pending_file(budget_data_setup.BudgetingMonths, pending_file, budget_item_list_data); // Assert CredCard1InOutRecord previous_record = null; foreach (CredCard1InOutRecord record in pending_file.Records) { if (null != previous_record) { Assert.IsTrue(record.Date.ToOADate() > previous_record.Date.ToOADate()); } previous_record = record; } }
public void Can_read_last_row_of_worksheet_as_csv() { // Arrange var cred_card1_record = new CredCard1InOutRecord(); string expected_csv = "27/04/2018,£5.10,,\"pintipoplication\",\"£10,567.89\","; // Act var result = _excelSpreadsheet.Read_last_row_as_csv(TestSheetNames.Cred_card, cred_card1_record); // Assert Assert.AreEqual(expected_csv, result); }
public void Can_cope_with_bad_unreconciled_amount() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); var bad_amount = "not an amount"; string csv_line = String.Format("19/12/2016^{0}^^ZZZSpecialDescription017^", bad_amount); // Act cred_card1_in_out_record.Load(csv_line); // Assert Assert.AreEqual(0, cred_card1_in_out_record.Unreconciled_amount); }
public void Can_cope_with_empty_date() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); var expected_date = new DateTime(9999, 9, 9); string csv_line = String.Format("^£7.99^^ZZZSpecialDescription017^"); // Act cred_card1_in_out_record.Load(csv_line); // Assert Assert.AreEqual(expected_date, cred_card1_in_out_record.Date); }
public void Will_populate_source_line_when_reading_from_cred_card1_in_out_record_cells() { // Arrange String expected_source_line = String.Format("27/04/2018^£5.10^^pintipoplication^\"£10,567.89\"^"); var cred_card1_in_out_record = new CredCard1InOutRecord(); var cells = _spreadsheet.Read_last_row("CredCard"); // Act cred_card1_in_out_record.Read_from_spreadsheet_row(cells); // Assert Assert.AreEqual(expected_source_line, cred_card1_in_out_record.OutputSourceLine); }
public void Should_be_able_to_read_negative_amounts() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); var negative_amount = "-£123.55"; string csv_line = String.Format("19/12/2016^^^ZZZSpecialDescription017^{0}", negative_amount); // Act cred_card1_in_out_record.Load(csv_line); // Assert Assert.AreEqual(-123.55, cred_card1_in_out_record.Reconciled_amount); }
public void Can_read_description_from_csv() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); var expected_description = "ZZZSpecialDescription017"; string csv_line = String.Format("19/12/2016^£7.99^^{0}^", expected_description); // Act cred_card1_in_out_record.Load(csv_line); // Assert Assert.AreEqual(expected_description, cred_card1_in_out_record.Description); }
public void Should_be_able_to_read_amounts_preceded_by_pound_signs() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); var amount_with_pound_sign = "£1,234.55"; string csv_line = String.Format("19/12/2016^{0}^^ZZZSpecialDescription017^", amount_with_pound_sign); // Act cred_card1_in_out_record.Load(csv_line); // Assert Assert.AreEqual(1234.55, cred_card1_in_out_record.Unreconciled_amount); }
public void Should_be_able_to_read_reconciled_amounts_containing_commas() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); var amount_containing_comma = "£1,234.55"; string csv_line = String.Format("19/12/2016^^^ZZZSpecialDescription017^{0}", amount_containing_comma); // Act cred_card1_in_out_record.Load(csv_line); // Assert Assert.AreEqual(1234.55, cred_card1_in_out_record.Reconciled_amount); }
public void Can_read_reconciled_amount_from_csv() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); var expected_amount = 238.92; string input_amount = "£" + expected_amount; string csv_line = String.Format("19/12/2016^£7.99^^ZZZSpecialDescription017^{0}", input_amount); // Act cred_card1_in_out_record.Load(csv_line); // Assert Assert.AreEqual(expected_amount, cred_card1_in_out_record.Reconciled_amount); }
public void Can_read_date_from_csv() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); string expected_date_as_string = "19/12/2016"; string csv_line = String.Format("{0}^£7.99^^ZZZSpecialDescription017^", expected_date_as_string); var expected_date = Convert.ToDateTime(expected_date_as_string, StringHelper.Culture()); // Act cred_card1_in_out_record.Load(csv_line); // Assert Assert.AreEqual(expected_date, cred_card1_in_out_record.Date); }
public void Can_read_amount_surrounded_by_quotes_from_csv() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); double expected_amount = 7888.99; string input_amount = "£" + expected_amount; string csv_line = String.Format("19/12/2016^\"{0}\"^^ZZZSpecialDescription017^", input_amount); // Act cred_card1_in_out_record.Load(csv_line); // Assert Assert.AreEqual(expected_amount, cred_card1_in_out_record.Unreconciled_amount); }
public void Csv_is_constructed_correctly_without_matched_record() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); string csv_line = String.Format("19/12/2016^£12.34^^Bantams^£33.44^"); cred_card1_in_out_record.Load(csv_line); cred_card1_in_out_record.Matched = false; // Act string constructed_csv_line = cred_card1_in_out_record.To_csv(); // Assert Assert.AreEqual("19/12/2016,£12.34,,\"Bantams\",£33.44,", constructed_csv_line); }
public void Empty_fields_are_output_as_nothing_for_csv() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); string csv_line = String.Format("19/12/2016^^^Bantams^^"); cred_card1_in_out_record.Load(csv_line); cred_card1_in_out_record.Matched = false; // Act string constructed_csv_line = cred_card1_in_out_record.To_csv(); // Assert Assert.AreEqual("19/12/2016,,,\"Bantams\",,", constructed_csv_line); }
public void Can_cope_with_input_containing_commas_preceded_by_spaces() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); double expected_amount = 12.35; string input_amount = "£" + expected_amount; string text_containing_commas = "something ,something ,something else"; string csv_line = String.Format("19/12/2016^^^{0}^{1}", text_containing_commas, input_amount); // Act cred_card1_in_out_record.Load(csv_line); // Assert Assert.AreEqual(expected_amount, cred_card1_in_out_record.Reconciled_amount); }
public void Can_make_main_amount_positive() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); var negative_amount = -23.23; string input_amount = "-£" + negative_amount * -1; string csv_line = String.Format("19/12/2016^{0}^^ZZZSpecialDescription017^", input_amount); cred_card1_in_out_record.Load(csv_line); // Act cred_card1_in_out_record.Make_main_amount_positive(); // Assert Assert.AreEqual(negative_amount * -1, cred_card1_in_out_record.Unreconciled_amount); }
public void If_main_amount_already_positive_then_making_it_positive_has_no_effect() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); var positive_amount = 23.23; string input_amount = "£" + positive_amount; string csv_line = String.Format("19/12/2016^{0}^^ZZZSpecialDescription017^", input_amount); cred_card1_in_out_record.Load(csv_line); // Act cred_card1_in_out_record.Make_main_amount_positive(); // Assert Assert.AreEqual(positive_amount, cred_card1_in_out_record.Unreconciled_amount); }
public void Amounts_containing_commas_should_be_encased_in_quotes() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); var amount_containing_comma = "£1,234.55"; string csv_line = String.Format("19/12/2016^{0}^^Bantams^", amount_containing_comma); cred_card1_in_out_record.Load(csv_line); // Act string constructed_csv_line = cred_card1_in_out_record.To_csv(); // Assert string expected_csv_line = String.Format("19/12/2016,\"{0}\",,\"Bantams\",,", amount_containing_comma); Assert.AreEqual(expected_csv_line, constructed_csv_line); }
public void Amounts_should_be_written_using_pound_signs() { // Arrange var cred_card1_in_out_record = new CredCard1InOutRecord(); var amount_with_pound_sign = "£123.55"; string csv_line = String.Format("19/12/2016^{0}^^Bantams^", amount_with_pound_sign); cred_card1_in_out_record.Load(csv_line); // Act string constructed_csv_line = cred_card1_in_out_record.To_csv(); // Assert string expected_csv_line = String.Format("19/12/2016,{0},,\"Bantams\",,", amount_with_pound_sign); Assert.AreEqual(expected_csv_line, constructed_csv_line); }
public void Will_read_from_cells_when_there_is_a_null_reconciled_amount_on_cred_card1_in_out_record() { // Arrange DateTime expected_date = new DateTime(year: 2018, month: 4, day: 25); Double expected_unreconciled_amount = 4.90; String expected_description = "pintipoplication"; Double expected_reconciled_amount = 0; var cred_card1_in_out_record = new CredCard1InOutRecord(); var cells = _spreadsheet.Read_specified_row("CredCard", 8); // Act cred_card1_in_out_record.Read_from_spreadsheet_row(cells); // Assert Assert.AreEqual(expected_date, cred_card1_in_out_record.Date); Assert.AreEqual(expected_unreconciled_amount, cred_card1_in_out_record.Unreconciled_amount); Assert.AreEqual(expected_description, cred_card1_in_out_record.Description); Assert.AreEqual(expected_reconciled_amount, cred_card1_in_out_record.Reconciled_amount); }