예제 #1
0
        public void M_CanReadLastRowOfSpecifiedWorksheetAsObjectList()
        {
            // Arrange
            var sheet_name    = "MockSheet";
            var fake_cell_row = new FakeCellRow().With_fake_data(new List <object>
            {
                "22/03/2018",
                "22.34",
                "last row",
                "7788"
            });
            var mock_spreadsheet_repo = new Mock <ISpreadsheetRepo>();

            mock_spreadsheet_repo.Setup(x => x.Read_last_row(sheet_name))
            .Returns(fake_cell_row);
            var spreadsheet = new Spreadsheet(mock_spreadsheet_repo.Object);

            // Act
            ICellRow actual_row = spreadsheet.Read_last_row(sheet_name);

            // Assert
            Assert.AreEqual(fake_cell_row.Read_cell(0), actual_row.Read_cell(0));
            Assert.AreEqual(fake_cell_row.Read_cell(1), actual_row.Read_cell(1));
            Assert.AreEqual(fake_cell_row.Read_cell(2), actual_row.Read_cell(2));
            Assert.AreEqual(fake_cell_row.Read_cell(3), actual_row.Read_cell(3));
        }
        public void M_WillReadFromCredCard1RecordCells()
        {
            // Arrange
            var      sheet_name           = "MockSheet";
            DateTime expected_date        = new DateTime(year: 2018, month: 6, day: 1);
            string   expected_reference   = "55556666";
            String   expected_description = "description3";
            Double   expected_amount      = 37958.90;
            var      excel_date           = expected_date.ToOADate();
            var      excel_date2          = expected_date.AddDays(1).ToOADate();
            var      fake_cell_row        = new FakeCellRow().With_fake_data(new List <object>
            {
                excel_date,
                excel_date2,
                expected_reference,
                expected_description,
                expected_amount
            });
            var mock_spreadsheet_repo = new Mock <ISpreadsheetRepo>();

            mock_spreadsheet_repo.Setup(x => x.Read_last_row(sheet_name)).Returns(fake_cell_row);
            var spreadsheet       = new Spreadsheet(mock_spreadsheet_repo.Object);
            var cred_card1_record = new CredCard1Record();
            var cells             = spreadsheet.Read_last_row(sheet_name);

            // Act
            cred_card1_record.Read_from_spreadsheet_row(cells);

            // Assert
            Assert.AreEqual(expected_date, cred_card1_record.Date);
            Assert.AreEqual(expected_reference, cred_card1_record.Reference);
            Assert.AreEqual(expected_description, cred_card1_record.Description);
            Assert.AreEqual(expected_amount, cred_card1_record.Amount);
        }
예제 #3
0
        public void M_CanAddUnreconciledRowsToCredCard1InOutCsvFileAndPutInDateOrder()
        {
            // Arrange
            var    sheet_name     = "MockSheet";
            double date           = 43345;
            var    amount         = 22.34;
            var    text1          = "first row";
            var    text2          = "second row";
            var    text3          = "third row";
            var    fake_cell_row1 = new FakeCellRow().With_fake_data(new List <object> {
                date, amount, null, text2
            });
            var fake_cell_row3 = new FakeCellRow().With_fake_data(new List <object> {
                date + 1, amount, null, text3
            });
            var fake_cell_row2 = new FakeCellRow().With_fake_data(new List <object> {
                date - 1, amount, null, text1
            });
            var mock_spreadsheet_repo = new Mock <ISpreadsheetRepo>();

            mock_spreadsheet_repo.Setup(x => x.Find_row_number_of_last_row_containing_cell(sheet_name, Dividers.Divider_text, 2))
            .Returns(1);
            mock_spreadsheet_repo.Setup(x => x.Last_row_number(sheet_name)).Returns(4);
            mock_spreadsheet_repo.Setup(x => x.Read_specified_row(sheet_name, 2)).Returns(fake_cell_row1);
            mock_spreadsheet_repo.Setup(x => x.Read_specified_row(sheet_name, 3)).Returns(fake_cell_row2);
            mock_spreadsheet_repo.Setup(x => x.Read_specified_row(sheet_name, 4)).Returns(fake_cell_row3);
            var spreadsheet = new Spreadsheet(mock_spreadsheet_repo.Object);

            var expected_num_records = 3;

            var csv_file = new CSVFileFactory <CredCard1InOutRecord>().Create_csv_file(false);

            // Act
            spreadsheet.Add_unreconciled_rows_to_csv_file <CredCard1InOutRecord>(sheet_name, csv_file);

            // Assert
            Assert.AreEqual(expected_num_records, csv_file.Records.Count);
            Assert.IsTrue(csv_file.Records[0].Source_line.Contains(text1), $"line 0 should contain correct text");
            Assert.IsTrue(csv_file.Records[1].Source_line.Contains(text2), $"line 1 should contain correct text");
            Assert.IsTrue(csv_file.Records[2].Source_line.Contains(text3), $"line 1 should contain correct text");
        }