public void M_MergeBespokeDataWithPendingFile_WillUpdateCredCard2BalancesOnTotalsSheet()
        {
            // Arrange
            TestHelper.Set_correct_date_formatting();
            var      mock_input_output        = new Mock <IInputOutput>();
            double   new_balance              = 5673.99;
            DateTime last_direct_debit_date   = new DateTime(2018, 12, 17);
            var      next_direct_debit_date01 = last_direct_debit_date.AddMonths(1);
            var      next_direct_debit_date02 = last_direct_debit_date.AddMonths(2);

            mock_input_output
            .Setup(x => x.Get_input(
                       string.Format(
                           ReconConsts.AskForCredCardDirectDebit,
                           ReconConsts.Cred_card2_name,
                           next_direct_debit_date01.ToShortDateString()), ""))
            .Returns(new_balance.ToString);
            mock_input_output
            .Setup(x => x.Get_input(
                       string.Format(
                           ReconConsts.AskForCredCardDirectDebit,
                           ReconConsts.Cred_card2_name,
                           next_direct_debit_date02.ToShortDateString()), ""))
            .Returns("0");
            var bank_record = new BankRecord {
                Date = last_direct_debit_date
            };
            var mock_spreadsheet = new Mock <ISpreadsheet>();

            mock_spreadsheet.Setup(x => x.Get_most_recent_row_containing_text <BankRecord>(
                                       MainSheetNames.Bank_out, ReconConsts.Cred_card2_dd_description, new List <int> {
                ReconConsts.DescriptionColumn, ReconConsts.DdDescriptionColumn
            }))
            .Returns(bank_record);
            var mock_pending_file = new Mock <ICSVFile <CredCard2InOutRecord> >();
            var pending_records   = new List <CredCard2InOutRecord>();

            mock_pending_file.Setup(x => x.Records).Returns(pending_records);
            var budgeting_months = new BudgetingMonths();
            var loading_info     = new CredCard2AndCredCard2InOutLoader().Loading_info();
            var cred_card2_and_cred_card2_in_out_loader = new CredCard2AndCredCard2InOutLoader();

            // Act
            cred_card2_and_cred_card2_in_out_loader.Merge_bespoke_data_with_pending_file(
                mock_input_output.Object,
                mock_spreadsheet.Object,
                mock_pending_file.Object,
                budgeting_months,
                loading_info);

            // Assert
            mock_spreadsheet.Verify(x => x.Update_balance_on_totals_sheet(
                                        Codes.Cred_card2_bal,
                                        new_balance * -1,
                                        string.Format(
                                            ReconConsts.CredCardBalanceDescription,
                                            ReconConsts.Cred_card2_name,
                                            $"{last_direct_debit_date.ToString("MMM")} {last_direct_debit_date.Year}"),
                                        5, 6, 4, mock_input_output.Object), Times.Exactly(1));
        }
コード例 #2
0
        private void Assert_WillAddAllMonthlyItemsToPendingFile_WithMonthsAndYearsChanged <TRecordType>(
            int first_month,
            int last_month,
            int monthly_record_count,
            List <TRecordType> pending_file_records,
            BudgetingMonths budgeting_months,
            string desc1,
            string desc2) where TRecordType : ICSVRecord, new()
        {
            // Arrange
            var num_repetitions = last_month >= first_month
                ? (last_month - first_month) + 1
                : ((last_month + 12) - first_month) + 1;
            var total_records = num_repetitions * monthly_record_count;

            // Assert
            Assert.AreEqual(total_records, pending_file_records.Count, "total num records");
            Assert.AreEqual(num_repetitions, pending_file_records.Count(x => x.Description == desc1), "num repetitions of desc1");
            Assert.AreEqual(num_repetitions, pending_file_records.Count(x => x.Description == desc2), "num repetitions of desc2");
            var desc1_records = pending_file_records.Where(x => x.Description == desc1)
                                .OrderBy(x => x.Date).ToList();
            int index       = 0;
            int final_month = last_month >= first_month ? last_month : last_month + 12;

            for (int month = first_month; month <= final_month; month++)
            {
                var expected_month = month <= 12 ? month : month - 12;
                var expected_year  = month <= 12 ? budgeting_months.Start_year : budgeting_months.Start_year + 1;
                Assert.AreEqual(expected_month, desc1_records[index].Date.Month, "correct month");
                Assert.AreEqual(expected_year, desc1_records[index].Date.Year, "correct year");
                index++;
            }
        }
コード例 #3
0
        public void Will_not_update_any_amounts_when_generating_ad_hoc_data_if_user_wants_no_expected_out_budgeting()
        {
            // Arrange
            var bank_and_bank_out_loader = new BankAndBankOutLoader();
            var mock_spreadsheet         = new Mock <ISpreadsheet>();
            var budgeting_months         = new BudgetingMonths
            {
                Start_year                     = 2020,
                Next_unplanned_month           = 6,
                Last_month_for_budget_planning = 6,
                Do_expected_out_budgeting      = false
            };

            // Act
            bank_and_bank_out_loader.Generate_ad_hoc_data(
                new Mock <IInputOutput>().Object,
                mock_spreadsheet.Object,
                new Mock <ICSVFile <BankRecord> >().Object,
                budgeting_months,
                new DataLoadingInformation <ActualBankRecord, BankRecord>()
                );

            // Assert
            mock_spreadsheet.Verify(x => x.Update_owed_CHB(It.IsAny <BudgetingMonths>()), Times.Never);
            mock_spreadsheet.Verify(x => x.Update_expected_out(
                                        It.IsAny <int>(),
                                        It.IsAny <string>(),
                                        It.IsAny <string>()), Times.Never);
        }
コード例 #4
0
        Load <TThirdPartyType, TOwnedType>(
            ISpreadsheet spreadsheet,
            IFileIO <TOwnedType> pending_file_io,
            ICSVFile <TOwnedType> pending_file,
            IFileIO <TThirdPartyType> third_party_file_io,
            IFileIO <TOwnedType> owned_file_io,
            BudgetingMonths budgeting_months,
            DataLoadingInformation <TThirdPartyType, TOwnedType> data_loading_info,
            IMatcher matcher)
            where TThirdPartyType : ICSVRecord, new()
            where TOwnedType : ICSVRecord, new()
        {
            Load_pending_data(pending_file_io, pending_file, data_loading_info);
            Merge_budget_data(spreadsheet, pending_file, budgeting_months, data_loading_info);
            Merge_other_data(spreadsheet, pending_file, budgeting_months, data_loading_info);
            Generate_ad_hoc_data(spreadsheet, pending_file, budgeting_months, data_loading_info);
            Merge_unreconciled_data(spreadsheet, pending_file, data_loading_info);
            var reconciliator = Load_third_party_and_owned_files_into_reconciliator <TThirdPartyType, TOwnedType>(
                data_loading_info,
                third_party_file_io,
                owned_file_io,
                spreadsheet);
            var reconciliation_interface = Create_reconciliation_interface(data_loading_info, reconciliator, matcher);

            return(reconciliation_interface);
        }
コード例 #5
0
        private BudgetingMonths Initialise_budgeting_months <TRecordType>(
            ISpreadsheet spreadsheet,
            BudgetItemListData budget_item_list_data)
            where TRecordType : ICSVRecord, new()
        {
            DateTime next_unplanned_month = _clock.Today_date_time();

            bool do_transaction_budgeting  = Confirm_budgeting(ReconConsts.ConfirmTransactionBudgeting);
            bool do_expected_out_budgeting = Confirm_budgeting(ReconConsts.ConfirmExpectedOutBudgeting);

            var budgeting_months = new BudgetingMonths
            {
                Do_expected_out_budgeting = do_expected_out_budgeting,
                Do_transaction_budgeting  = do_transaction_budgeting
            };

            if (do_transaction_budgeting)
            {
                next_unplanned_month = Get_next_unplanned_month <TRecordType>(spreadsheet, budget_item_list_data);
            }

            budgeting_months.Next_unplanned_month = next_unplanned_month.Month;
            budgeting_months.Start_year           = next_unplanned_month.Year;

            return(budgeting_months);
        }
コード例 #6
0
        private void Add_records_to_pending_file_for_records_that_have_matching_months <TRecordType>(
            IEnumerable <TRecordType> base_records,
            ICSVFile <TRecordType> pending_file,
            BudgetingMonths budgeting_months) where TRecordType : ICSVRecord, new()
        {
            var final_month = budgeting_months.Last_month_for_budget_planning >= budgeting_months.Next_unplanned_month
                ? budgeting_months.Last_month_for_budget_planning
                : budgeting_months.Last_month_for_budget_planning + 12;

            for (int month = budgeting_months.Next_unplanned_month; month <= final_month; month++)
            {
                var new_month = month;
                var new_year  = budgeting_months.Start_year;
                if (month > 12)
                {
                    new_month = month - 12;
                    new_year  = new_year + 1;
                }
                var new_annual_records = base_records
                                         .Where(x => x.Date.Month == new_month)
                                         .Select(x => (TRecordType)
                                                 With_correct_days_per_month(x.Copy(), new_year, x.Date.Month));
                pending_file.Records.AddRange(new_annual_records.ToList());
            }
            pending_file.Records = pending_file.Records.OrderBy(record => record.Date).ToList();
        }
コード例 #7
0
        public void LoadFilesAndMergeData_WillUseAllTheCorrectDataToLoadSpreadsheetAndPendingAndBudgetedDataForBankIn()
        {
            // Arrange
            var mock_input_output        = new Mock <IInputOutput>();
            var reconciliate             = new FileLoader(mock_input_output.Object);
            var mock_spreadsheet         = new Mock <ISpreadsheet>();
            var mock_pending_file_io     = new Mock <IFileIO <BankRecord> >();
            var mock_pending_file        = new Mock <ICSVFile <BankRecord> >();
            var mock_actual_bank_file_io = new Mock <IFileIO <ActualBankRecord> >();
            var mock_bank_out_file_io    = new Mock <IFileIO <BankRecord> >();
            var budgeting_months         = new BudgetingMonths();

            mock_actual_bank_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null))
            .Returns(new List <ActualBankRecord>());
            mock_bank_out_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null))
            .Returns(new List <BankRecord>());
            var loading_info = new BankAndBankOutLoader().Loading_info();
            var mock_matcher = new Mock <IMatcher>();

            Set_up_for_loader_bespoke_stuff(mock_input_output, mock_spreadsheet);

            // Act
            var reconciliation_interface = reconciliate.Load <ActualBankRecord, BankRecord>(
                mock_spreadsheet.Object,
                mock_pending_file_io.Object,
                mock_pending_file.Object,
                mock_actual_bank_file_io.Object,
                mock_bank_out_file_io.Object,
                budgeting_months,
                loading_info,
                mock_matcher.Object);

            // Assert
            mock_pending_file_io.Verify(x => x.Set_file_paths(loading_info.File_paths.Main_path, loading_info.Pending_file_name));
            mock_actual_bank_file_io.Verify(x => x.Set_file_paths(loading_info.File_paths.Main_path, loading_info.File_paths.Third_party_file_name));
            mock_bank_out_file_io.Verify(x => x.Set_file_paths(loading_info.File_paths.Main_path, loading_info.File_paths.Owned_file_name));
            mock_pending_file.Verify(x => x.Load(true, loading_info.Default_separator, true));
            mock_pending_file.Verify(x => x.Convert_source_line_separators(loading_info.Default_separator, loading_info.Loading_separator));
            mock_spreadsheet.Verify(x => x.Add_budgeted_monthly_data_to_pending_file(
                                        budgeting_months,
                                        It.IsAny <ICSVFile <BankRecord> >(),
                                        It.Is <BudgetItemListData>(y => y == loading_info.Monthly_budget_data)));
            mock_spreadsheet.Verify(x => x.Add_budgeted_annual_data_to_pending_file(
                                        budgeting_months,
                                        It.IsAny <ICSVFile <BankRecord> >(),
                                        It.Is <BudgetItemListData>(y => y == loading_info.Annual_budget_data)));
            mock_pending_file.Verify(x => x.Update_source_lines_for_output(loading_info.Loading_separator));
            mock_spreadsheet.Verify(x => x.Add_unreconciled_rows_to_csv_file(loading_info.Sheet_name, It.IsAny <ICSVFile <BankRecord> >()));
            mock_pending_file.Verify(x => x.Write_to_file_as_source_lines(loading_info.File_paths.Owned_file_name));
            mock_input_output.Verify(x => x.Output_line("Loading data from pending file (which you should have already split out, if necessary)..."));
            mock_input_output.Verify(x => x.Output_line("Merging budget data with pending data..."));
            mock_input_output.Verify(x => x.Output_line("Merging unreconciled rows from spreadsheet with pending and budget data..."));
            mock_input_output.Verify(x => x.Output_line("Copying merged data (from pending, unreconciled, and budgeting) into main 'owned' csv file..."));
            mock_input_output.Verify(x => x.Output_line("Loading data back in from 'owned' and 'third party' files..."));
            mock_input_output.Verify(x => x.Output_line("Creating reconciliation interface..."));
            Assert.AreEqual(loading_info.Third_party_descriptor, reconciliation_interface.Third_party_descriptor, "Third Party Descriptor");
            Assert.AreEqual(loading_info.Owned_file_descriptor, reconciliation_interface.Owned_file_descriptor, "Owned File Descriptor");
            Assert.AreEqual(mock_matcher.Object, reconciliation_interface.Matcher, "Matcher");
        }
コード例 #8
0
 public void Merge_bespoke_data_with_pending_file(
     IInputOutput input_output,
     ISpreadsheet spreadsheet,
     ICSVFile <BankRecord> pending_file,
     BudgetingMonths budgeting_months,
     DataLoadingInformation <ActualBankRecord, BankRecord> data_loading_info)
 {
 }
コード例 #9
0
 public void Generate_ad_hoc_data(
     IInputOutput input_output,
     ISpreadsheet spreadsheet,
     ICSVFile <BankRecord> pending_file,
     BudgetingMonths budgeting_months,
     DataLoadingInformation <ActualBankRecord, BankRecord> data_loading_info)
 {
 }
コード例 #10
0
        private string Num_months_question(BudgetingMonths budgeting_months, string item)
        {
            var months = budgeting_months.Num_budgeting_months();
            var start  = budgeting_months.Budgeting_start_date().ToString("MMM", CultureInfo.CurrentCulture);
            var end    = budgeting_months.Budgeting_end_date().ToString("MMM", CultureInfo.CurrentCulture);

            return($"You're budgeting for {months} months, {start} til {end}. How many months of {item} do you want to budget for?");
        }
コード例 #11
0
 public void Generate_ad_hoc_data(
     IInputOutput input_output,
     ISpreadsheet spreadsheet,
     ICSVFile <CredCard2InOutRecord> pending_file,
     BudgetingMonths budgeting_months,
     DataLoadingInformation <CredCard2Record, CredCard2InOutRecord> data_loading_info)
 {
 }
コード例 #12
0
        public void Merge_bespoke_data_with_pending_file(
            IInputOutput input_output,
            ISpreadsheet spreadsheet,
            ICSVFile <CredCard2InOutRecord> pending_file,
            BudgetingMonths budgeting_months,
            DataLoadingInformation <CredCard2Record, CredCard2InOutRecord> data_loading_info)
        {
            var most_recent_cred_card_direct_debit = spreadsheet.Get_most_recent_row_containing_text <BankRecord>(
                MainSheetNames.Bank_out,
                ReconConsts.Cred_card2_dd_description,
                new List <int> {
                ReconConsts.DescriptionColumn, ReconConsts.DdDescriptionColumn
            });

            var statement_date = new DateTime();
            var next_date      = most_recent_cred_card_direct_debit.Date.AddMonths(1);
            var input          = input_output.Get_input(string.Format(
                                                            ReconConsts.AskForCredCardDirectDebit,
                                                            ReconConsts.Cred_card2_name,
                                                            next_date.ToShortDateString()));
            double new_balance = 0;

            while (input != "0")
            {
                if (double.TryParse(input, out new_balance))
                {
                    new_balance = new_balance * -1;
                    pending_file.Records.Add(new CredCard2InOutRecord
                    {
                        Date                = next_date,
                        Description         = ReconConsts.Cred_card2_regular_pymt_description,
                        Unreconciled_amount = new_balance
                    });
                }
                statement_date = next_date.AddMonths(-1);
                next_date      = next_date.Date.AddMonths(1);
                input          = input_output.Get_input(string.Format(
                                                            ReconConsts.AskForCredCardDirectDebit,
                                                            ReconConsts.Cred_card2_name,
                                                            next_date.ToShortDateString()));
            }

            if (!new_balance.Double_equals(0))
            {
                spreadsheet.Update_balance_on_totals_sheet(
                    Codes.Cred_card2_bal,
                    new_balance,
                    string.Format(
                        ReconConsts.CredCardBalanceDescription,
                        ReconConsts.Cred_card2_name,
                        $"{statement_date.ToString("MMM")} {statement_date.Year}"),
                    balance_column: 5,
                    text_column: 6,
                    code_column: 4,
                    input_output: input_output);
            }
        }
コード例 #13
0
 private void Merge_other_data <TThirdPartyType, TOwnedType>(
     ISpreadsheet spreadsheet,
     ICSVFile <TOwnedType> pending_file,
     BudgetingMonths budgeting_months,
     DataLoadingInformation <TThirdPartyType, TOwnedType> data_loading_info)
     where TThirdPartyType : ICSVRecord, new()
     where TOwnedType : ICSVRecord, new()
 {
     data_loading_info.Loader.Merge_bespoke_data_with_pending_file(_input_output, spreadsheet, pending_file, budgeting_months, data_loading_info);
 }
コード例 #14
0
        private string Get_response_to_budgeting_months_confirmation_message(BudgetingMonths budgeting_months)
        {
            string first_month  = CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(budgeting_months.Next_unplanned_month);
            string second_month = CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(budgeting_months.Last_month_for_budget_planning);

            int month_span = budgeting_months.Num_budgeting_months();

            var confirmation_text = String.Format(ReconConsts.ConfirmMonthInterval, first_month, second_month, month_span);

            return(_input_output.Get_input(confirmation_text));
        }
コード例 #15
0
 private void Generate_ad_hoc_data <TThirdPartyType, TOwnedType>(
     ISpreadsheet spreadsheet,
     ICSVFile <TOwnedType> pending_file,
     BudgetingMonths budgeting_months,
     DataLoadingInformation <TThirdPartyType, TOwnedType> data_loading_info)
     where TThirdPartyType : ICSVRecord, new()
     where TOwnedType : ICSVRecord, new()
 {
     _input_output.Output_line("Generating ad hoc data...");
     data_loading_info.Loader.Generate_ad_hoc_data(_input_output, spreadsheet, pending_file, budgeting_months, data_loading_info);
 }
コード例 #16
0
        public void Add_budgeted_monthly_data_to_pending_file <TRecordType>(
            BudgetingMonths budgeting_months,
            ICSVFile <TRecordType> pending_file,
            BudgetItemListData budget_item_list_data) where TRecordType : ICSVRecord, new()
        {
            var base_records = Get_all_budget_items <TRecordType>(budget_item_list_data);

            Add_records_to_pending_file_for_every_specified_month <TRecordType>(
                base_records,
                (ICSVFile <TRecordType>)pending_file,
                budgeting_months);
        }
        public void Merge_Bespoke_Data_With_Pending_File__Will_Not_Update_Balance_On_Totals_Sheet_If_User_Enters_No_Data()
        {
            // Arrange
            TestHelper.Set_correct_date_formatting();
            var      mock_input_output        = new Mock <IInputOutput>();
            DateTime last_direct_debit_date   = new DateTime(2018, 12, 17);
            var      next_direct_debit_date01 = last_direct_debit_date.AddMonths(1);
            var      next_direct_debit_date02 = last_direct_debit_date.AddMonths(2);

            mock_input_output
            .Setup(x => x.Get_input(
                       string.Format(
                           ReconConsts.AskForCredCardDirectDebit,
                           ReconConsts.Cred_card2_name,
                           next_direct_debit_date01.ToShortDateString()), ""))
            .Returns("0");
            var bank_record = new BankRecord {
                Date = last_direct_debit_date
            };
            var mock_spreadsheet = new Mock <ISpreadsheet>();

            mock_spreadsheet.Setup(x => x.Get_most_recent_row_containing_text <BankRecord>(
                                       MainSheetNames.Bank_out, ReconConsts.Cred_card2_dd_description, new List <int> {
                ReconConsts.DescriptionColumn, ReconConsts.DdDescriptionColumn
            }))
            .Returns(bank_record);
            var mock_pending_file = new Mock <ICSVFile <CredCard2InOutRecord> >();
            var pending_records   = new List <CredCard2InOutRecord>();

            mock_pending_file.Setup(x => x.Records).Returns(pending_records);
            var budgeting_months = new BudgetingMonths();
            var loading_info     = new CredCard2AndCredCard2InOutLoader().Loading_info();
            var cred_card2_and_cred_card2_in_out_loader = new CredCard2AndCredCard2InOutLoader();

            // Act
            cred_card2_and_cred_card2_in_out_loader.Merge_bespoke_data_with_pending_file(
                mock_input_output.Object,
                mock_spreadsheet.Object,
                mock_pending_file.Object,
                budgeting_months,
                loading_info);

            // Assert
            mock_spreadsheet.Verify(x => x.Update_balance_on_totals_sheet(
                                        It.IsAny <string>(),
                                        It.IsAny <double>(),
                                        It.IsAny <string>(),
                                        It.IsAny <int>(),
                                        It.IsAny <int>(),
                                        It.IsAny <int>(),
                                        mock_input_output.Object),
                                    Times.Never);
        }
コード例 #18
0
        public void Add_budgeted_annual_data_to_pending_file <TRecordType>(
            BudgetingMonths budgeting_months,
            ICSVFile <TRecordType> pending_file,
            BudgetItemListData budget_item_list_data) where TRecordType : ICSVRecord, new()
        {
            var annual_records = Get_all_budget_items <TRecordType>(budget_item_list_data);

            Add_records_to_pending_file_for_records_that_have_matching_months <TRecordType>(
                annual_records,
                (ICSVFile <TRecordType>)pending_file,
                budgeting_months);
        }
コード例 #19
0
        public void M_MergeBespokeDataWithPendingFile_WillAddMostRecentCredCardDirectDebits()
        {
            // Arrange
            TestHelper.Set_correct_date_formatting();
            var      mock_input_output        = new Mock <IInputOutput>();
            var      mock_spreadsheet_repo    = new Mock <ISpreadsheetRepo>();
            double   expected_amount1         = 1234.55;
            double   expected_amount2         = 5673.99;
            DateTime last_direct_debit_date   = new DateTime(2018, 12, 17);
            var      next_direct_debit_date01 = last_direct_debit_date.AddMonths(1);
            var      next_direct_debit_date02 = last_direct_debit_date.AddMonths(2);

            Set_up_for_credit_card_data(
                ReconConsts.Cred_card1_name,
                ReconConsts.Cred_card1_dd_description,
                last_direct_debit_date,
                expected_amount1,
                expected_amount2,
                mock_input_output,
                mock_spreadsheet_repo, 1);
            Set_up_for_credit_card_data(
                ReconConsts.Cred_card2_name,
                ReconConsts.Cred_card2_dd_description,
                last_direct_debit_date,
                expected_amount1,
                expected_amount2,
                mock_input_output,
                mock_spreadsheet_repo, 2);
            var spreadsheet       = new Spreadsheet(mock_spreadsheet_repo.Object);
            var mock_pending_file = new Mock <ICSVFile <BankRecord> >();
            var pending_records   = new List <BankRecord>();

            mock_pending_file.Setup(x => x.Records).Returns(pending_records);
            var budgeting_months         = new BudgetingMonths();
            var loading_info             = new BankAndBankOutLoader().Loading_info();
            var bank_and_bank_out_loader = new BankAndBankOutLoader();

            // Act
            bank_and_bank_out_loader.Merge_bespoke_data_with_pending_file(
                mock_input_output.Object,
                spreadsheet,
                mock_pending_file.Object,
                budgeting_months,
                loading_info);

            // Assert
            Assert.AreEqual(4, pending_records.Count);
            Assert_direct_debit_details_are_correct(pending_records[0], next_direct_debit_date01, expected_amount1, ReconConsts.Cred_card1_dd_description);
            Assert_direct_debit_details_are_correct(pending_records[1], next_direct_debit_date02, expected_amount2, ReconConsts.Cred_card1_dd_description);
            Assert_direct_debit_details_are_correct(pending_records[2], next_direct_debit_date01, expected_amount1, ReconConsts.Cred_card2_dd_description);
            Assert_direct_debit_details_are_correct(pending_records[3], next_direct_debit_date02, expected_amount2, ReconConsts.Cred_card2_dd_description);
        }
コード例 #20
0
        private void Update_weekly_item(
            IInputOutput input_output,
            ISpreadsheet spreadsheet,
            BudgetingMonths budgeting_months,
            string item,
            string budget_code,
            string expected_out_code)
        {
            var week_getter = new WeekGetter(input_output, new Clock());
            var weeks       = week_getter.Decide_num_weeks(item, budgeting_months);

            spreadsheet.Update_expected_out(weeks.NumWeeks, budget_code, expected_out_code);
        }
コード例 #21
0
        public void Will_Not_Attempt_To_Merge_Budgeted_Annual_Data_If_User_Has_Asked_For_No_Budgeting()
        {
            // Arrange
            const int no_budgeting_wanted = 0;
            var       budgeting_months    = new BudgetingMonths
            {
                Start_year                     = 2020,
                Next_unplanned_month           = 6,
                Last_month_for_budget_planning = no_budgeting_wanted
            };
            var loading_info = new DummyLoader().Loading_info();

            // Give it some annual budget data, otherwise it owuldn't do annual nudgeting anyway.
            loading_info.Annual_budget_data = new BudgetItemListData();
            var mock_input_output        = new Mock <IInputOutput>();
            var reconciliate             = new FileLoader(mock_input_output.Object, new Clock());
            var mock_spreadsheet         = new Mock <ISpreadsheet>();
            var mock_pending_file_io     = new Mock <IFileIO <BankRecord> >();
            var mock_pending_file        = new Mock <ICSVFile <BankRecord> >();
            var mock_actual_bank_file_io = new Mock <IFileIO <ActualBankRecord> >();
            var mock_bank_out_file_io    = new Mock <IFileIO <BankRecord> >();

            mock_pending_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), It.IsAny <char>()))
            .Returns(new List <BankRecord>());
            mock_actual_bank_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null))
            .Returns(new List <ActualBankRecord>());
            mock_bank_out_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null))
            .Returns(new List <BankRecord>());
            var mock_matcher = new Mock <IMatcher>();

            // Act
            var reconciliation_interface = reconciliate.Load <ActualBankRecord, BankRecord>(
                mock_spreadsheet.Object,
                mock_pending_file_io.Object,
                mock_pending_file.Object,
                mock_actual_bank_file_io.Object,
                mock_bank_out_file_io.Object,
                budgeting_months,
                loading_info,
                mock_matcher.Object);

            // Assert
            mock_spreadsheet
            .Verify(x => x.Add_budgeted_annual_data_to_pending_file(
                        It.IsAny <BudgetingMonths>(),
                        It.IsAny <ICSVFile <BankRecord> >(),
                        It.IsAny <BudgetItemListData>()),
                    Times.Never);
        }
コード例 #22
0
 private void Merge_budget_data <TThirdPartyType, TOwnedType>(
     ISpreadsheet spreadsheet,
     ICSVFile <TOwnedType> pending_file,
     BudgetingMonths budgeting_months,
     DataLoadingInformation <TThirdPartyType, TOwnedType> data_loading_info)
     where TThirdPartyType : ICSVRecord, new()
     where TOwnedType : ICSVRecord, new()
 {
     _input_output.Output_line("Merging budget data with pending data...");
     spreadsheet.Add_budgeted_monthly_data_to_pending_file(budgeting_months, pending_file, data_loading_info.Monthly_budget_data);
     if (null != data_loading_info.Annual_budget_data)
     {
         spreadsheet.Add_budgeted_annual_data_to_pending_file(budgeting_months, pending_file, data_loading_info.Annual_budget_data);
     }
 }
コード例 #23
0
        public void LoadFilesAndMergeData_WillNotLoadData_WhenTesting()
        {
            // Arrange
            var mock_input_output        = new Mock <IInputOutput>();
            var reconciliate             = new FileLoader(mock_input_output.Object, new Clock());
            var mock_spreadsheet         = new Mock <ISpreadsheet>();
            var mock_pending_file_io     = new Mock <IFileIO <BankRecord> >();
            var mock_pending_file        = new Mock <ICSVFile <BankRecord> >();
            var mock_actual_bank_file_io = new Mock <IFileIO <ActualBankRecord> >();
            var mock_bank_out_file_io    = new Mock <IFileIO <BankRecord> >();

            mock_actual_bank_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null))
            .Returns(new List <ActualBankRecord>());
            mock_bank_out_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null))
            .Returns(new List <BankRecord>());
            var budgeting_months = new BudgetingMonths {
                Start_year = 2020, Next_unplanned_month = 6, Last_month_for_budget_planning = 6
            };
            var loading_info = new DummyLoader().Loading_info();

            loading_info.File_paths.Main_path = "This is not a path";
            bool exception_thrown = false;
            var  mock_matcher     = new Mock <IMatcher>();

            // Act
            try
            {
                var reconciliation_interface = reconciliate.Load <ActualBankRecord, BankRecord>(
                    mock_spreadsheet.Object,
                    mock_pending_file_io.Object,
                    mock_pending_file.Object,
                    mock_actual_bank_file_io.Object,
                    mock_bank_out_file_io.Object,
                    budgeting_months,
                    loading_info,
                    mock_matcher.Object);
            }
            catch (DirectoryNotFoundException)
            {
                exception_thrown = true;

                // Clean up
                loading_info.File_paths.Main_path = ReconConsts.Default_file_path;
            }

            // Assert
            Assert.IsFalse(exception_thrown);
        }
コード例 #24
0
        public void M_WillCallGenerateAdHocDataWithPendingFile_ForPassedInLoader()
        {
            // Arrange
            var mock_input_output        = new Mock <IInputOutput>();
            var reconciliate             = new FileLoader(mock_input_output.Object, new Clock());
            var mock_spreadsheet         = new Mock <ISpreadsheet>();
            var mock_pending_file_io     = new Mock <IFileIO <BankRecord> >();
            var mock_pending_file        = new Mock <ICSVFile <BankRecord> >();
            var mock_actual_bank_file_io = new Mock <IFileIO <ActualBankRecord> >();
            var mock_bank_out_file_io    = new Mock <IFileIO <BankRecord> >();
            var budgeting_months         = new BudgetingMonths {
                Start_year = 2020, Next_unplanned_month = 6, Last_month_for_budget_planning = 6
            };

            mock_actual_bank_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null))
            .Returns(new List <ActualBankRecord>());
            mock_bank_out_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null))
            .Returns(new List <BankRecord>());
            var mock_loader = new Mock <ILoader <ActualBankRecord, BankRecord> >();

            mock_loader.Setup(x => x.Create_new_third_party_file(It.IsAny <IFileIO <ActualBankRecord> >())).Returns(new ActualBankInFile(new CSVFile <ActualBankRecord>(mock_actual_bank_file_io.Object)));
            mock_loader.Setup(x => x.Create_new_owned_file(It.IsAny <IFileIO <BankRecord> >())).Returns(new GenericFile <BankRecord>(new CSVFile <BankRecord>(mock_bank_out_file_io.Object)));
            var loading_info = new DataLoadingInformation <ActualBankRecord, BankRecord>
            {
                Loader     = mock_loader.Object,
                File_paths = new FilePaths()
            };
            var mock_matcher = new Mock <IMatcher>();

            // Act
            var reconciliation_interface = reconciliate.Load <ActualBankRecord, BankRecord>(
                mock_spreadsheet.Object,
                mock_pending_file_io.Object,
                mock_pending_file.Object,
                mock_actual_bank_file_io.Object,
                mock_bank_out_file_io.Object,
                budgeting_months,
                loading_info,
                mock_matcher.Object);

            // Assert
            mock_loader.Verify(x => x.Generate_ad_hoc_data(
                                   mock_input_output.Object,
                                   mock_spreadsheet.Object,
                                   mock_pending_file.Object,
                                   budgeting_months,
                                   loading_info), Times.Exactly(1));
        }
コード例 #25
0
        private void Update_monthly_item(
            IInputOutput input_output,
            ISpreadsheet spreadsheet,
            BudgetingMonths budgeting_months,
            string item,
            string budget_code,
            string expected_out_code)
        {
            var input      = input_output.Get_input(Num_months_question(budgeting_months, item));
            var num_months = 0;

            if (int.TryParse(input, out num_months))
            {
                spreadsheet.Update_expected_out(num_months, budget_code, expected_out_code);
            }
        }
コード例 #26
0
        public void Will_calculate_budgeting_start_date_using_next_unplanned_month_and_start_year()
        {
            // Arrange
            var budgeting_months = new BudgetingMonths
            {
                Next_unplanned_month = 2,
                Start_year           = 2019
            };

            // Act
            var result = budgeting_months.Budgeting_start_date();

            // Assert
            Assert.AreEqual(result.Month, budgeting_months.Next_unplanned_month);
            Assert.AreEqual(result.Year, budgeting_months.Start_year);
        }
コード例 #27
0
        public BudgetingMonths Recursively_ask_for_budgeting_months(ISpreadsheet spreadsheet)
        {
            DateTime next_unplanned_month           = Get_next_unplanned_month(spreadsheet);
            int      last_month_for_budget_planning = Get_last_month_for_budget_planning(spreadsheet, next_unplanned_month.Month);
            var      budgeting_months = new BudgetingMonths
            {
                Next_unplanned_month           = next_unplanned_month.Month,
                Last_month_for_budget_planning = last_month_for_budget_planning,
                Start_year = next_unplanned_month.Year
            };

            if (last_month_for_budget_planning != 0)
            {
                budgeting_months.Last_month_for_budget_planning = Confirm_budgeting_month_choices_with_user(budgeting_months, spreadsheet);
            }
            return(budgeting_months);
        }
コード例 #28
0
        public void Merge_bespoke_data_with_pending_file(
            IInputOutput input_output,
            ISpreadsheet spreadsheet,
            ICSVFile <BankRecord> pending_file,
            BudgetingMonths budgeting_months,
            DataLoadingInformation <ActualBankRecord, BankRecord> data_loading_info)
        {
            input_output.Output_line(ReconConsts.Loading_expenses);
            _expected_income_csv_file.Load(false);

            spreadsheet.Add_unreconciled_rows_to_csv_file <ExpectedIncomeRecord>(MainSheetNames.Expected_in, _expected_income_file.File);
            _expected_income_csv_file.Populate_source_records_from_records();
            _expected_income_file.Filter_for_employer_expenses_and_bank_transactions_only();

            _expected_income_file.Copy_to_pending_file(pending_file);
            _expected_income_csv_file.Populate_records_from_original_file_load();
        }
コード例 #29
0
        private BudgetDataSetup <TRecordType> When_adding_budgeted_data_to_spreadsheet <TRecordType>(
            int first_month,
            int last_month,
            Mock <ISpreadsheetRepo> mock_spreadsheet_repo,
            BudgetItemListData budget_item_list_data,
            int default_day = 5) where TRecordType : ICSVRecord, new()
        {
            // Arrange
            var budgeting_months = new BudgetingMonths
            {
                Next_unplanned_month           = first_month,
                Last_month_for_budget_planning = last_month,
                Start_year = 2018
            };
            var    first_monthly_row = 3;
            var    last_monthly_row  = first_monthly_row + 2;
            string desc1             = "first monthly record";
            string desc2             = "second monthly record";
            var    monthly_records   = new List <TRecordType>
            {
                new TRecordType {
                    Date = new DateTime(budgeting_months.Start_year, first_month, default_day), Description = desc1
                },
                new TRecordType {
                    Date = new DateTime(budgeting_months.Start_year, first_month, 20), Description = desc2
                }
            };

            mock_spreadsheet_repo.Setup(x => x.Find_row_number_of_last_row_containing_cell(budget_item_list_data.Sheet_name, budget_item_list_data.Start_divider, 2)).Returns(first_monthly_row);
            mock_spreadsheet_repo.Setup(x => x.Find_row_number_of_last_row_containing_cell(budget_item_list_data.Sheet_name, budget_item_list_data.End_divider, 2)).Returns(last_monthly_row);
            mock_spreadsheet_repo.Setup(x => x.Get_rows_as_records <TRecordType>(
                                            budget_item_list_data.Sheet_name,
                                            first_monthly_row + 1,
                                            last_monthly_row - 1,
                                            budget_item_list_data.First_column_number,
                                            budget_item_list_data.Last_column_number)).Returns(monthly_records);

            return(new BudgetDataSetup <TRecordType>
            {
                Desc1 = desc1,
                Desc2 = desc2,
                BudgetingMonths = budgeting_months,
                MonthlyRecords = monthly_records
            });
        }
コード例 #30
0
        public void Will_calculate_num_budgeting_months_based_on_stored_data(
            int next_unplanned_month,
            int last_month_for_budget_planning,
            int expected_result)
        {
            // Arrange
            var budgeting_months = new BudgetingMonths
            {
                Next_unplanned_month           = next_unplanned_month,
                Last_month_for_budget_planning = last_month_for_budget_planning
            };

            // Act
            var result = budgeting_months.Num_budgeting_months();

            // Assert
            Assert.AreEqual(expected_result, result);
        }