Example #1
0
        //"[^a-zA-Z0-9-]+
        public void AdaptDescription_ShouldCleanNotNeededSymbols()
        {
            string testFile = $@"{projectDirectory}\ProductExcelSheets.app.tests\testGlasses_{this.GetCurrentMethod()}.xlsx";

            if (File.Exists(testFile))
            {
                File.Delete(testFile);
            }

            File.Copy(filePath, testFile);

            ExcelManager excelManager = new ExcelManager(mockedFileLogger.Object, "test.info", testFile);

            string sheetName = "SaintGobain";

            excelManager.AdaptDescription(sheetName);

            var fileinfo = new FileInfo(testFile);

            if (fileinfo.Exists)
            {
                using (ExcelPackage excelPackage = new ExcelPackage(fileinfo))
                {
                    ExcelWorkbook  excelWorkBook  = excelPackage.Workbook;
                    ExcelWorksheet excelWorksheet = excelWorkBook.Worksheets.Where(s => s.Name == sheetName).FirstOrDefault();

                    var columnDescription = excelWorksheet.Cells["1:1"].First(c => c.Value.ToString() == "Description").Start.Column;

                    int rangeMaxRows = excelWorksheet.Dimension.End.Row;
                    for (int i = 2; i <= rangeMaxRows; i++)
                    {
                        string cellStrDescription = excelWorksheet.Cells[i, columnDescription].Value.ToString();

                        Assert.IsTrue(cellStrDescription.Length <= DescriptionStringMaxLength);

                        Regex re = new Regex(@"^[a-zA-Z0-9- ]+$");
                        Assert.IsTrue(re.IsMatch(cellStrDescription));
                    }
                }
            }

            this.RemoveFile(testFile);
        }