コード例 #1
0
        public void AddQuantities_ShouldRecognizeByEurocodeAndManifacturer_And_addquantitiesWitPlace()
        {
            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 sourceSheet = "quantities";
            string targetSheet = "SaintGobain";

            excelManager.AddQuantities(sourceSheet, targetSheet);

            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 == targetSheet).FirstOrDefault();

                    var euroCodeTargetColumn        = excelWorksheet.Cells["1:1"].First(c => c.Value.ToString() == "Eurocode").Start.Column;
                    var liulinTargetColumn          = excelWorksheet.Cells["1:1"].First(c => c.Value.ToString() == "Liulin").Start.Column;
                    var slatinaTargetColumn         = excelWorksheet.Cells["1:1"].First(c => c.Value.ToString() == "Slatina").Start.Column;
                    var rouseTargetColumn           = excelWorksheet.Cells["1:1"].First(c => c.Value.ToString() == "Rouse").Start.Column;
                    var quantityLiulinTargetColumn  = excelWorksheet.Cells["1:1"].First(c => c.Value.ToString() == "Q_Liulin").Start.Column;
                    var quantitySlatinaTargetColumn = excelWorksheet.Cells["1:1"].First(c => c.Value.ToString() == "Q_Slatina").Start.Column;
                    var quantityRouseTargetColumn   = excelWorksheet.Cells["1:1"].First(c => c.Value.ToString() == "Q_Rouse").Start.Column;

                    int rangeMaxRows = excelWorksheet.Dimension.End.Row;
                    for (int i = 2; i <= rangeMaxRows; i++)
                    {
                        string cellStrEurocode = excelWorksheet.Cells[i, euroCodeTargetColumn].Value.ToString();
                        if (cellStrEurocode == "2436LGNS4RD")
                        {
                            string cellLiulin = excelWorksheet.Cells[i, liulinTargetColumn].Value.ToString();
                            Assert.AreEqual(cellLiulin, "Стойка 1");
                            string cellSlatina = excelWorksheet.Cells[i, slatinaTargetColumn].Value.ToString();
                            Assert.AreEqual(cellSlatina, "Стойка 2");
                            string cellRuse = excelWorksheet.Cells[i, rouseTargetColumn].Value.ToString();
                            Assert.AreEqual(cellRuse, "Стойка 3");
                            string cellQLiulin = excelWorksheet.Cells[i, quantityLiulinTargetColumn].Value.ToString();
                            Assert.AreEqual(cellQLiulin, "0");
                            string cellQSlatina = excelWorksheet.Cells[i, quantitySlatinaTargetColumn].Value.ToString();
                            Assert.AreEqual(cellQSlatina, "1");
                            string cellQRuse = excelWorksheet.Cells[i, quantityRouseTargetColumn].Value.ToString();
                            Assert.AreEqual(cellQRuse, "0");
                        }
                        else if (cellStrEurocode == "3030ASMM")
                        {
                            string cellLiulin = excelWorksheet.Cells[i, liulinTargetColumn].Value.ToString();
                            Assert.AreEqual(cellLiulin, "16");
                            string cellSlatina = excelWorksheet.Cells[i, slatinaTargetColumn].Value.ToString();
                            Assert.AreEqual(cellSlatina, "18");
                            string cellRuse = excelWorksheet.Cells[i, rouseTargetColumn].Value.ToString();
                            Assert.AreEqual(cellRuse, "35");
                            string cellQLiulin = excelWorksheet.Cells[i, quantityLiulinTargetColumn].Value.ToString();
                            Assert.AreEqual(cellQLiulin, "0");
                            string cellQSlatina = excelWorksheet.Cells[i, quantitySlatinaTargetColumn].Value.ToString();
                            Assert.AreEqual(cellQSlatina, "1");
                            string cellQRuse = excelWorksheet.Cells[i, quantityRouseTargetColumn].Value.ToString();
                            Assert.AreEqual(cellQRuse, "2");
                        }
                        else if (cellStrEurocode == "4633AGN")
                        {
                            string cellLiulin = excelWorksheet.Cells[i, liulinTargetColumn].Value.ToString();
                            Assert.AreEqual(cellLiulin, "55");
                            string cellSlatina = excelWorksheet.Cells[i, slatinaTargetColumn].Value.ToString();
                            Assert.AreEqual(cellSlatina, "55");
                            string cellRuse = excelWorksheet.Cells[i, rouseTargetColumn].Value.ToString();
                            Assert.AreEqual(cellRuse, "55");
                            Assert.IsTrue(excelManager.IsCellEmpty(excelWorksheet.Cells[i, quantityLiulinTargetColumn].Value));
                            Assert.IsTrue(excelManager.IsCellEmpty(excelWorksheet.Cells[i, quantitySlatinaTargetColumn].Value));
                            Assert.IsTrue(excelManager.IsCellEmpty(excelWorksheet.Cells[i, quantityRouseTargetColumn].Value));
                        }
                        else
                        {
                            Assert.IsTrue(excelManager.IsCellEmpty(excelWorksheet.Cells[i, liulinTargetColumn].Value));
                            Assert.IsTrue(excelManager.IsCellEmpty(excelWorksheet.Cells[i, slatinaTargetColumn].Value));
                            Assert.IsTrue(excelManager.IsCellEmpty(excelWorksheet.Cells[i, rouseTargetColumn].Value));
                            Assert.IsTrue(excelManager.IsCellEmpty(excelWorksheet.Cells[i, quantityLiulinTargetColumn].Value));
                            Assert.IsTrue(excelManager.IsCellEmpty(excelWorksheet.Cells[i, quantitySlatinaTargetColumn].Value));
                            Assert.IsTrue(excelManager.IsCellEmpty(excelWorksheet.Cells[i, quantityRouseTargetColumn].Value));
                        }
                    }
                }
            }

            this.RemoveFile(testFile);
        }