public void ATC7121b_AXDuplicateBPAYpayment()
        {
            #region Start Up Excel
            //MyApp = new Excel.Application();
            //MyApp.Visible = false;
            //MyBook = MyApp.Workbooks.Open(DatasourceDir + "\\TenancyRequests.xlsx");
            MyBook = MyApp.Workbooks.Open(DatasourceDir + @"\TenancyRequests.xlsx", 0, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            MySheet = (Excel.Worksheet)MyBook.Sheets[Properties.Settings.Default.ENVIRONMENT.ToString()];
            MyRange = MySheet.UsedRange;

            //Get specific row for the data
            int testDataRows = MyRange.Rows.Count;
            int MyRow = 0;
            for (int i = 2; i <= testDataRows; i++)
            {
                if (MyRange.Cells[i, 1].Value.ToString() == "7121")
                {
                    MyRow = i;
                    break;
                }
            }
            #endregion

            string referenceNumber = MyRange.Cells[MyRow, TenancyRequestSchema.GetColumnIndex("PAY_REF_NUMBER")].Value.ToString();
            string tenancyrequest = MyRange.Cells[MyRow, TenancyRequestSchema.GetColumnIndex("TR_NUMBER")].Value.ToString();
            string fileLocation = MyRange.Cells[MyRow, TenancyRequestSchema.GetColumnIndex("OUTFILE")].Value.ToString();
            string fileLocation2 = MyRange.Cells[MyRow, TenancyRequestSchema.GetColumnIndex("MISC1")].Value.ToString();

            Homepage homePage = new Homepage();
            homePage.ClickHomeTab();
            homePage.ClickBondManagementTab();
            homePage.ClickPaymentsLink();
            homePage.ClickBPayFileLink(); ;

            BPayFilePage bPayFilePage = new BPayFilePage();

            //import 1st file
            bPayFilePage.ClickImportMenuItem();
            BPayFileImportPage bPayFileImportPage = new BPayFileImportPage();
            Assert.IsTrue(bPayFileImportPage.GetWindowExistStatus());
            bPayFileImportPage.SetMoveFileCheckBox(true);
            bPayFileImportPage.SetProcessFileCheckBox(true);
            bPayFileImportPage.SetImportPathEdit("");
            bPayFileImportPage.SetFileNameEdit(fileLocation);
            bPayFileImportPage.ClickOKButton();
            InfoLogPage infoLogPage = new InfoLogPage();
            //check that file imported successful
            Assert.IsTrue(infoLogPage.GetTreeItemExists("File imported with identifier", "Importing BPAY file"));
            infoLogPage.ClickClearButton();
            infoLogPage.ClickCloseButton();

            //import 2nd file
            bPayFilePage.ClickImportMenuItem();
            bPayFileImportPage = new BPayFileImportPage();
            Assert.IsTrue(bPayFileImportPage.GetWindowExistStatus());
            bPayFileImportPage.SetMoveFileCheckBox(true);
            bPayFileImportPage.SetProcessFileCheckBox(true);
            bPayFileImportPage.SetImportPathEdit("");
            bPayFileImportPage.SetFileNameEdit(fileLocation2);
            bPayFileImportPage.ClickOKButton();
            infoLogPage = new InfoLogPage();

            //check that file imported successful
            Assert.IsTrue(infoLogPage.GetTreeItemExists("File imported with identifier", "Importing BPAY file"));
            infoLogPage.ClickClearButton();
            infoLogPage.ClickCloseButton();

            bPayFilePage.ClickCloseButton();

            //Navigate to Outbound CRM and click ok
            homePage.ClickCRMOutboundNotificationsLink();
            OutboundCRMIntegrationPage outBoundCRMIntegration = new OutboundCRMIntegrationPage();
            Assert.IsTrue(outBoundCRMIntegration.GetWindowExistStatus());
            outBoundCRMIntegration.ClickOKButton();

            //Navigate to Payments/BPay file exceptions
            homePage.ClickPaymentsLink();
            homePage.ClickBPayFileExceptionLink();
            //Order by created date

            //Confirm customer referance number exists
            BPayFileExceptionsPage bPayFileExceptionPage = new BPayFileExceptionsPage();

            Table table = new Table(bPayFileExceptionPage.GetFileExceptionTable());
            table.FilterCellValue("Customer reference number");
            bPayFileExceptionPage.ClickFilterMenuItem();

            FilterPage filterPage = new FilterPage();
            filterPage.SetFilterText("Customer reference number", referenceNumber);
            filterPage.ClickOkButton();
            StringAssert.Contains(table.GetCellValue("Customer reference number", referenceNumber, "Rejection reason"), "Duplicate CRN");
            bPayFileExceptionPage.ClickCloseButton();

            #region Shut down Excel
            MyBook.Save();
            MyBook.Close();
            MyApp.Quit();
            #endregion
        }
        public void ATC6740_AXPostBPAYpaymentswithunknownreferencenumber()
        {
            string dateValue = DateTime.Today.AddDays(-1).ToString("yyyyMMdd");
            string transDesc = "BPAY " + DateTime.Today.AddDays(-1).ToString("d/MM/yyyy");
            Random random = new Random();
            int randomNum = random.Next(1000, 9999);
            string fileLocation = Utils.BPayFileCreator.bPayUnknownClientFileCreator(dateValue, randomNum);
            string referenceNumber = Utils.BPayFileReaderClass.GetPaymentReference1File(fileLocation).ToString();

            Homepage homePage = new Homepage();
            homePage.ClickCompanyButton();

            SelectCompanyPage selectCompanyPage = new SelectCompanyPage();
            Table table = new Table(selectCompanyPage.GetCompanyListTable());
            table.ClickCellValue("Company", "RTB", "Company");
            selectCompanyPage.ClickOkButton();

            homePage.ClickHomeTab();
            homePage.ClickBondManagementTab();

            homePage.ClickPaymentsLink();
            homePage.ClickBPayFileLink(); ;

            BPayFilePage bPayFilePage = new BPayFilePage();
            bPayFilePage.ClickImportMenuItem();

            BPayFileImportPage bPayFileImportPage = new BPayFileImportPage();
            Assert.IsTrue(bPayFileImportPage.GetWindowExistStatus());
            bPayFileImportPage.SetMoveFileCheckBox(true);
            bPayFileImportPage.SetProcessFileCheckBox(true);
            //bPayFileImportPage.SetImportPathEdit(@"P:\Dynamics AX\Bank files\Bpay\Paul");
            bPayFileImportPage.SetImportPathEdit("");
            bPayFileImportPage.SetFileNameEdit(fileLocation);
            bPayFileImportPage.ClickOKButton();

            InfoLogPage infoLogPage = new InfoLogPage();
            string rtbTreeItem = infoLogPage.GetTreeItemName("Processing BPAY file RTB-", "Importing BPAY file");
            string RTB = rtbTreeItem.Substring(21, 10);
            string bvdTreeItem = infoLogPage.GetTreeItemName("Posting journal BDV", "Importing BPAY file");
            string BVD = bvdTreeItem.Substring(16, 9);
            Assert.IsTrue(infoLogPage.GetTreeItemExists("BPAY exception 'Invalid CRN' has been recorded for this line", "Importing BPAY file"));
            infoLogPage.ClickClearButton();
            infoLogPage.ClickCloseButton();
            bPayFilePage.ClickCloseButton();

            homePage.ClickHomeTab();
            homePage.ClickBondManagementTab();

            homePage.ClickCRMOutboundNotificationsLink();
            OutboundCRMIntegrationPage outboundCRMIntegrationPage = new OutboundCRMIntegrationPage();
            outboundCRMIntegrationPage.ClickOKButton();

            //Navigate to Payments/BPay file exceptions
            homePage.ClickPaymentsLink();
            homePage.ClickBPayFileExceptionLink();

            //Confirm customer referance number exists
            BPayFileExceptionsPage bPayFileExceptionPage = new BPayFileExceptionsPage();

            table = new Table(bPayFileExceptionPage.GetFileExceptionTable());
            table.FilterCellValue("Customer reference number");
            bPayFileExceptionPage.ClickFilterMenuItem();
            FilterPage filterPage = new FilterPage();
            filterPage.SetFilterText("Customer reference number", referenceNumber);
            filterPage.ClickOkButton();

            StringAssert.Contains(table.GetCellValue("Customer reference number", referenceNumber, "Rejection reason"), "Invalid CRN");
            bPayFileExceptionPage.ClickCloseButton();
        }