public void TestDocx2JsonConversion()
        {
            var sut = new Docx2Json(jsonIoService, docxJsonService, docxFileService);

            var filePath      = Path.GetDirectoryName(FullDocxTestFilePath);
            var fileExtension = Path.GetExtension(FullDocxTestFilePath);
            var fileName      = Path.GetFileName(filePath).Replace(fileExtension, "");

            var tempDocxPath = Path.Join(filePath, fileName + DateTime.Now.ToString("yyyyMMddHHmmssffff") + fileExtension);

            File.Copy(FullDocxTestFilePath, tempDocxPath);

            var result = sut.ExtractStringsToJsonFile(tempDocxPath);

            Assert.AreEqual("Success", result.Messages.First());

            //Validate that the Json file was saved properly
            Assert.IsTrue(File.Exists(result.FullPath));
            var rawFileContents = File.ReadAllLines(result.FullPath);

            Assert.IsNotNull(rawFileContents);

            //Clean Up files that was created
            File.Delete(tempDocxPath);
            File.Delete(result.FullPath);
        }
예제 #2
0
        static void MergeJson2Docx(Options opts)
        {
            // opts.InputJsonPath = @"F:\TextTranslator\theotech-docx_translator-54e33cd4e397\theotech-docx_translator-54e33cd4e397\DocxJsonConverter.Tests\TestFiles\TestDocxFile.json";
            opts.Docx2ConvertPath = @"F:\TextTranslator\Final Packet for distribution1.docx";

            if (opts.Docx2ConvertPath != null)
            {
                Docx2Json docx2JsonConversion = new Docx2Json(new JsonIoService(), new DocxJsonService(), new DocxFileService());
                var       result = docx2JsonConversion.ExtractStringsToJsonFile(opts.Docx2ConvertPath);

                if (result.Messages.First() == "Success")
                {
                    Console.WriteLine(result.Messages.First());
                    Console.WriteLine("Exported File Name:");
                    Console.WriteLine(result.FullPath);
                }
                else
                {
                    Console.WriteLine("ERROR: " + result.Messages.First());
                }
            }
            else
            {
                Console.WriteLine("ERROR: Please enter a valid -i .docx file path");
            }
        }