Exemple #1
0
        public void Create_new_combined_record(
            RecordForMatching <ActualBankRecord> record_for_matching,
            int match_index,
            ICSVFile <BankRecord> owned_file)
        {
            var sum_of_all_matches =
                record_for_matching.Matches[match_index].Actual_records.Sum(x => x.Main_amount());
            var missing_balance       = record_for_matching.SourceRecord.Main_amount() - sum_of_all_matches;
            var expense_amounts_match = record_for_matching.SourceRecord.Main_amount()
                                        .Double_equals(sum_of_all_matches);

            BankRecord new_match = New_combined_record(
                record_for_matching,
                match_index,
                expense_amounts_match,
                sum_of_all_matches);

            Update_expected_income_and_owned_files(
                record_for_matching,
                match_index,
                expense_amounts_match,
                sum_of_all_matches,
                missing_balance,
                owned_file);

            record_for_matching.Matches[match_index].Actual_records.Clear();
            record_for_matching.Matches[match_index].Actual_records.Add(new_match);
            owned_file.Add_record_permanently(new_match);
        }
 public void Match_specified_records <TThirdPartyType, TOwnedType>(
     RecordForMatching <TThirdPartyType> record_for_matching,
     int match_index,
     ICSVFile <TOwnedType> owned_file)
     where TThirdPartyType : ICSVRecord, new()
     where TOwnedType : ICSVRecord, new()
 {
     if (record_for_matching.Matches[match_index].Actual_records.Count > 1)
     {
         var new_match = new TOwnedType
         {
             Date        = record_for_matching.SourceRecord.Date,
             Description = Create_new_description(record_for_matching.Matches[match_index])
         };
         (new_match as BankRecord).Unreconciled_amount = record_for_matching.Matches[match_index].Actual_records.Sum(x => x.Main_amount());
         (new_match as BankRecord).Type = (record_for_matching.Matches[match_index].Actual_records[0] as BankRecord).Type;
         foreach (var actual_record in record_for_matching.Matches[match_index].Actual_records)
         {
             _bank_and_bank_in_loader.Update_expected_income_record_when_matched(record_for_matching.SourceRecord, (TOwnedType)actual_record);
             owned_file.Remove_record_permanently((TOwnedType)actual_record);
         }
         record_for_matching.Matches[match_index].Actual_records.Clear();
         record_for_matching.Matches[match_index].Actual_records.Add(new_match);
         owned_file.Add_record_permanently(new_match);
     }
     else
     {
         _bank_and_bank_in_loader.Update_expected_income_record_when_matched(
             record_for_matching.SourceRecord,
             (TOwnedType)record_for_matching.Matches[match_index].Actual_records[0]);
     }
     Match_records(record_for_matching.SourceRecord, record_for_matching.Matches[match_index].Actual_records[0]);
 }
        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));
            }
        }
Exemple #5
0
 public void Match_specified_records(
     RecordForMatching <CredCard2Record> record_for_matching,
     int match_index,
     ICSVFile <CredCard2InOutRecord> owned_file)
 {
     if (record_for_matching.Matches[match_index].Actual_records.Count > 1)
     {
         Create_new_combined_record(record_for_matching, match_index, owned_file);
     }
     Match_records(record_for_matching.SourceRecord, record_for_matching.Matches[match_index].Actual_records[0]);
 }
Exemple #6
0
        private CredCard2InOutRecord New_combined_record(
            RecordForMatching <CredCard2Record> record_for_matching,
            int match_index)
        {
            var new_match = new CredCard2InOutRecord
            {
                Date        = record_for_matching.SourceRecord.Date,
                Description = Create_new_description(record_for_matching, match_index)
            };

            new_match.Unreconciled_amount = record_for_matching.SourceRecord.Main_amount();
            return(new_match);
        }
        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_WhenMatchingSpecifiedRecords_WillUpdateExpectedIncomeRecordForEachOriginalMatch()
        {
            // Arrange
            var mock_bank_and_bank_in_loader = new Mock <IBankAndBankInLoader>();
            var mock_owned_file = new Mock <ICSVFile <BankRecord> >();

            mock_owned_file.Setup(x => x.Records).Returns(new List <BankRecord>());
            var matcher       = new BankAndBankInMatcher(this, new FakeSpreadsheetRepoFactory(), mock_bank_and_bank_in_loader.Object);
            var desc0         = "Source 01";
            var source_record = new ActualBankRecord
            {
                Date = DateTime.Today.AddDays(10), Amount = 40.44, Description = desc0
            };
            var desc1             = "Match 01";
            var desc2             = "Match 02";
            var amount1           = 20.22;
            var amount2           = 30.33;
            var date1             = DateTime.Today;
            var date2             = DateTime.Today.AddDays(1);
            var potential_matches = new List <IPotentialMatch>
            {
                new PotentialMatch
                {
                    Actual_records = new List <ICSVRecord>
                    {
                        new BankRecord {
                            Description = desc1, Unreconciled_amount = amount1, Date = date1
                        },
                        new BankRecord {
                            Description = desc2, Unreconciled_amount = amount2, Date = date2
                        }
                    }
                }
            };
            var index = 0;
            var record_for_matching = new RecordForMatching <ActualBankRecord>(source_record, potential_matches);

            Assert.AreEqual(0, matcher.MatchedExpectedIncomeRecords.Count);

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

            // Assert
            mock_bank_and_bank_in_loader.Verify(x => x.Update_expected_income_record_when_matched(
                                                    It.Is <ICSVRecord>(y => y.Description == desc0),
                                                    It.Is <ICSVRecord>(y => y.Description == desc1)));
            mock_bank_and_bank_in_loader.Verify(x => x.Update_expected_income_record_when_matched(
                                                    It.Is <ICSVRecord>(y => y.Description == desc0),
                                                    It.Is <ICSVRecord>(y => y.Description == desc2)));
        }
        public void M_WhenMatchingSpecifiedRecords_WillMatchRecordWithSpecifiedIndex()
        {
            // Arrange
            var mock_bank_and_bank_in_loader = new Mock <IBankAndBankInLoader>();
            var mock_owned_file = new Mock <ICSVFile <BankRecord> >();

            mock_owned_file.Setup(x => x.Records).Returns(new List <BankRecord>());
            var matcher       = new BankAndBankInMatcher(this, new FakeSpreadsheetRepoFactory(), mock_bank_and_bank_in_loader.Object);
            var source_record = new ActualBankRecord
            {
                Amount  = 34.56,
                Match   = null,
                Matched = false
            };
            var potential_matches = new List <IPotentialMatch>
            {
                new PotentialMatch {
                    Actual_records = new List <ICSVRecord> {
                        new BankRecord {
                            Matched = false
                        }
                    }
                },
                new PotentialMatch {
                    Actual_records = new List <ICSVRecord> {
                        new BankRecord {
                            Matched = false
                        }
                    }
                },
                new PotentialMatch {
                    Actual_records = new List <ICSVRecord> {
                        new BankRecord {
                            Matched = false
                        }
                    }
                }
            };
            var record_for_matching = new RecordForMatching <ActualBankRecord>(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");
        }
Exemple #10
0
        public void Create_new_combined_record(
            RecordForMatching <CredCard2Record> record_for_matching,
            int match_index,
            ICSVFile <CredCard2InOutRecord> owned_file)
        {
            foreach (var actual_record in record_for_matching.Matches[match_index].Actual_records)
            {
                owned_file.Remove_record_permanently((CredCard2InOutRecord)actual_record);
            }
            CredCard2InOutRecord new_match = New_combined_record(record_for_matching, match_index);

            record_for_matching.Matches[match_index].Actual_records.Clear();
            record_for_matching.Matches[match_index].Actual_records.Add(new_match);
            owned_file.Add_record_permanently(new_match);
        }
        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");
        }
Exemple #12
0
        private BankRecord New_combined_record(
            RecordForMatching <ActualBankRecord> record_for_matching,
            int match_index,
            bool expense_amounts_match,
            double sum_of_all_matches)
        {
            var new_match = new BankRecord
            {
                Date        = record_for_matching.SourceRecord.Date,
                Description = Create_new_description(record_for_matching.Matches[match_index], expense_amounts_match, sum_of_all_matches)
            };

            new_match.Unreconciled_amount = record_for_matching.SourceRecord.Main_amount();
            new_match.Type = (record_for_matching.Matches[match_index].Actual_records[0] as BankRecord).Type;
            return(new_match);
        }
Exemple #13
0
        public void Match_BankIn_records(
            RecordForMatching <ActualBankRecord> record_for_matching,
            int match_index,
            ICSVFile <BankRecord> owned_file)
        {
            var match = (BankRecord)record_for_matching.Matches[match_index].Actual_records[0];

            if (match.Type == Codes.ExpectedInBankTransaction)
            {
                _bank_and_bank_in_loader.Update_expected_income_record_when_matched(
                    record_for_matching.SourceRecord,
                    match);
            }

            Reconciliator <ActualBankRecord, BankRecord> .Match_specified_records(record_for_matching, match_index, owned_file);
        }
        public void M_WhenMatchingSpecifiedRecords_AndMultipleMatchesExist_WillCreateNewRecordWithAllAmountsAddedTogether()
        {
            // Arrange
            var mock_bank_and_bank_in_loader = new Mock <IBankAndBankInLoader>();
            var mock_owned_file = new Mock <ICSVFile <BankRecord> >();

            mock_owned_file.Setup(x => x.Records).Returns(new List <BankRecord>());
            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 potential_matches = new List <IPotentialMatch>
            {
                new PotentialMatch
                {
                    Actual_records = new List <ICSVRecord>
                    {
                        new BankRecord {
                            Description = "Match 01", Unreconciled_amount = 20.22
                        },
                        new BankRecord {
                            Description = "Match 02", Unreconciled_amount = 30.33
                        },
                        new BankRecord {
                            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 <ActualBankRecord>(source_record, potential_matches);

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

            // Assert
            Assert.AreEqual(expected_amount, record_for_matching.Matches[index].Actual_records[0].Main_amount());
        }
Exemple #15
0
 public void Match_expense_records(
     RecordForMatching <ActualBankRecord> record_for_matching,
     int match_index,
     ICSVFile <BankRecord> owned_file)
 {
     if (record_for_matching.Matches[match_index].Actual_records.Count > 1)
     {
         Create_new_combined_record(record_for_matching, match_index, owned_file);
     }
     else
     {
         _bank_and_bank_in_loader.Update_expected_income_record_when_matched(
             record_for_matching.SourceRecord,
             (BankRecord)record_for_matching.Matches[match_index].Actual_records[0]);
     }
     Match_records(
         record_for_matching.SourceRecord,
         (record_for_matching.Matches[match_index].Actual_records[0] as BankRecord));
 }
        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_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_SourceAndMatchWillHaveMatchPropertiesPointingAtEachOther()
        {
            // Arrange
            var mock_bank_and_bank_in_loader = new Mock <IBankAndBankInLoader>();
            var mock_owned_file = new Mock <ICSVFile <BankRecord> >();

            mock_owned_file.Setup(x => x.Records).Returns(new List <BankRecord>());
            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 potential_matches = new List <IPotentialMatch>
            {
                new PotentialMatch
                {
                    Actual_records = new List <ICSVRecord>
                    {
                        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 index = 0;
            var record_for_matching = new RecordForMatching <ActualBankRecord>(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_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");
        }
Exemple #20
0
        private void Update_expected_income_and_owned_files(
            RecordForMatching <ActualBankRecord> record_for_matching,
            int match_index,
            bool expense_amounts_match,
            double sum_of_all_matches,
            double missing_balance,
            ICSVFile <BankRecord> owned_file)
        {
            foreach (var actual_record in record_for_matching.Matches[match_index].Actual_records)
            {
                _bank_and_bank_in_loader.Update_expected_income_record_when_matched(record_for_matching.SourceRecord, actual_record);
                owned_file.Remove_record_permanently((BankRecord)actual_record);
            }

            if (!expense_amounts_match)
            {
                _bank_and_bank_in_loader.Create_new_expenses_record_to_match_balance(
                    record_for_matching.SourceRecord,
                    missing_balance);
            }
        }
Exemple #21
0
        private string Create_new_description(
            RecordForMatching <CredCard2Record> record_for_matching,
            int match_index)
        {
            var combined_amounts = $"{Get_description_without_specific_qualifier(record_for_matching.Matches[match_index].Actual_records[0])}";

            for (int count = 1; count < record_for_matching.Matches[match_index].Actual_records.Count; count++)
            {
                var match = record_for_matching.Matches[match_index].Actual_records[count];
                combined_amounts += $", {Get_description_without_specific_qualifier(match)}";
            }

            var sum_of_all_matches    = record_for_matching.Matches[match_index].Actual_records.Sum(x => x.Main_amount());
            var expense_amounts_match = record_for_matching.SourceRecord.Main_amount()
                                        .Double_equals(sum_of_all_matches);
            var extra_text = expense_amounts_match
                ? ""
                : $"{_transactions_dont_add_up} ({sum_of_all_matches.To_csv_string(true)})";

            return($"{_several_transactions} ({combined_amounts}){extra_text}");
        }
        public void M_WhenMatchingSpecifiedRecords_WillReplaceMultipleMatchesWithSingleMatch()
        {
            // Arrange
            var mock_bank_and_bank_in_loader = new Mock <IBankAndBankInLoader>();
            var mock_owned_file = new Mock <ICSVFile <BankRecord> >();

            mock_owned_file.Setup(x => x.Records).Returns(new List <BankRecord>());
            var matcher       = new BankAndBankInMatcher(this, new FakeSpreadsheetRepoFactory(), mock_bank_and_bank_in_loader.Object);
            var source_record = new ActualBankRecord
            {
                Amount  = 34.56,
                Match   = null,
                Matched = false
            };
            var potential_matches = new List <IPotentialMatch>
            {
                new PotentialMatch
                {
                    Actual_records = new List <ICSVRecord>
                    {
                        new BankRecord {
                            Description = "Match 01", Unreconciled_amount = 20
                        },
                        new BankRecord {
                            Description = "Match 02", Unreconciled_amount = 30
                        }
                    }
                }
            };
            var record_for_matching = new RecordForMatching <ActualBankRecord>(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");
        }