public void AtomicUpdateSetEmptyArray()
        {
            var conn = new Mocks.MSolrConnection();

            conn.postStream += new MFunc <string, string, Stream, IEnumerable <KeyValuePair <string, string> >, string>((url, contentType, content, param) => {
                string text = new StreamReader(content, Encoding.UTF8).ReadToEnd();
                Assert.Equal("/update", url);
                Assert.Equal("[{\"id\":\"0\",\"animal\":{\"set\":[]}}]", text);
                Console.WriteLine(text);
                return(null);
            });
            var updateSpecs = new AtomicUpdateSpec[] { new AtomicUpdateSpec("animal", AtomicUpdateType.Set, new string[] {}) };
            var cmd         = new AtomicUpdateCommand("id", "0", updateSpecs, null);

            cmd.Execute(conn);
            Assert.Equal(1, conn.postStream.Calls);
        }
Exemplo n.º 2
0
        public void AtomicUpdateAdd()
        {
            var conn = new Mocks.MSolrConnection();

            conn.postStream += new MFunc <string, string, Stream, IEnumerable <KeyValuePair <string, string> >, string>((url, contentType, content, param) => {
                string text = new StreamReader(content, Encoding.UTF8).ReadToEnd();
                Assert.Equal("/update", url);
                Assert.Equal("[{\"id\":\"0\",\"food\":{\"add\":\"nuts\"}}]", text);
                testOutputHelper.WriteLine(text);
                return(null);
            });
            var updateSpecs = new AtomicUpdateSpec[] { new AtomicUpdateSpec("food", AtomicUpdateType.Add, "nuts") };
            var cmd         = new AtomicUpdateCommand("id", "0", updateSpecs, null);

            cmd.Execute(conn);
            Assert.Equal(1, conn.postStream.Calls);
        }
        public void AtomicUpdateCommandNameInvariantCulture()
        {
            var conn = new Mocks.MSolrConnection();

            conn.postStream += new MFunc <string, string, Stream, IEnumerable <KeyValuePair <string, string> >, string>((url, contentType, content, param) => {
                string text = new StreamReader(content, Encoding.UTF8).ReadToEnd();
                Assert.Equal("/update", url);
                Assert.Equal("[{\"id\":\"0\",\"count\":{\"inc\":1}}]", text);
                Console.WriteLine(text);
                return(null);
            });
            var updateSpecs = new AtomicUpdateSpec[] { new AtomicUpdateSpec("count", AtomicUpdateType.Inc, 1) };
            var cmd         = new AtomicUpdateCommand("id", "0", updateSpecs, null);

            cmd.Execute(conn);
            Assert.Equal(1, conn.postStream.Calls);
        }
        public void AtomicUpdateRemoveRegexArray()
        {
            var conn = new Mocks.MSolrConnection();

            conn.postStream += new MFunc <string, string, Stream, IEnumerable <KeyValuePair <string, string> >, string>((url, contentType, content, param) => {
                string text = new StreamReader(content, Encoding.UTF8).ReadToEnd();
                Assert.Equal("/update", url);
                Assert.Equal("[{\"id\":\"0\",\"food\":{\"removeregex\":[\"nu.*\",\"seeds\",\"berr.+\"]}}]", text);
                Console.WriteLine(text);
                return(null);
            });
            var updateSpecs = new AtomicUpdateSpec[] { new AtomicUpdateSpec("food", AtomicUpdateType.RemoveRegex, new string[] { "nu.*", "seeds", "berr.+" }) };
            var cmd         = new AtomicUpdateCommand("id", "0", updateSpecs, null);

            cmd.Execute(conn);
            Assert.Equal(1, conn.postStream.Calls);
        }
Exemplo n.º 5
0
        public void AtomicUpdateWithParameter()
        {
            var conn = new Mocks.MSolrConnection();

            conn.postStream += new MFunc <string, string, Stream, IEnumerable <KeyValuePair <string, string> >, string>((url, contentType, content, param) => {
                string text = new StreamReader(content, Encoding.UTF8).ReadToEnd();
                Assert.Equal("/update", url);
                Assert.Equal("commitwithin", ((KeyValuePair <string, string>[])param)[0].Key);
                Assert.Equal("4343", ((KeyValuePair <string, string>[])param)[0].Value);
                Assert.Equal("[{\"id\":\"0\",\"count\":{\"inc\":3}}]", text);
                testOutputHelper.WriteLine(text);
                return(null);
            });
            var parameters = new AtomicUpdateParameters {
                CommitWithin = 4343
            };
            var updateSpecs = new AtomicUpdateSpec[] { new AtomicUpdateSpec("count", AtomicUpdateType.Inc, 3) };
            var cmd         = new AtomicUpdateCommand("id", "0", updateSpecs, parameters);

            cmd.Execute(conn);
            Assert.Equal(1, conn.postStream.Calls);
        }
Exemplo n.º 6
0
        public void AtomicUpdateSerialization()
        {
            var conn = new Mocks.MSolrConnection();

            conn.postStream += new MFunc <string, string, Stream, IEnumerable <KeyValuePair <string, string> >, string>((url, contentType, content, param) => {
                string text = new StreamReader(content, Encoding.UTF8).ReadToEnd();
                Assert.Equal("/update", url);
                Assert.Equal("[{"
                             + "\"id\":\"0\","
                             + "\"quote\":{\"set\":\"\\\"quoted\\\"\"},"
                             + "\"backslashInText\":{\"set\":\"y\\\\n\"},"
                             + "\"newLineInText\":{\"set\":\"line1\\nline2\"}"
                             + "}]",
                             text);
                testOutputHelper.WriteLine(text);
                return(null);
            });

            /* This document is equivalent to:
             * {
             *   id = 0;
             *   quote = "quoted";
             *   backslashInText = y\n;
             *   newLineInText = line1
             *   line2;
             * }
             */
            var updateSpecs = new AtomicUpdateSpec[] {
                new AtomicUpdateSpec("quote", AtomicUpdateType.Set, "\"quoted\""),
                new AtomicUpdateSpec("backslashInText", AtomicUpdateType.Set, "y\\n"),
                new AtomicUpdateSpec("newLineInText", AtomicUpdateType.Set, "line1\nline2")
            };
            var cmd = new AtomicUpdateCommand("id", "0", updateSpecs, null);

            cmd.Execute(conn);
            Assert.Equal(1, conn.postStream.Calls);
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        public Task <ResponseHeader> AtomicUpdateAsync(string uniqueKey, string id, IEnumerable <AtomicUpdateSpec> updateSpecs, AtomicUpdateParameters parameters)
        {
            var atomicUpdate = new AtomicUpdateCommand(uniqueKey, id, updateSpecs, parameters);

            return(SendAndParseHeaderAsync(atomicUpdate));
        }