public void ExecuteWithAllParameters()
        {
            var parameters = new ExtractParameters(null, "1", "text.doc");
            var conn       = new MSolrConnection();

            conn.postStream += new Moroco.MFunc <string, string, System.IO.Stream, System.Collections.Generic.IEnumerable <System.Collections.Generic.KeyValuePair <string, string> >, string>((url, type, stream, kvs) => {
                Assert.Equal("/update/extract", url);
                Assert.Equal("application/word-document", type);

                var p = new[] {
                    KV.Create("literal.id", parameters.Id),
                    KV.Create("resource.name", parameters.ResourceName),
                    KV.Create("literal.field1", "value1"),
                    KV.Create("literal.field2", "value2"),
                    KV.Create("stream.type", "application/word-document"),
                    KV.Create("commit", "true"),
                    KV.Create("uprefix", "pref"),
                    KV.Create("defaultField", "field1"),
                    KV.Create("extractOnly", "true"),
                    KV.Create("extractFormat", "text"),
                    KV.Create("capture", "html"),
                    KV.Create("captureAttr", "true"),
                    KV.Create("xpath", "body"),
                    KV.Create("lowernames", "true")
                };


                Assert.Equal(p, kvs); //ignore order should be added
                return("");
            });

            var cmd = new ExtractCommand(new ExtractParameters(null, "1", "text.doc")
            {
                AutoCommit        = true,
                Capture           = "html",
                CaptureAttributes = true,
                DefaultField      = "field1",
                ExtractOnly       = true,
                ExtractFormat     = ExtractFormat.Text,
                Fields            = new[] {
                    new ExtractField("field1", "value1"),
                    new ExtractField("field2", "value2")
                },
                LowerNames = true,
                XPath      = "body",
                Prefix     = "pref",
                StreamType = "application/word-document"
            });

            cmd.Execute(conn);
            Assert.Equal(1, conn.postStream.Calls);
        }
예제 #2
0
        public void ExecuteWithDuplicateIdField()
        {
            const string DuplicateId = "duplicateId";
            var          cmd         = new ExtractCommand(new ExtractParameters(null, DuplicateId, "text.doc")
            {
                Fields = new[] {
                    new ExtractField("id", DuplicateId),
                    new ExtractField("field2", "value2"),
                }
            });

            cmd.Execute(null);
        }
        public void ExecuteWithDuplicateIdField()
        {
            const string DuplicateId = "duplicateId";
            var          cmd         = new ExtractCommand(new ExtractParameters(null, DuplicateId, "text.doc")
            {
                Fields = new[] {
                    new ExtractField("id", DuplicateId),
                    new ExtractField("field2", "value2"),
                }
            });

            Assert.Throws <ArgumentException>(() => cmd.Execute(null));
        }
예제 #4
0
        public void ExecuteWithDuplicateIdField()
        {
            var mocks = new MockRepository();
            var conn  = mocks.StrictMock <ISolrConnection>();

            const string DuplicateId = "duplicateId";
            var          cmd         = new ExtractCommand(new ExtractParameters(null, DuplicateId, "text.doc")
            {
                Fields = new[] { new ExtractField("id", DuplicateId), new ExtractField("field2", "value2") }
            });

            cmd.Execute(conn);
        }
예제 #5
0
        public void ExecuteWithAllParameters()
        {
            var parameters = new ExtractParameters(null, "1", "text.doc");
            var conn       = new MSolrConnection();

            conn.postStream += (url, type, stream, kvs) => {
                Assert.AreEqual("/update/extract", url);
                Assert.AreEqual("application/word-document", type);

                var p = new[] {
                    KV.Create("literal.id", parameters.Id),
                    KV.Create("resource.name", parameters.ResourceName),
                    KV.Create("literal.field1", "value1"),
                    KV.Create("literal.field2", "value2"),
                    KV.Create("stream.type", "application/word-document"),
                    KV.Create("commit", "true"),
                    KV.Create("uprefix", "pref"),
                    KV.Create("defaultField", "field1"),
                    KV.Create("extractOnly", "true"),
                    KV.Create("extractFormat", "text"),
                    KV.Create("capture", "html"),
                    KV.Create("captureAttr", "true"),
                    KV.Create("xpath", "body"),
                    KV.Create("lowernames", "true")
                };

                CollectionAssert.AreEquivalent(p, kvs);
                return("");
            };

            var cmd = new ExtractCommand(new ExtractParameters(null, "1", "text.doc")
            {
                AutoCommit        = true,
                Capture           = "html",
                CaptureAttributes = true,
                DefaultField      = "field1",
                ExtractOnly       = true,
                ExtractFormat     = ExtractFormat.Text,
                Fields            = new[] {
                    new ExtractField("field1", "value1"),
                    new ExtractField("field2", "value2")
                },
                LowerNames = true,
                XPath      = "body",
                Prefix     = "pref",
                StreamType = "application/word-document"
            });

            cmd.Execute(conn);
            Assert.AreEqual(1, conn.postStream.Calls);
        }
예제 #6
0
        public void ExecuteWithAllParameters()
        {
            var mocks      = new MockRepository();
            var conn       = mocks.StrictMock <ISolrConnection>();
            var parameters = new ExtractParameters(null, "1", "text.doc");

            With.Mocks(mocks).Expecting(() =>
            {
                Expect.Call(conn.PostStream("/update/extract", "application/word-document", null, new List <KeyValuePair <string, string> > {
                    KV.Create("literal.id", parameters.Id),
                    KV.Create("resource.name", parameters.ResourceName),
                    KV.Create("literal.field1", "value1"),
                    KV.Create("literal.field2", "value2"),
                    KV.Create("stream.type", "application/word-document"),
                    KV.Create("commit", "true"),
                    KV.Create("uprefix", "pref"),
                    KV.Create("defaultField", "field1"),
                    KV.Create("extractOnly", "true"),
                    KV.Create("extractFormat", "text"),
                    KV.Create("capture", "html"),
                    KV.Create("captureAttr", "true"),
                    KV.Create("xpath", "body"),
                    KV.Create("lowernames", "true")
                }))
                .Repeat.Once()
                .Return("");
            })
            .Verify(() =>
            {
                var cmd = new ExtractCommand(new ExtractParameters(null, "1", "text.doc")
                {
                    AutoCommit        = true,
                    Capture           = "html",
                    CaptureAttributes = true,
                    DefaultField      = "field1",
                    ExtractOnly       = true,
                    ExtractFormat     = ExtractFormat.Text,
                    Fields            = new[] { new ExtractField("field1", "value1"), new ExtractField("field2", "value2") },
                    LowerNames        = true,
                    XPath             = "body",
                    Prefix            = "pref",
                    StreamType        = "application/word-document"
                });
                cmd.Execute(conn);
            });
        }
예제 #7
0
        public void Execute()
        {
            var parameters = new ExtractParameters(null, "1", "text.doc");
            var conn       = new MSolrConnection();

            conn.postStream += (url, b, stream, kvs) => {
                Assert.AreEqual("/update/extract", url);
                var p = new[] {
                    KV.Create("literal.id", parameters.Id),
                    KV.Create("resource.name", parameters.ResourceName),
                };
                CollectionAssert.AreEquivalent(p, kvs);
                return("");
            };
            var cmd = new ExtractCommand(parameters);

            cmd.Execute(conn);
            Assert.AreEqual(1, conn.postStream.Calls);
        }
예제 #8
0
        public void Execute()
        {
            var mocks      = new MockRepository();
            var conn       = mocks.StrictMock <ISolrConnection>();
            var parameters = new ExtractParameters(null, "1", "text.doc");

            With.Mocks(mocks).Expecting(() => {
                Expect.Call(conn.PostStream("/update/extract", null, null, new List <KeyValuePair <string, string> > {
                    KV("literal.id", parameters.Id),
                    KV("resource.name", parameters.ResourceName),
                }))
                .Repeat.Once()
                .Return("");
            })
            .Verify(() => {
                var cmd = new ExtractCommand(new ExtractParameters(null, "1", "text.doc"));
                cmd.Execute(conn);
            });
        }
        public void Execute()
        {
            var parameters = new ExtractParameters(null, "1", "text.doc");
            var conn       = new MSolrConnection();

            conn.postStream += new Moroco.MFunc <string, string, System.IO.Stream, System.Collections.Generic.IEnumerable <System.Collections.Generic.KeyValuePair <string, string> >, string>((url, b, stream, kvs) => {
                Assert.Equal("/update/extract", url);
                var p = new[] {
                    KV.Create("literal.id", parameters.Id),
                    KV.Create("resource.name", parameters.ResourceName),
                };
                Assert.Equal(p, kvs); //ignore order should be added
                return("");
            });
            var cmd = new ExtractCommand(parameters);

            cmd.Execute(conn);
            Assert.Equal(1, conn.postStream.Calls);
        }
예제 #10
0
        private static void StartOperation()
        {
            string        path     = ReadTargetFilePath();
            List <string> commands = ReadCommands();

            ExtractCommand extractCommand = new ExtractCommand(path);

            extractCommand.Execute();

            for (int i = 0; i < commands.Count; i++)
            {
                GetCommandToExecute(commands[i], out ICommand commandToExecute, extractCommand);
                if (commandToExecute == null)
                {
                    Console.WriteLine($"Ann error has occured! {commands[i]} couldn't be created");
                    continue;
                }

                Console.WriteLine(commandToExecute.Execute());
            }
        }