public void Can_write_new_contents_to_csv()
        {
            // Arrange
            var file_io  = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only");
            var csv_file = new CSVFile <BankRecord>(file_io);

            csv_file.Load();
            var new_bank_record = new BankRecord();
            // Date, unreconciled amount, type and description are mandatory.
            // string csvLine = String.Format("DATE^UNRECONCILED_AMT^^TYPE^DESCRIPTION^^^^^");
            var todays_date = DateTime.Today.ToString("dd/MM/yyyy");

            new_bank_record.Load(String.Format("{0}^£12.34^^POS^Purchase^^^^^", todays_date));
            csv_file.Records.Add(new_bank_record);

            // Act
            csv_file.Write_to_csv_file("testing");

            // Assert
            var file_io_test_file = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only-testing");
            var new_csv_file      = new CSVFile <BankRecord>(file_io_test_file);

            new_csv_file.Load(
                true,
                ',');
            List <string> csv_lines = new_csv_file.All_records_as_csv();

            Assert.AreEqual("01/02/2017,£350.00,,ABC,\"ZZZThing3\",,,,,", csv_lines[0]);
            Assert.AreEqual("01/03/2017,£350.00,,ABC,\"ZZZThing2\",,,,,", csv_lines[1]);
            Assert.AreEqual("24/03/2017,£200.12,,PCL,\"ZZZSpecialDescription001\",,,,,", csv_lines[2]);
            Assert.AreEqual("01/04/2017,£261.40,,PCL,\"ZZZSpecialDescription005\",,,,,", csv_lines[3]);
            Assert.AreEqual("03/04/2017,£350.00,,ABC,\"ZZZThing1\",,,,,", csv_lines[4]);
            Assert.AreEqual(String.Format("{0},£12.34,,POS,\"Purchase\",,,,,", todays_date), csv_lines[5]);
        }
        public void Will_order_records_for_spreadsheet_by_matched_and_then_by_date_with_divider_between()
        {
            // Arrange
            const bool doNotOrderByDate = false;
            var        file_io          = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only");
            var        csv_file         = new CSVFile <BankRecord>(file_io);

            csv_file.Load(
                true,
                null,
                doNotOrderByDate);
            csv_file.Records[0].Matched = true;
            csv_file.Records[1].Matched = true;
            csv_file.Records[3].Matched = true;

            // Act
            var records = csv_file.Records_ordered_for_spreadsheet();

            // Assert
            Assert.AreEqual("ZZZThing2", records[0].Description);
            Assert.AreEqual("ZZZSpecialDescription001", records[1].Description);
            Assert.AreEqual("ZZZThing1", records[2].Description);
            Assert.AreEqual(true, records[3].Divider);
            Assert.AreEqual("ZZZThing3", records[4].Description);
            Assert.AreEqual("ZZZSpecialDescription005", records[5].Description);
        }
        public void Will_append_all_rows_in_csv_file_to_specified_worksheet()
        {
            // Arrange
            var sheet_name = TestSheetNames.Bank;
            var file_io    = new FileIO <BankRecord>(new ExcelSpreadsheetRepoFactory(""), _csvFilePath, "BankIn-formatted-date-only");
            var csv_file   = new CSVFile <BankRecord>(file_io);

            csv_file.Load();
            var initial_last_row_number = _excelSpreadsheet.Last_row_number(sheet_name);

            // Act
            _excelSpreadsheet.Append_csv_file <BankRecord>(sheet_name, csv_file);
            var new_last_row   = _excelSpreadsheet.Read_last_row(sheet_name);
            var new_row_number = _excelSpreadsheet.Last_row_number(sheet_name);

            // Clean up
            for (int count = 1; count <= csv_file.Records.Count; count++)
            {
                _excelSpreadsheet.Remove_last_row(sheet_name);
            }

            // Assert
            var last_record_in_ordered_csv_file = csv_file.Records_ordered_for_spreadsheet()[csv_file.Records.Count - 1];

            Assert.AreEqual(last_record_in_ordered_csv_file.Date, DateTime.FromOADate((double)new_last_row.Read_cell(0)));
            Assert.AreEqual(last_record_in_ordered_csv_file.Unreconciled_amount, (Double)new_last_row.Read_cell(1));
            Assert.AreEqual(last_record_in_ordered_csv_file.Type, (String)new_last_row.Read_cell(3));
            Assert.AreEqual(last_record_in_ordered_csv_file.Description, (String)new_last_row.Read_cell(4));
            Assert.AreEqual(null, new_last_row.Read_cell(5));
            Assert.AreEqual(null, new_last_row.Read_cell(6));
            Assert.AreEqual(initial_last_row_number + csv_file.Records.Count, new_row_number);
        }
        public void Will_create_new_expenses_record_to_match_balance()
        {
            // Arrange
            var income_file_io = new Mock <IFileIO <ExpectedIncomeRecord> >();
            var income_records = new List <ExpectedIncomeRecord>();

            income_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(income_records);
            var income_file = new CSVFile <ExpectedIncomeRecord>(income_file_io.Object);

            income_file.Load();
            var expected_income_file = new ExpectedIncomeFile(income_file);
            var actual_bank_record   = new ActualBankRecord
            {
                Date   = DateTime.Today,
                Amount = 50
            };
            double balance = actual_bank_record.Amount - 10;

            // Act
            expected_income_file.Create_new_expenses_record_to_match_balance(actual_bank_record, balance);

            // Assert
            Assert.AreEqual(1, expected_income_file.File.Records.Count);
            Assert.AreEqual(ReconConsts.UnknownExpense, expected_income_file.File.Records[0].Description);
            Assert.AreEqual(balance, expected_income_file.File.Records[0].Unreconciled_amount);
            Assert.AreEqual(actual_bank_record, expected_income_file.File.Records[0].Match);
            Assert.AreEqual(true, expected_income_file.File.Records[0].Matched);
            Assert.AreEqual(actual_bank_record.Date, expected_income_file.File.Records[0].Date);
            Assert.AreEqual(actual_bank_record.Date, expected_income_file.File.Records[0].Date_paid);
            Assert.AreEqual(actual_bank_record.Amount, expected_income_file.File.Records[0].Total_paid);
            Assert.AreEqual(Codes.Expenses, expected_income_file.File.Records[0].Code);
        }
        public void M_WhenAddingRecordPermanentlyItIsStillThereAfterRefreshingFileContents()
        {
            // Arrange
            var mock_file_io     = new Mock <IFileIO <ExpectedIncomeRecord> >();
            var lost_description = "First record";
            var source_records   = new List <ExpectedIncomeRecord>
            {
                new ExpectedIncomeRecord {
                    Description = lost_description
                },
                new ExpectedIncomeRecord {
                    Description = "Second record"
                }
            };

            mock_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(source_records);
            var file = new CSVFile <ExpectedIncomeRecord>(mock_file_io.Object);

            file.Load();
            Assert.AreEqual(2, file.Records.Count);

            // Act
            file.Remove_record_permanently(source_records[0]);
            file.Populate_records_from_original_file_load();

            // Assert
            Assert.AreEqual(1, file.Records.Count);
            Assert.IsFalse(file.Records.Any(x => x.Description == lost_description));
        }
        public void Can_write_descriptions_containing_commas()
        {
            // Arrange
            var file_io  = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only");
            var csv_file = new CSVFile <BankRecord>(file_io);

            csv_file.Load();
            var new_bank_record = new BankRecord();
            var description_containing_comma = "something, something, something else";

            // Date, unreconciled amount, type and description are mandatory.
            // string csvLine = String.Format("DATE^UNRECONCILED_AMT^^TYPE^DESCRIPTION^^^^^");
            new_bank_record.Load(string.Format("01/05/2017^12.34^^POS^{0}^^^^^", description_containing_comma));
            csv_file.Records.Add(new_bank_record);

            // Act
            csv_file.Write_to_csv_file("testing");

            // Assert
            var file_io_test_file = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only-testing");
            var new_csv_file      = new CSVFile <BankRecord>(file_io_test_file);

            new_csv_file.Load(
                true,
                ',');

            Assert.AreEqual("01/05/2017,£12.34,,POS,\"something, something, something else\",,,,,", new_csv_file.Records[5].Source_line);
        }
        public void Can_output_all_records_as_csv_ordered_by_matched_and_then_by_date()
        {
            // Arrange
            const bool doNotOrderByDate = false;
            var        file_io          = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only");
            var        csv_file         = new CSVFile <BankRecord>(file_io);

            csv_file.Load(
                true,
                null,
                doNotOrderByDate);
            csv_file.Records[0].Matched = true;
            csv_file.Records[1].Matched = true;
            csv_file.Records[3].Matched = true;

            // Act
            List <string> csv_lines = csv_file.All_records_as_csv();

            // Assert
            Assert.AreEqual("01/03/2017,£350.00,x,ABC,\"ZZZThing2\",,,,,", csv_lines[0]);
            Assert.AreEqual("24/03/2017,£200.12,x,PCL,\"ZZZSpecialDescription001\",,,,,", csv_lines[1]);
            Assert.AreEqual("03/04/2017,£350.00,x,ABC,\"ZZZThing1\",,,,,", csv_lines[2]);
            Assert.AreEqual("01/02/2017,£350.00,,ABC,\"ZZZThing3\",,,,,", csv_lines[3]);
            Assert.AreEqual("01/04/2017,£261.40,,PCL,\"ZZZSpecialDescription005\",,,,,", csv_lines[4]);
        }
        public void M_WhenReconcilingExpenses_WillNotMatchOnASingleDifferentAmount()
        {
            // Arrange
            var mock_bank_and_bank_in_loader = new Mock <IBankAndBankInLoader>();
            var expense_amount = 10.00;
            List <BankRecord> expected_in_rows = new List <BankRecord> {
                new BankRecord {
                    Unreconciled_amount = expense_amount
                }
            };
            var bank_in_file_io = new Mock <IFileIO <BankRecord> >();

            bank_in_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(expected_in_rows);
            var bank_in_file = new CSVFile <BankRecord>(bank_in_file_io.Object);

            bank_in_file.Load();
            ActualBankRecord expense_transaction = new ActualBankRecord {
                Amount = expense_amount - 1
            };
            var matcher = new BankAndBankInMatcher(this, new FakeSpreadsheetRepoFactory(), mock_bank_and_bank_in_loader.Object);

            // Act
            var result = matcher.Standby_find_expense_matches(expense_transaction, bank_in_file).ToList();

            // Assert
            Assert.AreEqual(0, result.Count);
        }
        public void M_WillCopyRecordsToAnotherFile()
        {
            // Arrange
            var mock_source_file_io = new Mock <IFileIO <ExpectedIncomeRecord> >();
            var source_records      = new List <ExpectedIncomeRecord>
            {
                new ExpectedIncomeRecord {
                    Description = "First record"
                },
                new ExpectedIncomeRecord {
                    Description = "Second record"
                }
            };

            mock_source_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(source_records);
            var source_file = new CSVFile <ExpectedIncomeRecord>(mock_source_file_io.Object);

            source_file.Load();
            var mock_target_file_io = new Mock <IFileIO <ExpectedIncomeRecord> >();

            mock_target_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(new List <ExpectedIncomeRecord>());
            var target_file = new CSVFile <ExpectedIncomeRecord>(mock_target_file_io.Object);

            target_file.Load();
            Assert.AreEqual(0, target_file.Records.Count);

            // Act
            source_file.Copy_records_to_csv_file(target_file);

            // Assert
            Assert.AreEqual(source_file.Records.Count, target_file.Records.Count);
            Assert.AreEqual(source_file.Records[0].Description, target_file.Records[0].Description);
            Assert.AreEqual(source_file.Records[1].Description, target_file.Records[1].Description);
        }
        public void M_WhenRemovingRecordPermanentlyItDoesNotComeBackAfterRefreshingFileContents()
        {
            // Arrange
            var mock_file_io    = new Mock <IFileIO <ExpectedIncomeRecord> >();
            var new_description = "Third record";
            var source_records  = new List <ExpectedIncomeRecord>
            {
                new ExpectedIncomeRecord {
                    Description = "First record"
                },
                new ExpectedIncomeRecord {
                    Description = "Second record"
                }
            };

            mock_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(source_records);
            var file = new CSVFile <ExpectedIncomeRecord>(mock_file_io.Object);

            file.Load();
            Assert.AreEqual(2, file.Records.Count);

            // Act
            file.Add_record_permanently(new ExpectedIncomeRecord {
                Description = new_description
            });
            file.Populate_records_from_original_file_load();

            // Assert
            Assert.AreEqual(3, file.Records.Count);
            Assert.AreEqual(new_description, file.Records[2].Description);
        }
        public void Can_write_amounts_containing_commas()
        {
            // Arrange
            var file_io  = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only");
            var csv_file = new CSVFile <BankRecord>(file_io);

            csv_file.Load();
            var new_bank_record         = new BankRecord();
            var amount_containing_comma = "£1,234.55";

            new_bank_record.Load(string.Format("01/05/2017^{0}^^POS^Purchase^^^^^", amount_containing_comma));
            csv_file.Records.Add(new_bank_record);

            // Act
            csv_file.Write_to_csv_file("testing");

            // Assert
            var file_io_test_file = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only-testing");
            var new_csv_file      = new CSVFile <BankRecord>(file_io_test_file);

            new_csv_file.Load(
                true,
                ',');

            Assert.AreEqual(1234.55, new_csv_file.Records[5].Unreconciled_amount);
            Assert.AreEqual("\"Purchase\"", new_csv_file.Records[5].Description);
        }
Пример #12
0
        public void Will_copy_all_records_to_pending_file()
        {
            // Arrange
            var mock_expected_income_file = new Mock <ICSVFile <ExpectedIncomeRecord> >();
            var expected_income_records   = new List <ExpectedIncomeRecord>
            {
                new ExpectedIncomeRecord
                {
                    Description = "description1"
                },
                new ExpectedIncomeRecord
                {
                    Description = "description2"
                }
            };

            mock_expected_income_file.Setup(x => x.Records).Returns(expected_income_records);
            var expected_income_file = new ExpectedIncomeFile(mock_expected_income_file.Object);
            var mock_pending_file_io = new Mock <IFileIO <BankRecord> >();

            mock_pending_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(new List <BankRecord>());
            var pending_file = new CSVFile <BankRecord>(mock_pending_file_io.Object);

            pending_file.Load();
            Assert.AreEqual(0, pending_file.Records.Count);

            // Act
            expected_income_file.Copy_to_pending_file(pending_file);

            // Assert
            Assert.AreEqual(2, pending_file.Records.Count);
            Assert.AreEqual(expected_income_file.File.Records[0].Description, pending_file.Records[0].Description);
            Assert.AreEqual(expected_income_file.File.Records[1].Description, pending_file.Records[1].Description);
        }
Пример #13
0
        public void Can_filter_for_employer_expense_records_only()
        {
            // Arrange
            var mock_expected_income_file_io = new Mock <IFileIO <ExpectedIncomeRecord> >();
            var expected_income_csv_file     = new CSVFile <ExpectedIncomeRecord>(mock_expected_income_file_io.Object);
            var expected_description         = "description2";
            var expected_income_records      = new List <ExpectedIncomeRecord>
            {
                new ExpectedIncomeRecord
                {
                    Description = expected_description,
                    Code        = Codes.Expenses
                },
                new ExpectedIncomeRecord
                {
                    Description = "description1",
                    Code        = "other"
                }
            };

            mock_expected_income_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(expected_income_records);
            expected_income_csv_file.Load();
            var expected_income_file = new ExpectedIncomeFile(expected_income_csv_file);

            // Act
            expected_income_file.Filter_for_employer_expenses_only();

            // Assert
            Assert.AreEqual(1, expected_income_csv_file.Records.Count);
            Assert.AreEqual(expected_description, expected_income_csv_file.Records[0].Description);
        }
Пример #14
0
        public void WhenFinishing_WillReconcileAllRecords()
        {
            // Arrange
            var mock_income_file_io = new Mock <IFileIO <ExpectedIncomeRecord> >();
            var desc1  = "desc1";
            var desc2  = "desc2";
            var amount = 10;
            var expected_income_records = new List <ExpectedIncomeRecord>
            {
                new ExpectedIncomeRecord {
                    Matched = false, Unreconciled_amount = amount, Reconciled_amount = 0, Description = desc1
                },
                new ExpectedIncomeRecord {
                    Matched = true, Unreconciled_amount = amount, Reconciled_amount = 0, Description = desc2
                }
            };

            mock_income_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(expected_income_records);
            var csv_file = new CSVFile <ExpectedIncomeRecord>(mock_income_file_io.Object);

            csv_file.Load();
            var expected_income_file = new ExpectedIncomeFile(csv_file);

            // Act
            expected_income_file.Finish();

            // Assert
            Assert.AreEqual(amount, csv_file.Records[0].Unreconciled_amount);
            Assert.AreEqual(0, csv_file.Records[0].Reconciled_amount);
            Assert.AreEqual(desc1, csv_file.Records[0].Description);
            Assert.AreEqual(0, csv_file.Records[1].Unreconciled_amount);
            Assert.AreEqual(amount, csv_file.Records[1].Reconciled_amount);
            Assert.AreEqual(desc2, csv_file.Records[1].Description);
        }
        public void M_WhenMatchingSpecifiedRecords_AndMultipleMatchesExist_WillRemoveOriginalMatchesFromOwnedFile()
        {
            // Arrange
            var mock_bank_and_bank_in_loader = new Mock <IBankAndBankInLoader>();
            var matcher       = new BankAndBankInMatcher(this, new FakeSpreadsheetRepoFactory(), mock_bank_and_bank_in_loader.Object);
            var source_record = new ActualBankRecord
            {
                Date    = DateTime.Today,
                Amount  = 34.56,
                Match   = null,
                Matched = false
            };
            var bank_records = new List <BankRecord>
            {
                new BankRecord {
                    Description = "Match 01", Unreconciled_amount = 20.22, Type = "Type"
                },
                new BankRecord {
                    Description = "Match 02", Unreconciled_amount = 30.33
                },
                new BankRecord {
                    Description = "Match 02", Unreconciled_amount = 40.44
                }
            };
            var mock_bank_in_file_io = new Mock <IFileIO <BankRecord> >();

            mock_bank_in_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(bank_records);
            var bank_in_file = new CSVFile <BankRecord>(mock_bank_in_file_io.Object);

            bank_in_file.Load();
            var potential_matches = new List <IPotentialMatch> {
                new PotentialMatch {
                    Actual_records = new List <ICSVRecord>()
                }
            };

            potential_matches[0].Actual_records.Add(bank_records[0]);
            potential_matches[0].Actual_records.Add(bank_records[1]);
            potential_matches[0].Actual_records.Add(bank_records[2]);
            var index = 0;
            var record_for_matching = new RecordForMatching <ActualBankRecord>(source_record, potential_matches);

            foreach (var bank_record in bank_records)
            {
                Assert.IsTrue(bank_in_file.Records.Contains(bank_record));
            }

            // Act
            matcher.Match_specified_records(record_for_matching, index, bank_in_file);

            // Assert
            foreach (var bank_record in bank_records)
            {
                Assert.IsFalse(bank_in_file.Records.Contains(bank_record));
            }
        }
        public void M_WhenMatchingSpecifiedRecords_AndMultipleMatchesExist_WillRemoveOriginalMatchesFromOwnedFile()
        {
            // Arrange
            var matcher       = new CredCard2AndCredCard2InOutMatcher(this);
            var source_record = new CredCard2Record
            {
                Date    = DateTime.Today,
                Amount  = 34.56,
                Match   = null,
                Matched = false
            };
            var bank_records = new List <CredCard2InOutRecord>
            {
                new CredCard2InOutRecord {
                    Description = "Match 01", Unreconciled_amount = 20.22
                },
                new CredCard2InOutRecord {
                    Description = "Match 02", Unreconciled_amount = 30.33
                },
                new CredCard2InOutRecord {
                    Description = "Match 02", Unreconciled_amount = 40.44
                }
            };
            var mock_cred_card2_in_out_file_io = new Mock <IFileIO <CredCard2InOutRecord> >();

            mock_cred_card2_in_out_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(bank_records);
            var cred_card2_in_out_file = new CSVFile <CredCard2InOutRecord>(mock_cred_card2_in_out_file_io.Object);

            cred_card2_in_out_file.Load();
            var potential_matches = new List <IPotentialMatch> {
                new PotentialMatch {
                    Actual_records = new List <ICSVRecord>()
                }
            };

            potential_matches[0].Actual_records.Add(bank_records[0]);
            potential_matches[0].Actual_records.Add(bank_records[1]);
            potential_matches[0].Actual_records.Add(bank_records[2]);
            var index = 0;
            var record_for_matching = new RecordForMatching <CredCard2Record>(source_record, potential_matches);

            foreach (var bank_record in bank_records)
            {
                Assert.IsTrue(cred_card2_in_out_file.Records.Contains(bank_record));
            }

            // Act
            matcher.Match_specified_records(record_for_matching, index, cred_card2_in_out_file);

            // Assert
            foreach (var bank_record in bank_records)
            {
                Assert.IsFalse(cred_card2_in_out_file.Records.Contains(bank_record));
            }
        }
        public void M_CanCreateEmptyCSVFile()
        {
            // Act
            var file_io  = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory());
            var csv_file = new CSVFile <BankRecord>(file_io);

            csv_file.Load(false);

            // Assert
            Assert.AreEqual(0, csv_file.Records.Count);
        }
        public void Can_load_csv_file()
        {
            // Act & Arrange
            var file_io  = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankOut-formatted-date-only");
            var csv_file = new CSVFile <BankRecord>(file_io);

            csv_file.Load();

            // Assert
            Assert.AreEqual("01/03/2017^£5.00^^TILL^DescriptionBank013^^^^^", csv_file.File_contents[0]);
        }
Пример #19
0
        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_load_cred_card1_in_out_records()
        {
            // Act & Arrange
            var file_io  = new FileIO <CredCard1InOutRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "CredCard1InOut-formatted-date-only");
            var csv_file = new CSVFile <CredCard1InOutRecord>(file_io);

            csv_file.Load();

            // Assert
            Assert.AreEqual("ZZZSpecialDescription017", csv_file.Records[0].Description);
            Assert.AreEqual(32, csv_file.Records.Count);
            Assert.AreEqual("Description-CredCard1-form-007", csv_file.Records[31].Description);
        }
        public void Can_load_cred_card1_records()
        {
            // Act & Arrange
            var file_io  = new FileIO <CredCard1Record>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "CredCard1-Statement");
            var csv_file = new CSVFile <CredCard1Record>(file_io);

            csv_file.Load();

            // Assert
            Assert.AreEqual("22223333", csv_file.Records[0].Reference);
            Assert.AreEqual(50, csv_file.Records.Count);
            Assert.AreEqual("Description-CredCard1-001", csv_file.Records[49].Description);
        }
        public void Can_load_bank_out_records()
        {
            // Act & Arrange
            var file_io  = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankOut-formatted-date-only");
            var csv_file = new CSVFile <BankRecord>(file_io);

            csv_file.Load();

            // Assert
            Assert.AreEqual("TILL", csv_file.Records[0].Type);
            Assert.AreEqual(47, csv_file.Records.Count);
            Assert.AreEqual("ZZZEsterene plinkle (Inestimable plarts)", csv_file.Records[46].Description);
        }
        public void When_filtering_for_negative_records_all_are_converted_to_positive()
        {
            // Arrange
            var file_io  = new FileIO <ActualBankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "ActualBank-sample");
            var csv_file = new CSVFile <ActualBankRecord>(file_io);

            csv_file.Load();

            // Act
            csv_file.Filter_for_negative_records_only();

            // Assert
            Assert.AreEqual(115.30, csv_file.Records[50].Amount);
        }
        public void Will_order_records_by_date_on_loading_by_default()
        {
            // Act & Arrange
            var file_io  = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only");
            var csv_file = new CSVFile <BankRecord>(file_io);

            csv_file.Load();

            // Assert
            Assert.AreEqual("01/02/2017", csv_file.Records[0].Date.ToShortDateString());
            Assert.AreEqual("01/03/2017", csv_file.Records[1].Date.ToShortDateString());
            Assert.AreEqual("24/03/2017", csv_file.Records[2].Date.ToShortDateString());
            Assert.AreEqual("01/04/2017", csv_file.Records[3].Date.ToShortDateString());
            Assert.AreEqual("03/04/2017", csv_file.Records[4].Date.ToShortDateString());
        }
Пример #25
0
        public void Will_update_expected_income_record_when_matched()
        {
            // Arrange
            var match_desc     = "matchDesc";
            var match_date     = DateTime.Today.AddDays(2);
            var match_amount   = 22.22;
            var source_date    = DateTime.Today;
            var source_amount  = 22.22;
            var income_file_io = new Mock <IFileIO <ExpectedIncomeRecord> >();
            var income_records = new List <ExpectedIncomeRecord>
            {
                new ExpectedIncomeRecord
                {
                    Description         = match_desc,
                    Date                = match_date,
                    Unreconciled_amount = match_amount
                }
            };

            income_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(income_records);
            var income_file = new CSVFile <ExpectedIncomeRecord>(income_file_io.Object);

            income_file.Load();
            var expected_income_file = new ExpectedIncomeFile(income_file);
            var actual_bank_record   = new ActualBankRecord
            {
                Date   = source_date,
                Amount = source_amount
            };
            var bank_record = new BankRecord
            {
                Description         = match_desc,
                Date                = match_date,
                Unreconciled_amount = match_amount
            };

            // Act
            expected_income_file.Update_expected_income_record_when_matched(actual_bank_record, bank_record);

            // Assert
            Assert.AreEqual(match_desc, income_records[0].Description);
            Assert.AreEqual(match_amount, income_records[0].Unreconciled_amount);
            Assert.AreEqual(actual_bank_record, income_records[0].Match);
            Assert.AreEqual(true, income_records[0].Matched);
            Assert.AreEqual(match_date, income_records[0].Date);
            Assert.AreEqual(source_date, income_records[0].Date_paid);
            Assert.AreEqual(source_amount, income_records[0].Total_paid);
        }
        public void Can_filter_for_negative_records_only()
        {
            // Arrange
            var file_io  = new FileIO <ActualBankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "ActualBank-sample");
            var csv_file = new CSVFile <ActualBankRecord>(file_io);

            csv_file.Load();

            // Act
            csv_file.Filter_for_negative_records_only();

            // Assert
            Assert.AreEqual("'DIVIDE YOUR GREEN", csv_file.Records[0].Description);
            Assert.AreEqual(51, csv_file.Records.Count);
            Assert.AreEqual(4554.18, csv_file.Records[50].Balance);
        }
        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();
        }
        public void Can_load_actual_bank_records()
        {
            // Act & Arrange
            const bool doNotOrderByDate = false;
            var        file_io          = new FileIO <ActualBankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "ActualBank-sample");
            var        csv_file         = new CSVFile <ActualBankRecord>(file_io);

            csv_file.Load(
                true,
                null,
                doNotOrderByDate);

            // Assert
            Assert.AreEqual("'ZZZSpecialDescription001", csv_file.Records[0].Description);
            Assert.AreEqual(67, csv_file.Records.Count);
            Assert.AreEqual(4554.18, csv_file.Records[66].Balance);
        }
        public void Can_load_bank_in_records()
        {
            // Act & Arrange
            const bool doNotOrderByDate = false;
            var        file_io          = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only");
            var        csv_file         = new CSVFile <BankRecord>(file_io);

            csv_file.Load(
                true,
                null,
                doNotOrderByDate);

            // Assert
            Assert.AreEqual("PCL", csv_file.Records[0].Type);
            Assert.AreEqual(5, csv_file.Records.Count);
            Assert.AreEqual("ZZZThing3", csv_file.Records[4].Description);
        }
        public void Can_convert_commas_to_little_hats_for_bank_in()
        {
            // Arrange
            var file_io  = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-with-commas");
            var csv_file = new CSVFile <BankRecord>(file_io);

            csv_file.Load(true, ',');

            // Act
            csv_file.Convert_source_line_separators(',', '^');

            // Assert
            List <string> csv_lines = csv_file.All_records_as_source_lines();

            Assert.AreEqual("24/03/2017^£200.12^^PCL^ZZZSpecialDescription001^^^^^", csv_lines[0]);
            Assert.AreEqual("01/04/2017^£261.40^^PCL^ZZZSpecialDescription005^^^^^", csv_lines[1]);
            Assert.AreEqual("03/10/2018^£350.00^^ABC^ZZZThing1^^^^^", csv_lines[2]);
        }