Example #1
0
        public void Will_mark_last_bank_out_row_when_loading_before_records_are_ordered_in_date_order()
        {
            // Arrange
            string last_row_description = "Last row";
            var    fake_records         = new List <ActualBankRecord>
            {
                new ActualBankRecord {
                    Amount = -10, Date = new DateTime(2020, 1, 4), Description = last_row_description
                },
                new ActualBankRecord {
                    Amount = -10, Date = new DateTime(2020, 1, 4), Description = "This will be the last row when ordered in date order."
                },
                new ActualBankRecord {
                    Amount = -10, Date = new DateTime(2020, 1, 2)
                },
            };
            var mock_actual_bank_file_io = new Mock <IFileIO <ActualBankRecord> >();

            mock_actual_bank_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), It.IsAny <char?>()))
            .Returns(fake_records);
            var actual_bank_file     = new CSVFile <ActualBankRecord>(mock_actual_bank_file_io.Object);
            var actual_bank_out_file = new ActualBankOutFile(actual_bank_file);

            // Act
            actual_bank_out_file.Load();

            // Assert
            var last_record = actual_bank_out_file.File.Records.First(x => x.Description == last_row_description);

            Assert.AreEqual(ReconConsts.LastOnlineTransaction, last_record.LastTransactionMarker);
        }
Example #2
0
        public void Will_find_multiple_balance_rows_when_result_is_ambiguous_because_multiple_early_records_exist_that_point_to_different_recent_records()
        {
            // Arrange
            string balance_row_desc_01 = "Potential balance row 01";
            string balance_row_desc_02 = "Potential balance row 02";
            var    fake_records        = new List <ActualBankRecord>
            {
                // most recent records
                new ActualBankRecord {
                    Amount = -10, Balance = 900.00, Date = new DateTime(2020, 1, 4), Description = balance_row_desc_02
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 910.00, Date = new DateTime(2020, 1, 4)
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 920.00, Date = new DateTime(2020, 1, 4), Description = balance_row_desc_01
                },
                // middle records
                new ActualBankRecord {
                    Amount = -10, Balance = 930.00, Date = new DateTime(2020, 1, 3)
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 940.00, Date = new DateTime(2020, 1, 3)
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 950.00, Date = new DateTime(2020, 1, 2)
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 960.00, Date = new DateTime(2020, 1, 2)
                },
                // earliest records
                new ActualBankRecord {
                    Amount = -10, Balance = 970.00, Date = new DateTime(2020, 1, 1)
                },
                new ActualBankRecord {
                    Amount = -20, Balance = 980.00, Date = new DateTime(2020, 1, 1)
                },
                new ActualBankRecord {
                    Amount = -20, Balance = 1000.00, Date = new DateTime(2020, 1, 1), Description = "This record could point at balance_row_desc_01"
                },
                new ActualBankRecord {
                    Amount = 30, Balance = 1020.00, Date = new DateTime(2020, 1, 1)
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 990.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);

            // Act
            var result = actual_bank_out_file.Get_potential_balance_rows();

            // Assert
            Assert.AreEqual(2, result.Count());
            Assert.IsTrue(result.Any(x => x.Description == balance_row_desc_01));
            Assert.IsTrue(result.Any(x => x.Description == balance_row_desc_02));
        }
        private void Update_bank_balance(
            ActualBankOutFile actual_bank_out_file,
            ISpreadsheet spreadsheet,
            IInputOutput input_output)
        {
            input_output.Output_line("Writing bank balance to spreadsheet...");

            IList <ActualBankRecord> potential_balance_rows = actual_bank_out_file.Get_potential_balance_rows().ToList();

            if (!potential_balance_rows.Any())
            {
                input_output.Output_line("");
                input_output.Get_generic_input(ReconConsts.CantFindBalanceRow);
            }
            else
            {
                ActualBankRecord balance_row = Choose_balance_row(potential_balance_rows, input_output);

                string balance_description = String.Format(
                    ReconConsts.BankBalanceDescription,
                    ReconConsts.Bank_descriptor,
                    balance_row.Description,
                    balance_row.Main_amount().To_csv_string(true),
                    balance_row.Date.ToString(@"dd\/MM\/yyyy"));

                spreadsheet.Update_balance_on_totals_sheet(
                    Codes.Bank_bal,
                    balance_row.Balance,
                    balance_description,
                    balance_column: ReconConsts.BankBalanceAmountColumn,
                    text_column: ReconConsts.BankBalanceTextColumn,
                    code_column: ReconConsts.BankBalanceCodeColumn,
                    input_output: input_output);
            }
        }
Example #4
0
        public void Will_filter_for_negative_records_when_loading()
        {
            // Arrange
            var mock_actual_bank_file = new Mock <ICSVFile <ActualBankRecord> >();
            var actual_bank_out_file  = new ActualBankOutFile(mock_actual_bank_file.Object);

            // Act
            actual_bank_out_file.Load();

            // Assert
            mock_actual_bank_file.Verify(x => x.Filter_for_negative_records_only());
        }
Example #5
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>()));
        }
Example #6
0
        public void Will_find_balance_row_when_records_are_not_in_correct_order()
        {
            // Arrange
            string balance_row_description = "Balance row";
            var    fake_records            = new List <ActualBankRecord>
            {
                // most recent records
                new ActualBankRecord {
                    Amount = -10, Balance = 910.00, Date = new DateTime(2020, 1, 4)
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 920.00, Date = new DateTime(2020, 1, 4)
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 900.00, Date = new DateTime(2020, 1, 4), Description = balance_row_description
                },
                // middle records
                new ActualBankRecord {
                    Amount = -10, Balance = 930.00, Date = new DateTime(2020, 1, 3)
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 940.00, Date = new DateTime(2020, 1, 3)
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 950.00, Date = new DateTime(2020, 1, 2)
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 960.00, Date = new DateTime(2020, 1, 2)
                },
                // earliest records
                new ActualBankRecord {
                    Amount = -10, Balance = 990.00, Date = new DateTime(2020, 1, 1), Description = "First row"
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 970.00, Date = new DateTime(2020, 1, 1)
                },
                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);

            // Act
            var result = actual_bank_out_file.Get_potential_balance_rows();

            // Assert
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(balance_row_description, result.ToList()[0].Description);
        }
Example #7
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>()));
        }
Example #8
0
        public void Will_find_balance_row_when_most_recent_transaction_has_no_balance()
        {
            // Arrange
            string balance_row_description = "Balance row";
            var    fake_records            = new List <ActualBankRecord>
            {
                // pending record with no balance
                new ActualBankRecord {
                    Amount = -10, Balance = 0.00, Date = new DateTime(2020, 1, 5)
                },
                // most recent records
                new ActualBankRecord {
                    Amount = -10, Balance = 940.00, Date = new DateTime(2020, 1, 4), Description = balance_row_description
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 950.00, Date = new DateTime(2020, 1, 4)
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 960.00, Date = new DateTime(2020, 1, 4)
                },
                // earliest records
                new ActualBankRecord {
                    Amount = -10, Balance = 970.00, Date = new DateTime(2020, 1, 1)
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 980.00, Date = new DateTime(2020, 1, 1)
                },
                new ActualBankRecord {
                    Amount = -10, Balance = 990.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);

            // Act
            var result = actual_bank_out_file.Get_potential_balance_rows();

            // Assert
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(balance_row_description, result.ToList()[0].Description);
        }