Ejemplo n.º 1
0
        private IMatcher Get_reconciliaton_type_from_user()
        {
            IMatcher result = null;

            _input_output.Output_line("");
            _input_output.Output_line("What type are your third party and owned files?");
            _input_output.Output_options(new List <string>
            {
                ReconConsts.Accounting_type_01,
                ReconConsts.Accounting_type_02,
                ReconConsts.Accounting_type_03,
                ReconConsts.Accounting_type_04,
            });

            string input = _input_output.Get_generic_input(ReconConsts.Four_accounting_types);

            switch (input)
            {
            case "1": result = new CredCard1AndCredCard1InOutMatcher(_input_output); break;

            case "2": result = new CredCard2AndCredCard2InOutMatcher(_input_output); break;

            case "3": result = new BankAndBankInMatcher(_input_output, new BankAndBankInLoader(_spreadsheet_factory)); break;

            case "4": result = new BankAndBankOutMatcher(_input_output); break;
            }

            return(result);
        }
        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_WhenTransactionMatchingWillResetRecordMatchingDelegate()
        {
            // Arrange
            var mock_reconciliator            = new Mock <IReconciliator <CredCard2Record, CredCard2InOutRecord> >();
            var mock_reconciliation_interface = new Mock <IReconciliationInterface <CredCard2Record, CredCard2InOutRecord> >();
            var matcher = new CredCard2AndCredCard2InOutMatcher(this);

            // Act
            matcher.Do_transaction_matching(mock_reconciliator.Object, mock_reconciliation_interface.Object);

            // Assert
            mock_reconciliator.Verify(x => x.Reset_record_matcher());
        }
        public void M_WhenTransactionMatchingWillDoSemiAutomaticMatching()
        {
            // Arrange
            var mock_reconciliator            = new Mock <IReconciliator <CredCard2Record, CredCard2InOutRecord> >();
            var mock_reconciliation_interface = new Mock <IReconciliationInterface <CredCard2Record, CredCard2InOutRecord> >();
            var matcher = new CredCard2AndCredCard2InOutMatcher(this);

            // Act
            matcher.Do_transaction_matching(mock_reconciliator.Object, mock_reconciliation_interface.Object);

            // Assert
            mock_reconciliation_interface.Verify(x => x.Do_semi_automatic_matching());
        }
        public void M_WhenTransactionMatchingWillFilterThirdPartyFileForSpecifiedTransactionsOnly()
        {
            // Arrange
            var mock_reconciliator            = new Mock <IReconciliator <CredCard2Record, CredCard2InOutRecord> >();
            var mock_reconciliation_interface = new Mock <IReconciliationInterface <CredCard2Record, CredCard2InOutRecord> >();
            var matcher = new CredCard2AndCredCard2InOutMatcher(this);

            // Act
            matcher.Do_transaction_matching(mock_reconciliator.Object, mock_reconciliation_interface.Object);

            // Assert
            mock_reconciliator.Verify(x => x.Filter_third_party_file(matcher.Is_not_third_party_matching_transaction));
        }
        public void M_WhenMatchingSpecifiedRecords_AndMultipleMatchesExist_WillCreateNewRecordWithExplanatoryDescription()
        {
            // Arrange
            var mock_owned_file = new Mock <ICSVFile <CredCard2InOutRecord> >();

            mock_owned_file.Setup(x => x.Records).Returns(new List <CredCard2InOutRecord>());
            var matcher       = new CredCard2AndCredCard2InOutMatcher(this);
            var source_record = new CredCard2Record
            {
                Amount  = 34.56,
                Match   = null,
                Matched = false
            };
            var desc01            = "Thing 01";
            var desc02            = "Thing 02";
            var desc03            = "Thing 03";
            var potential_matches = new List <IPotentialMatch>
            {
                new PotentialMatch
                {
                    Actual_records = new List <ICSVRecord>
                    {
                        new CredCard2InOutRecord {
                            Description = $"{ReconConsts.Amazon_description} {desc01}", Unreconciled_amount = 20.22
                        },
                        new CredCard2InOutRecord {
                            Description = $"{ReconConsts.Amazon_description} {desc02}", Unreconciled_amount = 10.33
                        },
                        new CredCard2InOutRecord {
                            Description = $"{ReconConsts.Amazon_description} {desc03}", Unreconciled_amount = 2.01
                        }
                    }
                }
            };
            var index   = 0;
            var matches = potential_matches[index].Actual_records;
            var expected_description =
                $"{ReconConsts.SeveralAmazonTransactions} "
                + $"({desc01} {matches[0].Main_amount().To_csv_string(true)}, "
                + $"{desc02} {matches[1].Main_amount().To_csv_string(true)}, "
                + $"{desc03} {matches[2].Main_amount().To_csv_string(true)})"
                + $"{ReconConsts.TransactionsDontAddUp} ({potential_matches[index].Actual_records.Sum(x => x.Main_amount()).To_csv_string(true)})";
            var record_for_matching = new RecordForMatching <CredCard2Record>(source_record, potential_matches);

            // Act
            matcher.SetAmazonStrings();
            matcher.Match_specified_records(record_for_matching, index, mock_owned_file.Object);

            // Assert
            Assert.AreEqual(expected_description, record_for_matching.Matches[index].Actual_records[0].Description);
        }
        public void M_WillFilterOwnedFileForSpecifiedTransactionsOnly()
        {
            // Arrange
            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(new List <CredCard2InOutRecord> {
                new CredCard2InOutRecord {
                    Description = ReconConsts.iTunes_description + "1"
                },
                new CredCard2InOutRecord {
                    Description = "something"
                },
                new CredCard2InOutRecord {
                    Description = ReconConsts.iTunes_description + "2"
                },
                new CredCard2InOutRecord {
                    Description = ReconConsts.iTunes_description + "3"
                },
                new CredCard2InOutRecord {
                    Description = "something else"
                }
            });
            var cred_card2_in_out_file  = new GenericFile <CredCard2InOutRecord>(new CSVFile <CredCard2InOutRecord>(mock_cred_card2_in_out_file_io.Object));
            var mock_cred_card2_file_io = new Mock <IFileIO <CredCard2Record> >();

            mock_cred_card2_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null))
            .Returns(new List <CredCard2Record> {
                new CredCard2Record {
                    Description = $"\"HOLLYHILL {ReconConsts.iTunes_description}\""
                }
            });
            var cred_card2_file   = new GenericFile <CredCard2Record>(new CSVFile <CredCard2Record>(mock_cred_card2_file_io.Object));
            var data_loading_info = new DataLoadingInformation <CredCard2Record, CredCard2InOutRecord>
            {
                Sheet_name = MainSheetNames.Cred_card2, Loader = new CredCard2AndCredCard2InOutLoader()
            };
            var reconciliator = new Reconciliator <CredCard2Record, CredCard2InOutRecord>(data_loading_info, cred_card2_file, cred_card2_in_out_file);
            var matcher       = new CredCard2AndCredCard2InOutMatcher(this);

            // Act
            matcher.SetiTunesStrings();
            matcher.Filter_matching_transactions_from_cred_card2_in_out(reconciliator);

            // Assert
            Assert.AreEqual(3, reconciliator.Owned_file.Records.Count);
            Assert.AreEqual(ReconConsts.iTunes_description + "1", reconciliator.Owned_file.Records[0].Description);
            Assert.AreEqual(ReconConsts.iTunes_description + "2", reconciliator.Owned_file.Records[1].Description);
            Assert.AreEqual(ReconConsts.iTunes_description + "3", reconciliator.Owned_file.Records[2].Description);
        }
        public void M_WhenMatchingSpecifiedRecords_WillMatchRecordWithSpecifiedIndex()
        {
            // Arrange
            var mock_owned_file = new Mock <ICSVFile <CredCard2InOutRecord> >();

            mock_owned_file.Setup(x => x.Records).Returns(new List <CredCard2InOutRecord>());
            var matcher       = new CredCard2AndCredCard2InOutMatcher(this);
            var source_record = new CredCard2Record
            {
                Amount  = 34.56,
                Match   = null,
                Matched = false
            };
            var potential_matches = new List <IPotentialMatch>
            {
                new PotentialMatch {
                    Actual_records = new List <ICSVRecord> {
                        new CredCard2InOutRecord {
                            Matched = false
                        }
                    }
                },
                new PotentialMatch {
                    Actual_records = new List <ICSVRecord> {
                        new CredCard2InOutRecord {
                            Matched = false
                        }
                    }
                },
                new PotentialMatch {
                    Actual_records = new List <ICSVRecord> {
                        new CredCard2InOutRecord {
                            Matched = false
                        }
                    }
                }
            };
            var record_for_matching = new RecordForMatching <CredCard2Record>(source_record, potential_matches);
            var index = 1;

            // Act
            matcher.Match_specified_records(record_for_matching, index, mock_owned_file.Object);

            // Assert
            Assert.AreEqual(false, record_for_matching.Matches[0].Actual_records[0].Matched, "first record not matched");
            Assert.AreEqual(true, record_for_matching.Matches[1].Actual_records[0].Matched, "second record matched");
            Assert.AreEqual(false, record_for_matching.Matches[2].Actual_records[0].Matched, "third record not matched");
        }
        public void M_WhenMatchingSpecifiedRecords_AndMultipleMatchesAreChosen_AndSummedAmountsDontMatch_WillMarkDiscrepancy()
        {
            // Arrange
            var mock_owned_file = new Mock <ICSVFile <CredCard2InOutRecord> >();

            mock_owned_file.Setup(x => x.Records).Returns(new List <CredCard2InOutRecord>());
            var matcher           = new CredCard2AndCredCard2InOutMatcher(this);
            var potential_matches = new List <IPotentialMatch>
            {
                new PotentialMatch
                {
                    Actual_records = new List <ICSVRecord>
                    {
                        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 index           = 0;
            var matches         = potential_matches[index].Actual_records;
            var expected_amount = matches[0].Main_amount() + matches[1].Main_amount() + matches[2].Main_amount();
            var source_record   = new CredCard2Record
            {
                Date    = DateTime.Today,
                Amount  = expected_amount + 10,
                Match   = null,
                Matched = false
            };
            var record_for_matching = new RecordForMatching <CredCard2Record>(source_record, potential_matches);

            // Act
            matcher.Match_specified_records(record_for_matching, index, mock_owned_file.Object);

            // Assert
            Assert.IsTrue(record_for_matching.Matches[index].Actual_records[0].Description.Contains(ReconConsts.TransactionsDontAddUp));
        }
        public void M_WhenMatchingSpecifiedRecords_AndMultipleMatchesAreChosen_WillCreateNewRecordWithAmountToMatchSource()
        {
            // Arrange
            var mock_owned_file = new Mock <ICSVFile <CredCard2InOutRecord> >();

            mock_owned_file.Setup(x => x.Records).Returns(new List <CredCard2InOutRecord>());
            var matcher       = new CredCard2AndCredCard2InOutMatcher(this);
            var source_record = new CredCard2Record
            {
                Date    = DateTime.Today,
                Amount  = 34.56,
                Match   = null,
                Matched = false
            };
            var potential_matches = new List <IPotentialMatch>
            {
                new PotentialMatch
                {
                    Actual_records = new List <ICSVRecord>
                    {
                        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 index               = 0;
            var matches             = potential_matches[index].Actual_records;
            var expected_amount     = matches[0].Main_amount() + matches[1].Main_amount() + matches[2].Main_amount();
            var record_for_matching = new RecordForMatching <CredCard2Record>(source_record, potential_matches);

            // Act
            matcher.Match_specified_records(record_for_matching, index, mock_owned_file.Object);

            // Assert
            Assert.AreEqual(record_for_matching.SourceRecord.Main_amount(), record_for_matching.Matches[index].Actual_records[0].Main_amount());
        }
        public void M_WhenMatchingSpecifiedRecords_SourceAndMatchWillHaveMatchPropertiesPointingAtEachOther()
        {
            // Arrange
            var mock_owned_file = new Mock <ICSVFile <CredCard2InOutRecord> >();

            mock_owned_file.Setup(x => x.Records).Returns(new List <CredCard2InOutRecord>());
            var matcher       = new CredCard2AndCredCard2InOutMatcher(this);
            var source_record = new CredCard2Record
            {
                Date    = DateTime.Today,
                Amount  = 34.56,
                Match   = null,
                Matched = false
            };
            var potential_matches = new List <IPotentialMatch>
            {
                new PotentialMatch
                {
                    Actual_records = new List <ICSVRecord>
                    {
                        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 index = 0;
            var record_for_matching = new RecordForMatching <CredCard2Record>(source_record, potential_matches);

            // Act
            matcher.Match_specified_records(record_for_matching, index, mock_owned_file.Object);

            // Assert
            Assert.AreEqual(record_for_matching.SourceRecord, record_for_matching.Matches[index].Actual_records[0].Match, "match is pointing at source");
            Assert.AreEqual(record_for_matching.Matches[index].Actual_records[0], record_for_matching.SourceRecord.Match, "source is pointing at match");
        }
        public void M_WhenMatchingSpecifiedRecords_WillReplaceMultipleMatchesWithSingleMatch()
        {
            // Arrange
            var mock_owned_file = new Mock <ICSVFile <CredCard2InOutRecord> >();

            mock_owned_file.Setup(x => x.Records).Returns(new List <CredCard2InOutRecord>());
            var matcher       = new CredCard2AndCredCard2InOutMatcher(this);
            var source_record = new CredCard2Record
            {
                Amount  = 34.56,
                Match   = null,
                Matched = false
            };
            var potential_matches = new List <IPotentialMatch>
            {
                new PotentialMatch
                {
                    Actual_records = new List <ICSVRecord>
                    {
                        new CredCard2InOutRecord {
                            Description = "Match 01", Unreconciled_amount = 20
                        },
                        new CredCard2InOutRecord {
                            Description = "Match 02", Unreconciled_amount = 30
                        }
                    }
                }
            };
            var record_for_matching = new RecordForMatching <CredCard2Record>(source_record, potential_matches);
            var index = 0;

            Assert.AreEqual(2, record_for_matching.Matches[index].Actual_records.Count, "num matches before call");

            // Act
            matcher.Match_specified_records(record_for_matching, index, mock_owned_file.Object);

            // Assert
            Assert.AreEqual(1, record_for_matching.Matches[index].Actual_records.Count, "num matches after call");
        }
        public void Will_not_lose_previously_matched_records_when_files_are_refreshed()
        {
            // Arrange
            var some_other_third_party_description = "Some other third party Cred Card 2 description";
            var some_other_owned_description       = "Some other owned Cred Card 2 description";
            var third_party_data = new List <CredCard2Record>
            {
                new CredCard2Record {
                    Description = ReconConsts.Amazon_description
                },
                new CredCard2Record {
                    Description = some_other_third_party_description
                }
            };
            var mock_cred_card2_file_io = new Mock <IFileIO <CredCard2Record> >();

            mock_cred_card2_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(third_party_data);
            var cred_card2_file = new GenericFile <CredCard2Record>(new CSVFile <CredCard2Record>(mock_cred_card2_file_io.Object));
            var owned_data      = new List <CredCard2InOutRecord>
            {
                new CredCard2InOutRecord {
                    Description = $"{ReconConsts.Amazon_description} CredCard2InOutRecord01"
                },
                new CredCard2InOutRecord {
                    Description = $"{ReconConsts.Amazon_description} CredCard2InOutRecord02"
                },
                new CredCard2InOutRecord {
                    Description = $"{ReconConsts.Amazon_description} CredCard2InOutRecord03"
                },
                new CredCard2InOutRecord {
                    Description = some_other_owned_description
                }
            };
            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(owned_data);
            var cred_card2_in_out_file = new GenericFile <CredCard2InOutRecord>(new CSVFile <CredCard2InOutRecord>(mock_cred_card2_in_out_file_io.Object));
            var data_loading_info      = new DataLoadingInformation <CredCard2Record, CredCard2InOutRecord>
            {
                Sheet_name = MainSheetNames.Cred_card2, Loader = new CredCard2AndCredCard2InOutLoader()
            };
            var reconciliator = new Reconciliator <CredCard2Record, CredCard2InOutRecord>(data_loading_info, cred_card2_file, cred_card2_in_out_file);
            var expected_potential_matches = new List <PotentialMatch>
            {
                new PotentialMatch
                {
                    Actual_records = new List <ICSVRecord> {
                        owned_data[0], owned_data[1]
                    },
                    Console_lines = new List <ConsoleLine> {
                        new ConsoleLine {
                            Description_string = "Console Description"
                        }
                    }
                }
            };
            var matcher = new CredCard2AndCredCard2InOutMatcher(this);

            matcher.Filter_matching_transactions_from_cred_card2(reconciliator);
            matcher.Filter_matching_transactions_from_cred_card2_in_out(reconciliator);
            reconciliator.Set_match_finder((record, file) => expected_potential_matches);
            reconciliator.Set_record_matcher(matcher.Match_specified_records);
            reconciliator.Find_reconciliation_matches_for_next_third_party_record();
            reconciliator.Match_current_record(0);
            Assert.AreEqual(1, reconciliator.Third_party_file.Records.Count);
            Assert.AreEqual(2, reconciliator.Owned_file.Records.Count);
            Assert.IsFalse(reconciliator.Owned_file.Records[0].Matched);
            Assert.IsTrue(reconciliator.Owned_file.Records[1].Matched);
            Assert.IsTrue(reconciliator.Owned_file.Records[1].Description.Contains(ReconConsts.SeveralAmazonTransactions));

            // Act
            matcher.SetAmazonStrings();
            reconciliator.Refresh_files();

            // Assert
            Assert.AreEqual(2, reconciliator.Third_party_file.Records.Count);
            Assert.AreEqual(some_other_third_party_description, reconciliator.Third_party_file.Records[1].Description);
            Assert.AreEqual(3, reconciliator.Owned_file.Records.Count);
            Assert.IsFalse(reconciliator.Owned_file.Records[0].Matched);
            Assert.AreEqual(some_other_owned_description, reconciliator.Owned_file.Records[1].Description);
            Assert.AreEqual(third_party_data[0], reconciliator.Owned_file.Records[2].Match);
            Assert.IsTrue(reconciliator.Owned_file.Records[2].Matched);
            Assert.IsTrue(reconciliator.Owned_file.Records[2].Description.Contains(ReconConsts.SeveralAmazonTransactions));
        }