コード例 #1
0
        /// <summary>
        /// Parses data from a file and builds it into a collection of <see cref="Document"/> objects.
        /// </summary>
        /// <param name="file">The file to import.</param>
        /// <param name="encoding">The encoding of the file.</param>
        /// <returns>Returns a <see cref="DocumentCollection"/>.</returns>
        public DocumentCollection Import(FileInfo file, Encoding encoding)
        {
            List <string[]>    records      = parser.Parse(file, encoding);
            List <Document>    documentList = builder.Build(records);
            DocumentCollection documents    = new DocumentCollection(documentList);

            return(documents);
        }
コード例 #2
0
        public void Exporters_DatExporter_FromOptTest()
        {
            // Arrange
            var mockReader = new Mock <TextReader>();
            var mockWriter = new Mock <TextWriter>();
            int calls      = 0;

            mockReader
            .Setup(r => r.ReadLine())
            .Returns(() => lfpLines[calls])
            .Callback(() => calls++);
            List <string> output = new List <string>();

            mockWriter
            .Setup(r => r.WriteLine(It.IsAny <string>()))
            .Callback((string s) => output.Add(s));
            FileInfo    infile = new FileInfo(@"X:\VOL001\infile.lfp");
            TextBuilder rep    = new TextBuilder(
                TextBuilder.TextLevel.None,
                TextBuilder.TextLocation.None,
                null, null);
            var     builder = new LfpBuilder();
            IParser parser  = new LfpParser();

            builder.PathPrefix  = String.Empty;
            builder.TextBuilder = rep;

            // act
            List <string[]>    records   = parser.Parse(mockReader.Object);
            List <Document>    documents = builder.Build(records);
            DocumentCollection docs      = new DocumentCollection(documents);

            string[] fields   = new string[] { "DocID", "Page Count", "Volume Name" };
            var      exporter = DatExporter.Builder
                                .Start(mockWriter.Object, fields)
                                .SetDelimiters(Delimiters.COMMA_DELIMITED)
                                .Build();

            exporter.Export(docs);

            // assert
            Assert.AreEqual("DocID,Page Count,Volume Name", output[0]);
            Assert.AreEqual("000000001,3,001", output[1]);
        }
コード例 #3
0
        public void Exporters_LfpExporter_FromLfpMultiTest()
        {
            // Arrange
            var mockReader = new Mock <TextReader>();
            var mockWriter = new Mock <TextWriter>();
            int calls      = 0;

            mockReader
            .Setup(r => r.ReadLine())
            .Returns(() => lfpMultiLines[calls])
            .Callback(() => calls++);
            List <string> output = new List <string>();

            mockWriter
            .Setup(r => r.WriteLine(It.IsAny <string>()))
            .Callback((string s) => output.Add(s));
            FileInfo    infile = new FileInfo(@"X:\VOL001\infile.lfp");
            string      vol    = "TEST001";
            TextBuilder rep    = new TextBuilder(
                TextBuilder.TextLevel.None,
                TextBuilder.TextLocation.None,
                null, null);
            var     builder = new LfpBuilder();
            IParser parser  = new LfpParser();

            builder.PathPrefix  = String.Empty;
            builder.TextBuilder = rep;

            // act
            List <string[]>    records   = parser.Parse(mockReader.Object);
            List <Document>    documents = builder.Build(records);
            DocumentCollection docs      = new DocumentCollection(documents);
            var exporter = LfpExporter.Builder
                           .Start(mockWriter.Object)
                           .SetVolumeName(vol)
                           .Build();

            exporter.Export(docs);

            // assert
            Assert.AreEqual("IM,000000001,D,1,@TEST001;IMG_0001;000000001.pdf;7,0", output[0]);
            Assert.AreEqual("IM,000000002,,2,@TEST001;IMG_0001;000000001.pdf;7,0", output[1]);
            Assert.AreEqual("IM,000000003,,3,@TEST001;IMG_0001;000000001.pdf;7,0", output[2]);
        }