Exemplo n.º 1
0
        public void Cells(string script, string mustbe)
        {
            JS     engine = new JS(ReadCell);
            string result = engine.Execute(script);

            Assert.AreEqual(mustbe, result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Метод, получающий имя выходного файла на основании JS скрипта из XML конфига
        /// </summary>
        /// <param name="worksheet">Excel документ для чтения ячеек в JS скрипте</param>
        /// <param name="inputFile">Полный путь к исходному Exel файлу</param>
        /// <param name="simple">Необходимо ли вообще использовать JS</param>
        /// <param name="script">Содержимое JS скрипта в виде текста</param>
        /// <returns></returns>
        public string getOutputFilename(Worksheet worksheet, String inputFile, bool simple, string script = null)
        {
            if (simple)
            {
                return(Path.GetFileName(Path.ChangeExtension(inputFile, ".dbf")));
            }

            JS.DelegateReadExcel readCell = (x, y) =>
            {
                try
                {
                    return(worksheet.Cells[y, x].Value);
                }
                catch (Exception ex)
                {
                    Logger.warn($"Ошибка при чтении ячейки x={x},y={y}: {ex.Message}");
                    return(null);
                }
            };

            JS js = new JS(readCell, Logger.info);

            js.SetPath(inputFile);

            string outputFilename = js.Execute(script);

            if (!outputFilename.EndsWith(".dbf"))
            {
                outputFilename += ".dbf";
            }
            return(outputFilename);
        }
Exemplo n.º 3
0
        public void FileFunction(string script, string mustbe)
        {
            JS engine = new JS(null);

            engine.SetPath("C:\\Книги\\Этот Прекрасный Мир.doc");
            string result = engine.Execute(script);

            Assert.AreEqual(mustbe, result);
        }
Exemplo n.º 4
0
        public void Exceptions()
        {
            JS engine = new JS(null);

            ExceptionAssert.Throws <JS.JSException>(() => engine.Execute("dir(0)"));
            ExceptionAssert.Throws <ArgumentException>(() => engine.SetPath(null).Execute("dir(0)"));
            ExceptionAssert.Throws <ArgumentException>(() => engine.SetPath("Invalid Path?").Execute("dir(0)"));
            // ReSharper disable once ObjectCreationAsStatement
            ExceptionAssert.Throws <ArgumentNullException>(() => new PathHelper(null));
        }