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_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");
        }
        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());
        }
        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_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");
        }