Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void WhenLoadingPendingData_WillConvertSourceLineSeparatorsAfterLoading()
        {
            // Arrange
            var mock_input_output    = new Mock <IInputOutput>();
            var reconciliate         = new FileLoader(mock_input_output.Object);
            var mock_pending_file_io = new Mock <IFileIO <BankRecord> >();
            var pending_file         = new CSVFile <BankRecord>(mock_pending_file_io.Object);

            mock_pending_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null))
            .Returns(new List <BankRecord> {
                new BankRecord()
            });
            var  loading_info     = new BankAndBankOutLoader().Loading_info();
            bool exception_thrown = false;

            // Act
            try
            {
                reconciliate.Load_pending_data <ActualBankRecord, BankRecord>(
                    mock_pending_file_io.Object,
                    pending_file,
                    loading_info);
            }
            catch (NullReferenceException)
            {
                exception_thrown = true;
            }

            // Assert
            Assert.IsFalse(exception_thrown);
        }
Ejemplo n.º 3
0
        public void Will_not_update_owed_CHB_when_generating_ad_hoc_data_if_user_says_no()
        {
            // Arrange
            var bank_and_bank_out_loader = new BankAndBankOutLoader();
            var mock_spreadsheet         = new Mock <ISpreadsheet>();
            var mock_input_output        = new Mock <IInputOutput>();

            mock_input_output.Setup(x => x.Get_input(It.Is <string>(y => y.Contains("CHB")), ""))
            .Returns("N");

            // Act
            bank_and_bank_out_loader.Generate_ad_hoc_data(
                mock_input_output.Object,
                mock_spreadsheet.Object,
                new Mock <ICSVFile <BankRecord> >().Object,
                new BudgetingMonths {
                Start_year = 2020, Next_unplanned_month = 6, Last_month_for_budget_planning = 6, Do_expected_out_budgeting = true
            },
                new DataLoadingInformation <ActualBankRecord, BankRecord>()
                );

            // Assert
            mock_spreadsheet.Verify(x => x.Update_owed_CHB(It.IsAny <BudgetingMonths>()),
                                    Times.Never);
        }
Ejemplo n.º 4
0
        public void Will_update_groceries_when_generating_ad_hoc_data()
        {
            // Arrange
            var bank_and_bank_out_loader = new BankAndBankOutLoader();
            var mock_input_output        = new Mock <IInputOutput>();
            var mock_spreadsheet         = new Mock <ISpreadsheet>();

            // Act
            bank_and_bank_out_loader.Generate_ad_hoc_data(
                mock_input_output.Object,
                mock_spreadsheet.Object,
                new Mock <ICSVFile <BankRecord> >().Object,
                new BudgetingMonths {
                Start_year = 2020, Next_unplanned_month = 6, Last_month_for_budget_planning = 6, Do_expected_out_budgeting = true
            },
                new DataLoadingInformation <ActualBankRecord, BankRecord>()
                );

            // Assert
            mock_spreadsheet.Verify(x => x.Update_expected_out(
                                        It.IsAny <int>(),
                                        Codes.Code005,
                                        Codes.Code075));
            mock_input_output.Verify(x => x.Get_input(
                                         It.Is <string>(y => y.Contains("grocery shopping")), ""));
        }
Ejemplo n.º 5
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");
        }
        public void Do_matching(FilePaths main_file_paths)
        {
            var loading_info = new BankAndBankOutLoader().Loading_info();

            loading_info.File_paths = main_file_paths;
            var file_loader = new FileLoader(_input_output);
            ReconciliationInterface <ActualBankRecord, BankRecord> reconciliation_interface
                = file_loader.Load_files_and_merge_data <ActualBankRecord, BankRecord>(loading_info, _spreadsheet_factory, this);

            reconciliation_interface?.Do_the_matching();
        }
Ejemplo n.º 7
0
        public void Will_assume_bank_records_are_in_reverse_date_order_when_looking_for_bank_balance_transaction()
        {
            // Arrange
            var bank_and_bank_out_loader = new BankAndBankOutLoader();
            var mockSpreadsheet          = new Mock <ISpreadsheet>();
            var mockInputOutput          = new Mock <IInputOutput>();

            mockInputOutput.Setup(x => x.Get_generic_input(ReconConsts.MultipleBalanceRows)).Returns("1");
            string expected_description  = "Balance row";
            string alternative_candidate = "another potential candidate";
            var    fake_records          = new List <ActualBankRecord>
            {
                // most recent records
                new ActualBankRecord {
                    Amount = -10, Balance = 970.00, Date = new DateTime(2020, 1, 4), Description = expected_description
                },
                new ActualBankRecord {
                    Amount = 10, Balance = 980.00, Date = new DateTime(2020, 1, 4)
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 970.00, Date = new DateTime(2020, 1, 4), Description = alternative_candidate
                },
                // earliest records
                new ActualBankRecord {
                    Amount = -10, Balance = 980.00, Date = new DateTime(2020, 1, 1)
                },
            };
            var mock_actual_bank_file = new Mock <ICSVFile <ActualBankRecord> >();

            mock_actual_bank_file.Setup(x => x.Records).Returns(fake_records);
            var actual_bank_out_file = new ActualBankOutFile(mock_actual_bank_file.Object);
            var mock_bank_file       = new Mock <ICSVFile <BankRecord> >();
            var bank_file            = new GenericFile <BankRecord>(mock_bank_file.Object);

            // Act
            bank_and_bank_out_loader.Do_actions_which_require_third_party_data_access(
                actual_bank_out_file,
                bank_file,
                mockSpreadsheet.Object,
                mockInputOutput.Object);

            // Assert
            mockInputOutput.Verify(x => x.Output_line(It.Is <string>(y => y.Contains(expected_description))), Times.Exactly(2));
            mockInputOutput.Verify(x => x.Output_line(It.Is <string>(y => y.Contains(alternative_candidate))), Times.Exactly(1));
            mockSpreadsheet.Verify(x => x.Update_balance_on_totals_sheet(
                                       Codes.Bank_bal,
                                       It.IsAny <double>(),
                                       It.Is <string>(y => y.Contains(expected_description)),
                                       ReconConsts.BankBalanceAmountColumn,
                                       ReconConsts.BankBalanceTextColumn,
                                       ReconConsts.BankBalanceCodeColumn,
                                       It.IsAny <IInputOutput>()));
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public void Will_update_bank_balance()
        {
            // Arrange
            var    bank_and_bank_out_loader    = new BankAndBankOutLoader();
            var    mockSpreadsheet             = new Mock <ISpreadsheet>();
            var    mockInputOutput             = new Mock <IInputOutput>();
            string expected_description        = "Balance row";
            double expected_balance            = 970.00;
            double expected_transaction_amount = -10.00;
            var    fake_records = new List <ActualBankRecord>
            {
                // earliest records
                new ActualBankRecord {
                    Amount = -10, Balance = 990.00, Date = new DateTime(2020, 1, 1)
                },
                // most recent records
                new ActualBankRecord {
                    Amount = -10, Balance = 980.00, Date = new DateTime(2020, 1, 4)
                },
                new ActualBankRecord {
                    Amount = expected_transaction_amount, Balance = expected_balance, Date = new DateTime(2020, 1, 4), Description = expected_description
                },
            };
            var mock_actual_bank_file = new Mock <ICSVFile <ActualBankRecord> >();

            mock_actual_bank_file.Setup(x => x.Records).Returns(fake_records);
            var actual_bank_out_file = new ActualBankOutFile(mock_actual_bank_file.Object);
            var mock_bank_file       = new Mock <ICSVFile <BankRecord> >();
            var bank_file            = new GenericFile <BankRecord>(mock_bank_file.Object);

            // Act
            bank_and_bank_out_loader.Do_actions_which_require_third_party_data_access(
                actual_bank_out_file,
                bank_file,
                mockSpreadsheet.Object,
                mockInputOutput.Object);

            // Assert
            mockSpreadsheet.Verify(x => x.Update_balance_on_totals_sheet(
                                       Codes.Bank_bal,
                                       expected_balance,
                                       It.Is <string>(y => y.Contains(expected_description) &&
                                                      y.Contains(expected_transaction_amount.To_csv_string(true))),
                                       ReconConsts.BankBalanceAmountColumn,
                                       ReconConsts.BankBalanceTextColumn,
                                       ReconConsts.BankBalanceCodeColumn,
                                       It.IsAny <IInputOutput>()));
        }