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 M_WhenAddingAnnualBudgetedDataToSpreadsheet_WillAdjustDayIfDaysInMonthIsTooLow() { // Arrange var budget_item_list_data = new BudgetItemListData { Sheet_name = MainSheetNames.Budget_in, Start_divider = Dividers.Date, End_divider = Dividers.Total, First_column_number = 2, Last_column_number = 6 }; var first_month = 12; var last_month = 2; var mock_spreadsheet_repo = new Mock <ISpreadsheetRepo>(); var budget_data_setup = When_adding_budgeted_data_to_spreadsheet <BankRecord>( first_month, last_month, mock_spreadsheet_repo, budget_item_list_data, default_day: 31); var pending_file_records = new List <BankRecord>(); var mock_pending_file = new Mock <ICSVFile <BankRecord> >(); mock_pending_file.Setup(x => x.Records).Returns(pending_file_records); var spreadsheet = new Spreadsheet(mock_spreadsheet_repo.Object); bool exception_thrown = false; // Act try { spreadsheet.Add_budgeted_annual_data_to_pending_file(budget_data_setup.BudgetingMonths, mock_pending_file.Object, budget_item_list_data); } catch (Exception) { exception_thrown = true; } // Assert Assert.IsFalse(exception_thrown); }
public void M_WhenAddingBudgetedBankOutDataToSpreadsheet_WillAddAnnualBankOutTransactionsToPendingFile_IfMonthMatchesBudgetingMonths( int first_month, int last_month) { // Arrange var annual_budget_item_list_data = new BudgetItemListData { Sheet_name = MainSheetNames.Budget_out, Start_divider = Dividers.Annual_sodds, End_divider = Dividers.Annual_total, First_column_number = 2, Last_column_number = 6 }; var mock_spreadsheet_repo = new Mock <ISpreadsheetRepo>(); var first_annual_row = 10; var last_annual_row = first_annual_row + 2; string desc1 = "annual record with matching month"; string desc2 = "other annual record with matching month"; string desc3 = "annual record with non-matching month"; var annual_bank_records = new List <BankRecord> { new BankRecord { Date = new DateTime(2018, first_month, 1), Description = desc1 }, new BankRecord { Date = new DateTime(2018, last_month, 1), Description = desc2 }, new BankRecord { Date = new DateTime(2018, last_month + 2, 1), Description = desc3 } }; mock_spreadsheet_repo.Setup(x => x.Find_row_number_of_last_row_containing_cell(annual_budget_item_list_data.Sheet_name, annual_budget_item_list_data.Start_divider, 2)).Returns(first_annual_row); mock_spreadsheet_repo.Setup(x => x.Find_row_number_of_last_row_containing_cell(annual_budget_item_list_data.Sheet_name, annual_budget_item_list_data.End_divider, 2)).Returns(last_annual_row); mock_spreadsheet_repo.Setup(x => x.Get_rows_as_records <BankRecord>(annual_budget_item_list_data.Sheet_name, first_annual_row + 1, last_annual_row - 1, annual_budget_item_list_data.First_column_number, annual_budget_item_list_data.Last_column_number)).Returns(annual_bank_records); // Everything else: var budgeting_months = new BudgetingMonths { Next_unplanned_month = first_month, Last_month_for_budget_planning = last_month, Start_year = 2018 }; var pending_file_records = new List <BankRecord>(); var mock_pending_file = new Mock <ICSVFile <BankRecord> >(); mock_pending_file.Setup(x => x.Records).Returns(pending_file_records); var spreadsheet = new Spreadsheet(mock_spreadsheet_repo.Object); // Act spreadsheet.Add_budgeted_annual_data_to_pending_file(budgeting_months, mock_pending_file.Object, annual_budget_item_list_data); // Assert Assert.AreEqual(2, pending_file_records.Count, "total num records"); Assert.AreEqual(1, pending_file_records.Count(x => x.Description == desc1), "num repetitions of matching record"); Assert.AreEqual(1, pending_file_records.Count(x => x.Description == desc2), "num repetitions of other matching record"); Assert.AreEqual(0, pending_file_records.Count(x => x.Description == desc3), "num repetitions of non-matching record"); var expected_record2_year = last_month >= first_month ? budgeting_months.Start_year : budgeting_months.Start_year + 1; Assert.AreEqual(expected_record2_year, pending_file_records[1].Date.Year); }