public void Builders_OptBuilder_NoText()
        {
            builder.PathPrefix  = String.Empty;
            builder.TextBuilder = null;
            List <Document>    documents = builder.Build(OptRecords);
            DocumentCollection docs      = new DocumentCollection(documents);

            Assert.AreEqual(10, docs.Count);
            Assert.AreEqual(25, docs.ImageCount);
            Assert.AreEqual(0, docs.TextCount);
            Assert.AreEqual(0, docs.NativeCount);
            Assert.AreEqual(0, docs.ParentCount);
            Assert.AreEqual(0, docs.ChildCount);
            Assert.AreEqual(10, docs.StandAloneCount);
        }
Exemple #2
0
        /// <summary>
        /// Parses data from a file and builds the data 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);
        }
        public DocumentCollection GetDocs()
        {
            var datLines = new List <string>(new string[] {
                "þDOCIDþþBEGATTþþVOLUMEþþDOCTYPEþþNATIVEþ",
                "þDOC000001þþDOC000001þþVOL001þþEMAILþþX:\\VOL001\\NATIVE\\0001\\DOC000001.XLSXþ",
                "þDOC000002þþDOC000001þþVOL001þþPDFþþþ",
                null, null
            });

            var optLines = new List <string[]> {
                new string[] { "DOC000001", "VOL001", "X:\\VOL001\\IMAGES\\0001\\DOC000001.jpg", "Y", "", "", "1" },
                new string[] { "DOC000002", "VOL001", "X:\\VOL001\\IMAGES\\0001\\DOC000002.tif", "Y", "", "", "2" },
                new string[] { "DOC000003", "VOL001", "X:\\VOL001\\IMAGES\\0001\\DOC000003.tif", "", "", "", "" }
            };

            var mockReader = new Mock <TextReader>();
            int calls      = 0;

            mockReader
            .Setup(r => r.ReadLine())
            .Returns(() => datLines[calls])
            .Callback(() => calls++);
            FileInfo infile        = new FileInfo(@"X:\VOL001\infile.dat");
            bool     hasHeader     = true;
            string   keyColName    = "DOCID";
            string   parentColName = "BEGATT";
            string   childColName  = String.Empty;
            string   childColDelim = ";";
            RepresentativeBuilder        repSetting = new RepresentativeBuilder("NATIVE", Representative.FileType.Native);
            List <RepresentativeBuilder> reps       = new List <RepresentativeBuilder>();

            reps.Add(repSetting);
            var             builder = new DatBuilder();
            IParser         parser  = new DatParser(Delimiters.CONCORDANCE);
            List <string[]> records = parser.Parse(mockReader.Object);

            builder.HasHeader              = hasHeader;
            builder.KeyColumnName          = keyColName;
            builder.ParentColumnName       = parentColName;
            builder.ChildColumnName        = childColName;
            builder.ChildSeparator         = childColDelim;
            builder.RepresentativeBuilders = reps;
            builder.ParentColumnName       = infile.Directory.FullName;
            List <Document> documents  = builder.Build(records);
            var             docs       = new DocumentCollection(documents);
            var             optBuilder = new OptBuilder();

            optBuilder.PathPrefix  = String.Empty;
            optBuilder.TextBuilder = null;
            List <Document> optDocs = optBuilder.Build(optLines);

            docs.AddRange(optDocs);
            docs[1].SetParent(docs[0]);
            return(docs);
        }
        public void Exporters_DatExporter_FromLfpTest()
        {
            // Arrange
            var mockReader = new Mock <TextReader>();
            var mockWriter = new Mock <TextWriter>();
            int calls      = 0;

            mockReader
            .Setup(r => r.ReadLine())
            .Returns(() => optLines[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.opt");
            TextBuilder rep    = new TextBuilder(
                TextBuilder.TextLevel.None,
                TextBuilder.TextLocation.None,
                null, null);
            var     builder = new OptBuilder();
            IParser parser  = new DatParser(Delimiters.COMMA_DELIMITED);

            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" };
            var      exporter = DatExporter.Builder
                                .Start(mockWriter.Object, fields)
                                .SetDelimiters(Delimiters.COMMA_QUOTE)
                                .Build();

            exporter.Export(docs);

            // assert
            Assert.AreEqual("\"DocID\",\"Page Count\"", output[0]);
            Assert.AreEqual("\"000000001\",\"1\"", output[1]);
            Assert.AreEqual("\"000000002\",\"2\"", output[2]);
        }
Exemple #5
0
        public void Exporters_LfpExporter_FromOptTest()
        {
            // Arrange
            var mockReader = new Mock <TextReader>();
            var mockWriter = new Mock <TextWriter>();
            int calls      = 0;

            mockReader
            .Setup(r => r.ReadLine())
            .Returns(() => optLines[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.opt");
            string      vol    = "TEST001";
            TextBuilder rep    = new TextBuilder(
                TextBuilder.TextLevel.None,
                TextBuilder.TextLocation.None,
                null, null);
            var     builder = new OptBuilder();
            IParser parser  = new DatParser(Delimiters.COMMA_DELIMITED);

            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,0,@TEST001;X:\\VOL001\\IMAGES\\0001;000000001.jpg;4,0", output[0]);
            Assert.AreEqual("IM,000000002,D,0,@TEST001;X:\\VOL001\\IMAGES\\0001;000000002.tif;2,0", output[1]);
            Assert.AreEqual("IM,000000003,,0,@TEST001;X:\\VOL001\\IMAGES\\0001;000000003.tif;2,0", output[2]);
        }