Beispiel #1
0
        public void DeleteByMultipleId()
        {
            var mocks             = new MockRepository();
            var connection        = mocks.StrictMock <ISolrConnection>();
            var headerParser      = mocks.StrictMock <ISolrHeaderResponseParser>();
            var executer          = mocks.StrictMock <ISolrQueryExecuter <TestDocumentWithUniqueKey> >();
            var docSerializer     = mocks.StrictMock <ISolrDocumentSerializer <TestDocumentWithUniqueKey> >();
            var validationManager = mocks.StrictMock <IMappingValidator>();

            With.Mocks(mocks)
            .Expecting(() => {
                Expect.On(connection)
                .Call(connection.Post("/update", "<delete><id>0</id><id>0</id></delete>"))
                .Repeat.Once()
                .Return(EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml"));
                Expect.On(headerParser)
                .Call(headerParser.Parse(null))
                .IgnoreArguments()
                .Return(new ResponseHeader());
            })
            .Verify(() => {
                var basic = new SolrBasicServer <TestDocumentWithUniqueKey>(connection, executer, docSerializer, null, headerParser, null, null, null);
                var ops   = new SolrServer <TestDocumentWithUniqueKey>(basic, new AttributesMappingManager(), validationManager);
                ops.Delete(new[] {
                    new TestDocumentWithUniqueKey(),
                    new TestDocumentWithUniqueKey(),
                });
            });
        }
Beispiel #2
0
        public void DeleteDocumentWithUniqueKey()
        {
            var mocks             = new MockRepository();
            var basicServer       = mocks.StrictMock <ISolrBasicOperations <TestDocumentWithUniqueKey> >();
            var mapper            = mocks.StrictMock <IReadOnlyMappingManager>();
            var validationManager = mocks.StrictMock <IMappingValidator>();

            With.Mocks(mocks)
            .Expecting(() => {
                Expect.On(basicServer)
                .Call(basicServer.Delete(new[] { "0" }, null))
                .IgnoreArguments()
                .Return(new ResponseHeader());
                Expect.On(mapper)
                .Call(mapper.GetUniqueKey(typeof(TestDocumentWithUniqueKey)))
                .Return(new SolrFieldModel {
                    Property  = typeof(TestDocumentWithUniqueKey).GetProperty("id"),
                    FieldName = "id"
                });
            })
            .Verify(delegate {
                var ops = new SolrServer <TestDocumentWithUniqueKey>(basicServer, mapper, validationManager);
                ops.Delete(new TestDocumentWithUniqueKey());
            });
        }
Beispiel #3
0
        public void AtomicUpdate()
        {
            var xml        = EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml");
            var connection = new MSolrConnection();

            connection.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\",\"animal\":{\"set\":\"squirrel\"},\"food\":{\"add\":[\"nuts\",\"seeds\"]},\"count\":{\"inc\":3},\"colour\":{\"remove\":\"pink\"},\"habitat\":{\"removeregex\":[\"tree.*\",\"river.+\"]}}]", text);
                return(xml);
            });
            var headerParser = new MSolrHeaderResponseParser();

            headerParser.parse += _ => null;
            var basic      = new SolrBasicServer <TestDocumentWithUniqueKey>(connection, null, null, null, headerParser, null, null, null);
            var ops        = new SolrServer <TestDocumentWithUniqueKey>(basic, new AttributesMappingManager(), null);
            var parameters = new AtomicUpdateParameters {
                CommitWithin = 4343
            };
            var updateSpecs = new AtomicUpdateSpec[] { new AtomicUpdateSpec("animal", AtomicUpdateType.Set, "squirrel"),
                                                       new AtomicUpdateSpec("food", AtomicUpdateType.Add, new string[] { "nuts", "seeds" }), new AtomicUpdateSpec("count", AtomicUpdateType.Inc, 3),
                                                       new AtomicUpdateSpec("colour", AtomicUpdateType.Remove, "pink"), new AtomicUpdateSpec("habitat", AtomicUpdateType.RemoveRegex, new string[] { "tree.*", "river.+" }) };

            ops.AtomicUpdate(new TestDocumentWithUniqueKey(), updateSpecs, parameters);
            Assert.Equal(1, connection.postStream.Calls);
        }
        static SolrServerInstance()
        {
            var connection = new SolrConnection("http://192.168.101.3:8986/solr");

            _newsServer = new SolrServer(connection);
            _newsServer.AddHandler <SolrAnalysisHandler>();
            _newsServer.AddHandler <SolrSelectHandler>();
            _newsServer.AddHandler <SolrUpdateHandler>();
            _newsServer.AddHandler <SolrMltHandler>();
            _newsServer.AddHandler <SolrParticipleHandler>();


            connection      = new SolrConnection("http://192.168.101.3:9000/solr/tone");
            _toneSolrServer = new SolrServer(connection);
            _toneSolrServer.AddHandler <SolrSelectHandler>();
            _toneSolrServer.AddHandler <SolrUpdateHandler>();

            connection   = new SolrConnection("http://192.168.101.2:8986/solr");
            _newsServer2 = new SolrServer(connection);
            _newsServer2.AddHandler <SolrAnalysisHandler>();
            _newsServer2.AddHandler <SolrSelectHandler>();
            _newsServer2.AddHandler <SolrUpdateHandler>();
            _newsServer2.AddHandler <SolrMltHandler>();

            connection       = new SolrConnection("http://192.168.101.2:9000/solr/tone");
            _toneSolrServer2 = new SolrServer(connection);
            _toneSolrServer2.AddHandler <SolrSelectHandler>();
            _toneSolrServer2.AddHandler <SolrUpdateHandler>();
        }
Beispiel #5
0
        public void NullableDateTime()
        {
            var    mocks             = new MockRepository();
            var    connection        = mocks.StrictMock <ISolrConnection>();
            var    responseParser    = mocks.DynamicMock <ISolrHeaderResponseParser>();
            var    resultParser      = mocks.StrictMock <ISolrQueryResultParser <TestDocWithNullable> >();
            var    queryExecuter     = new SolrQueryExecuter <TestDocWithNullable>(resultParser, connection, null, null);
            var    mapper            = new AttributesMappingManager();
            var    docSerializer     = new SolrDocumentSerializer <TestDocWithNullable>(mapper, new DefaultFieldSerializer());
            var    validationManager = mocks.StrictMock <IMappingValidator>();
            var    basicSolr         = new SolrBasicServer <TestDocWithNullable>(connection, queryExecuter, docSerializer, null, responseParser, null, null, null);
            var    solr = new SolrServer <TestDocWithNullable>(basicSolr, mapper, validationManager);
            string xml  = null;

            With.Mocks(mocks)
            .Expecting(() => {
                Expect.On(connection)
                .Call(connection.Post(null, null))
                .IgnoreArguments()
                .Do(new Writer(delegate(string u, string s) {
                    Console.WriteLine(s);
                    xml = s;
                    return(EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml"));
                }));
            })
            .Verify(() => {
                solr.Add(new TestDocWithNullable());
                Assert.AreEqual("<add><doc /></add>", xml);
            });
        }
Beispiel #6
0
 public void Ping()
 {
     var mocks = new MockRepository();
     var basicServer = mocks.StrictMock<ISolrBasicOperations<TestDocument>>();
     With.Mocks(mocks)
         .Expecting(() => Expect.Call(basicServer.Ping()).Return(new ResponseHeader()))
         .Verify(() => {
             var s = new SolrServer<TestDocument>(basicServer, null, null);
             s.Ping();
         });
 }
Beispiel #7
0
 public void Ping()
 {
     var mocks = new MockRepository();
     var basicServer = mocks.CreateMock<ISolrBasicOperations<TestDocument>>();
     var mapper = mocks.CreateMock<IReadOnlyMappingManager>();
     With.Mocks(mocks)
         .Expecting(basicServer.Ping)
         .Verify(() => {
             var s = new SolrServer<TestDocument>(basicServer, mapper);
             s.Ping();
         });
 }
Beispiel #8
0
        public void Ping()
        {
            var basicServer = new MSolrBasicOperations <TestDocument> {
                ping = () => new ResponseHeader {
                    QTime = 2
                },
            };
            var s = new SolrServer <TestDocument>(basicServer, null, null);
            var r = s.Ping();

            Assert.Equal(2, r.QTime);
        }
Beispiel #9
0
        public void Rollback()
        {
            var mocks       = new MockRepository();
            var basicServer = mocks.StrictMock <ISolrBasicOperations <TestDocument> >();

            With.Mocks(mocks)
            .Expecting(() => Expect.Call(basicServer.Rollback()).Return(new ResponseHeader()))
            .Verify(() => {
                var s = new SolrServer <TestDocument>(basicServer, null, null);
                s.Rollback();
            });
        }
Beispiel #10
0
        public void GetSchema()
        {
            var basicServer = new MSolrBasicOperations <TestDocument>();

            basicServer.getSchema += () => new SolrSchema {
                UniqueKey = "bla"
            };
            var s = new SolrServer <TestDocument>(basicServer, null, null);
            var r = s.GetSchema();

            Assert.Equal("bla", r.UniqueKey);
        }
Beispiel #11
0
        public void Commit()
        {
            var basicServer = new MSolrBasicOperations <TestDocument> {
                commit = _ => new ResponseHeader {
                    QTime = 2
                }
            };
            var s = new SolrServer <TestDocument>(basicServer, null, null);
            var r = s.Commit();

            Assert.Equal(2, r.QTime);
        }
Beispiel #12
0
 public void DeleteDocumentWithoutUniqueKey_ShouldThrow()
 {
     Assert.Throws <SolrNetException>(() => {
         var mapper           = new MReadOnlyMappingManager();
         mapper.getUniqueKey += t => {
             Assert.AreEqual(typeof(TestDocumentWithoutUniqueKey), t);
             return(null);
         };
         var ops = new SolrServer <TestDocumentWithoutUniqueKey>(null, mapper, null);
         ops.Delete(new TestDocumentWithoutUniqueKey());
         Assert.AreEqual(1, mapper.getUniqueKey.Calls);
     });
 }
Beispiel #13
0
        public void Rollback()
        {
            var basicServer = new MSolrBasicOperations <TestDocument>();

            basicServer.rollback += () => new ResponseHeader {
                QTime = 2
            };
            var s = new SolrServer <TestDocument>(basicServer, null, null);
            var r = s.Rollback();

            Assert.Equal(2, r.QTime);
            Assert.Equal(1, basicServer.rollback.Calls);
        }
Beispiel #14
0
        public void Add_enumerable_calls_operations_with_null_add_parameters()
        {
            var basicServer = new MSolrBasicOperations <TestDocument>();

            basicServer.addWithBoost += (docs, p) => {
                Assert.Null(p);
                return(null);
            };
            var s = new SolrServer <TestDocument>(basicServer, null, null);
            var t = new[] { new TestDocument(), new TestDocument() };

            s.AddRange(t);
            basicServer.addWithBoost.Verify();
        }
Beispiel #15
0
        public void Validate()
        {
            var basicServer = new MSolrBasicOperations <TestDocument>();

            basicServer.getSchema += () => new SolrSchema();
            var validator = new MMappingValidator();

            validator.enumerate &= x => x.Return(new List <ValidationResult>());
            var s = new SolrServer <TestDocument>(basicServer, null, validator);

            s.EnumerateValidationResults().ToList();
            Assert.Equal(1, basicServer.getSchema.Calls);
            Assert.Equal(1, validator.enumerate.Calls);
        }
Beispiel #16
0
 public void GetSchema()
 {
     var mocks = new MockRepository();
     var basicServer = mocks.StrictMock<ISolrBasicOperations<TestDocument>>();
     var mapper = mocks.StrictMock<IReadOnlyMappingManager>();
     var validationManager = mocks.StrictMock<IMappingValidator>();
     With.Mocks(mocks)
         .Expecting(() => Expect.Call(basicServer.GetSchema())
             .Repeat.Once()
             .Return(new SolrSchema()))
         .Verify(() => {
             var s = new SolrServer<TestDocument>(basicServer, mapper, validationManager);
             s.GetSchema();
         });
 }
Beispiel #17
0
        public void Add_enumerable_with_add_parameters_calls_operations_with_same_add_parameters()
        {
            var parameters = new AddParameters {
                CommitWithin = 4343
            };
            var basicServer = new MSolrBasicOperations <TestDocument>();

            basicServer.addWithBoost += (docs, p) => {
                Assert.Same(parameters, p);
                return(null);
            };
            var s = new SolrServer <TestDocument>(basicServer, null, null);
            var t = new[] { new TestDocument(), new TestDocument() };

            s.AddRange(t, parameters);
        }
Beispiel #18
0
        public void Add_single_doc_calls_operations_with_null_add_parameters() {
            var basicServer = new MSolrBasicOperations<TestDocument>();
            basicServer.addWithBoost += (docs, param) => {
                Assert.IsNull(param);
                return null;
            };
            basicServer.addWithBoost &= x => x.Expect(1);

            var mapper = new MReadOnlyMappingManager();
            var validationManager = new MMappingValidator();

            var s = new SolrServer<TestDocument>(basicServer, mapper, validationManager);
            var t = new TestDocument();
            s.Add(t);
            basicServer.addWithBoost.Verify();
        }
        public ISolrOperations <T> GetServer(ISolrConnection connection)
        {
            var basicServer = GetBasicServer(connection);

            MappingValidator = new MappingValidator(MappingManager, new IValidationRule[]
            {
                new MappedPropertiesIsInSolrSchemaRule(),
                new RequiredFieldsAreMappedRule(),
                new UniqueKeyMatchesMappingRule(),
                new MultivaluedMappedToCollectionRule()
            });

            ISolrOperations <T> server = new SolrServer <T>(basicServer, MappingManager, MappingValidator);

            return(server);
        }
Beispiel #20
0
        public void AddWithBoost_single_doc_calls_operations_with_null_add_parameters() {
            var basicServer = new MSolrBasicOperations<TestDocument>();
            basicServer.addWithBoost += (a,b) => {
                Assert.IsNull(b);
                return null;
            };

            var mapper = new MReadOnlyMappingManager();
            var validationManager = new MMappingValidator();

            var s = new SolrServer<TestDocument>(basicServer, mapper, validationManager);
            var t = new TestDocument();
            s.AddWithBoost(t, 2.1);

            Assert.AreEqual(1, basicServer.addWithBoost.Calls);
        }
Beispiel #21
0
        public void DeleteDocumentWithoutUniqueKey_ShouldThrow()
        {
            var mocks             = new MockRepository();
            var basicServer       = mocks.StrictMock <ISolrBasicOperations <TestDocumentWithoutUniqueKey> >();
            var mapper            = mocks.StrictMock <IReadOnlyMappingManager>();
            var validationManager = mocks.StrictMock <IMappingValidator>();

            With.Mocks(mocks)
            .Expecting(() => {
                Expect.On(mapper)
                .Call(mapper.GetUniqueKey(typeof(TestDocumentWithoutUniqueKey)))
                .Return(null);
            }).Verify(() => {
                var ops = new SolrServer <TestDocumentWithoutUniqueKey>(basicServer, mapper, validationManager);
                ops.Delete(new TestDocumentWithoutUniqueKey());
            });
        }
Beispiel #22
0
        public void GetSchema()
        {
            var mocks             = new MockRepository();
            var basicServer       = mocks.StrictMock <ISolrBasicOperations <TestDocument> >();
            var mapper            = mocks.StrictMock <IReadOnlyMappingManager>();
            var validationManager = mocks.StrictMock <IMappingValidator>();

            With.Mocks(mocks)
            .Expecting(() => Expect.Call(basicServer.GetSchema())
                       .Repeat.Once()
                       .Return(new SolrSchema()))
            .Verify(() =>
            {
                var s = new SolrServer <TestDocument>(basicServer, mapper, validationManager);
                s.GetSchema();
            });
        }
Beispiel #23
0
        public static ISolrOperations <T> GetServer <T>(ISolrConnection connection)
        {
            IReadOnlyMappingManager mapper = new MemoizingMappingManager(new AttributesMappingManager());

            IReadOnlyMappingManager mappingManager   = mapper;
            IMappingValidator       mappingValidator = new MappingValidator(mapper, new IValidationRule[] {
                new MappedPropertiesIsInSolrSchemaRule(),
                new RequiredFieldsAreMappedRule(),
                new UniqueKeyMatchesMappingRule(),
                new MultivaluedMappedToCollectionRule()
            });

            var basicServer            = GetBasicServer <T>(connection);
            ISolrOperations <T> server = new SolrServer <T>(basicServer, mappingManager, mappingValidator);

            return(server);
        }
Beispiel #24
0
        public void Add_single_doc_with_add_parameters_calls_operations_with_same_add_parameters() {
            var parameters = new AddParameters { CommitWithin = 4343 };
            var basicServer = new MSolrBasicOperations<TestDocument>();
            basicServer.addWithBoost += (_, p) => {
                Assert.AreEqual(parameters, p);
                return null;
            };

            var mapper = new MReadOnlyMappingManager();
            var validationManager = new MMappingValidator();

            var s = new SolrServer<TestDocument>(basicServer, mapper, validationManager);
            var t = new TestDocument();
            s.Add(t, parameters);

            Assert.AreEqual(1, basicServer.addWithBoost.Calls);
        }
Beispiel #25
0
        public void DeleteDocumentWithUniqueKey()
        {
            var mapper = new MReadOnlyMappingManager();

            mapper.getUniqueKey += t => {
                Assert.AreEqual(typeof(TestDocumentWithUniqueKey), t);
                return(new SolrFieldModel(
                           property: typeof(TestDocumentWithUniqueKey).GetProperty("id"),
                           fieldName: "id"));
            };
            var basicServer = new MSolrBasicOperations <TestDocumentWithUniqueKey>();

            basicServer.delete &= x => x.Stub();
            var ops = new SolrServer <TestDocumentWithUniqueKey>(basicServer, mapper, null);

            ops.Delete(new TestDocumentWithUniqueKey());
            Assert.AreEqual(1, mapper.getUniqueKey.Calls);
        }
Beispiel #26
0
 public void AddWithBoost_single_doc_calls_operations_with_null_add_parameters()
 {
     var mocks = new MockRepository();
     var basicServer = mocks.StrictMock<ISolrBasicOperations<TestDocument>>();
     var mapper = mocks.StrictMock<IReadOnlyMappingManager>();
     var validationManager = mocks.StrictMock<IMappingValidator>();
     With.Mocks(mocks)
         .Expecting(() =>
             Expect.Call(
                 basicServer.AddWithBoost(Arg<IEnumerable<KeyValuePair<TestDocument, double?>>>.Is.Anything, Arg<AddParameters>.Is.Null))
             .Repeat.Once())
         .Verify(() =>
         {
             var s = new SolrServer<TestDocument>(basicServer, mapper, validationManager);
             var t = new TestDocument();
             s.AddWithBoost(t, 2.1);
         });
 }
Beispiel #27
0
        public void AddWithBoost_single_doc_calls_operations_with_null_add_parameters()
        {
            var mocks             = new MockRepository();
            var basicServer       = mocks.StrictMock <ISolrBasicOperations <TestDocument> >();
            var mapper            = mocks.StrictMock <IReadOnlyMappingManager>();
            var validationManager = mocks.StrictMock <IMappingValidator>();

            With.Mocks(mocks)
            .Expecting(() =>
                       Expect.Call(
                           basicServer.AddWithBoost(Arg <IEnumerable <KeyValuePair <TestDocument, double?> > > .Is.Anything, Arg <AddParameters> .Is.Null))
                       .Repeat.Once())
            .Verify(() =>
            {
                var s = new SolrServer <TestDocument>(basicServer, mapper, validationManager);
                var t = new TestDocument();
                s.AddWithBoost(t, 2.1);
            });
        }
        public void AddWithBoost_single_doc_with_add_parameters_calls_operations_with_same_add_parameters()
        {
            var basicServer = new MSolrBasicOperations<TestDocument>();
            var parameters = new AddParameters { CommitWithin = 4343 };
            var t = new TestDocument();
            basicServer.addWithBoost += (docs, p) => {
                Assert.AreSame(parameters, p);
                var ldocs = docs.ToList();
                Assert.AreEqual(1, ldocs.Count);
                var doc = ldocs[0];
                Assert.AreEqual(2.1, doc.Value);
                Assert.AreSame(t, doc.Key);
                return null;
            };

            var s = new SolrServer<TestDocument>(basicServer, null, null);
            s.AddWithBoost(t, 2.1, parameters);
            Assert.AreEqual(1, basicServer.addWithBoost.Calls);
        }
Beispiel #29
0
        public void AddWithBoost_single_doc_calls_operations_with_null_add_parameters()
        {
            var basicServer = new MSolrBasicOperations <TestDocument>();

            basicServer.addWithBoost += (a, b) => {
                Assert.Null(b);
                return(null);
            };

            var mapper            = new MReadOnlyMappingManager();
            var validationManager = new MMappingValidator();

            var s = new SolrServer <TestDocument>(basicServer, mapper, validationManager);
            var t = new TestDocument();

            s.AddWithBoost(t, 2.1);

            Assert.Equal(1, basicServer.addWithBoost.Calls);
        }
Beispiel #30
0
        public void Add_single_doc_calls_operations_with_null_add_parameters()
        {
            var basicServer = new MSolrBasicOperations <TestDocument>();

            basicServer.addWithBoost += (docs, param) => {
                Assert.Null(param);
                return(null);
            };
            basicServer.addWithBoost &= x => x.Expect(1);

            var mapper            = new MReadOnlyMappingManager();
            var validationManager = new MMappingValidator();

            var s = new SolrServer <TestDocument>(basicServer, mapper, validationManager);
            var t = new TestDocument();

            s.Add(t);
            basicServer.addWithBoost.Verify();
        }
Beispiel #31
0
        public void FacetFieldQuery()
        {
            var mocks = new MockRepository();
            var query = new Dictionary <string, string>();

            query["q"]           = "*:*";
            query["facet"]       = "true";
            query["facet.field"] = "cat";
            query["rows"]        = "0";
            var connection        = new MockConnection(query);
            var resultParser      = mocks.StrictMock <ISolrQueryResultParser <TestDocumentWithUniqueKey> >();
            var mapper            = mocks.StrictMock <IReadOnlyMappingManager>();
            var validationManager = mocks.StrictMock <IMappingValidator>();
            var docSerializer     = mocks.StrictMock <ISolrDocumentSerializer <TestDocumentWithUniqueKey> >();

            With.Mocks(mocks).Expecting(() => {
                Expect.On(resultParser)
                .Call(resultParser.Parse(""))
                .IgnoreArguments()
                .Repeat.Once()
                .Return(new SolrQueryResults <TestDocumentWithUniqueKey> {
                    FacetFields = new Dictionary <string, ICollection <KeyValuePair <string, int> > > {
                        {
                            "cat", new List <KeyValuePair <string, int> > {
                                new KeyValuePair <string, int>("electronics", 5),
                                new KeyValuePair <string, int>("hard drive", 3),
                            }
                        }
                    }
                });
            }).Verify(() => {
                var querySerializer      = new DefaultQuerySerializer(new DefaultFieldSerializer());
                var facetQuerySerializer = new DefaultFacetQuerySerializer(querySerializer, new DefaultFieldSerializer());
                var queryExecuter        = new SolrQueryExecuter <TestDocumentWithUniqueKey>(resultParser, connection, querySerializer, facetQuerySerializer);
                var basicSolr            = new SolrBasicServer <TestDocumentWithUniqueKey>(connection, queryExecuter, docSerializer, null, null, null, null, null);
                var solr = new SolrServer <TestDocumentWithUniqueKey>(basicSolr, mapper, validationManager);
                var r    = solr.FacetFieldQuery(new SolrFacetFieldQuery("cat"));
                Assert.AreEqual(2, r.Count);
                Assert.AreEqual("electronics", r.First().Key);
            });
        }
Beispiel #32
0
        public void DeleteByMultipleId()
        {
            var connection = new MSolrConnection();

            connection.post += (url, content) => {
                Assert.AreEqual("/update", url);
                Assert.AreEqual("<delete><id>0</id><id>0</id></delete>", content);
                return(EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml"));
            };
            var headerParser = new MSolrHeaderResponseParser();

            headerParser.parse += _ => null;
            var basic = new SolrBasicServer <TestDocumentWithUniqueKey>(connection, null, null, null, headerParser, null, null, null);
            var ops   = new SolrServer <TestDocumentWithUniqueKey>(basic, new AttributesMappingManager(), null);

            ops.Delete(new[] {
                new TestDocumentWithUniqueKey(),
                new TestDocumentWithUniqueKey(),
            });
            Assert.AreEqual(1, connection.post.Calls);
        }
Beispiel #33
0
        public void Add_enumerable_with_add_parameters_calls_operations_with_same_add_parameters()
        {
            var mocks             = new MockRepository();
            var basicServer       = mocks.StrictMock <ISolrBasicOperations <TestDocument> >();
            var mapper            = mocks.StrictMock <IReadOnlyMappingManager>();
            var validationManager = mocks.StrictMock <IMappingValidator>();
            var parameters        = new AddParameters {
                CommitWithin = 4343
            };

            With.Mocks(mocks)
            .Expecting(() =>
                       Expect.Call(
                           basicServer.AddWithBoost(Arg <IEnumerable <KeyValuePair <TestDocument, double?> > > .Is.Anything, Arg <AddParameters> .Is.Equal(parameters)))
                       .Repeat.Once())
            .Verify(() =>
            {
                var s = new SolrServer <TestDocument>(basicServer, mapper, validationManager);
                var t = new[] { new TestDocument(), new TestDocument() };
                s.Add(t, parameters);
            });
        }
Beispiel #34
0
        public void Validate()
        {
            var mocks             = new MockRepository();
            var basicServer       = mocks.StrictMock <ISolrBasicOperations <TestDocument> >();
            var mapper            = mocks.StrictMock <IReadOnlyMappingManager>();
            var validationManager = mocks.StrictMock <IMappingValidator>();

            With.Mocks(mocks)
            .Expecting(() => {
                Expect.Call(basicServer.GetSchema())
                .Repeat.Once()
                .Return(new SolrSchema());
                Expect.Call(validationManager.EnumerateValidationResults(typeof(TestDocument), new SolrSchema()))
                .Repeat.Once()
                .IgnoreArguments()
                .Return(new List <ValidationResult>());
            })
            .Verify(() => {
                var s = new SolrServer <TestDocument>(basicServer, mapper, validationManager);
                s.EnumerateValidationResults().ToList();
            });
        }
Beispiel #35
0
        public void Add_single_doc_with_add_parameters_calls_operations_with_same_add_parameters()
        {
            var parameters = new AddParameters {
                CommitWithin = 4343
            };
            var basicServer = new MSolrBasicOperations <TestDocument>();

            basicServer.addWithBoost += (_, p) => {
                Assert.Equal(parameters, p);
                return(null);
            };

            var mapper            = new MReadOnlyMappingManager();
            var validationManager = new MMappingValidator();

            var s = new SolrServer <TestDocument>(basicServer, mapper, validationManager);
            var t = new TestDocument();

            s.Add(t, parameters);

            Assert.Equal(1, basicServer.addWithBoost.Calls);
        }
Beispiel #36
0
        public void AddWithBoost_single_doc_with_add_parameters_calls_operations_with_same_add_parameters()
        {
            var basicServer = new MSolrBasicOperations <TestDocument>();
            var parameters  = new AddParameters {
                CommitWithin = 4343
            };
            var t = new TestDocument();

            basicServer.addWithBoost += (docs, p) => {
                Assert.Same(parameters, p);
                var ldocs = docs.ToList();
                Assert.Equal(1, ldocs.Count);
                var doc = ldocs[0];
                Assert.Equal(2.1, doc.Value);
                Assert.Same(t, doc.Key);
                return(null);
            };

            var s = new SolrServer <TestDocument>(basicServer, null, null);

            s.AddWithBoost(t, 2.1, parameters);
            Assert.Equal(1, basicServer.addWithBoost.Calls);
        }
Beispiel #37
0
 public void Add_enumerable_with_add_parameters_calls_operations_with_same_add_parameters()
 {
     var mocks = new MockRepository();
     var basicServer = mocks.StrictMock<ISolrBasicOperations<TestDocument>>();
     var mapper = mocks.StrictMock<IReadOnlyMappingManager>();
     var validationManager = mocks.StrictMock<IMappingValidator>();
     var parameters = new AddParameters { CommitWithin = 4343 };
     With.Mocks(mocks)
         .Expecting(() =>
                    Expect.Call(
                        basicServer.AddWithBoost(Arg<IEnumerable<KeyValuePair<TestDocument, double?>>>.Is.Anything, Arg<AddParameters>.Is.Equal(parameters)))
                        .Repeat.Once())
         .Verify(() =>
         {
             var s = new SolrServer<TestDocument>(basicServer, mapper, validationManager);
             var t = new[] { new TestDocument(), new TestDocument() };
             s.AddRange(t, parameters);
         });
 }
Beispiel #38
0
 public void Validate()
 {
     var mocks = new MockRepository();
     var basicServer = mocks.StrictMock<ISolrBasicOperations<TestDocument>>();
     var mapper = mocks.StrictMock<IReadOnlyMappingManager>();
     var validationManager = mocks.StrictMock<IMappingValidator>();
     With.Mocks(mocks)
         .Expecting(() => {
             Expect.Call(basicServer.GetSchema())
                 .Repeat.Once()
                 .Return(new SolrSchema());
             Expect.Call(validationManager.EnumerateValidationResults(typeof(TestDocument), new SolrSchema()))
                 .Repeat.Once()
                 .IgnoreArguments()
                 .Return(new List<ValidationResult>());
         })
         .Verify(() => {
             var s = new SolrServer<TestDocument>(basicServer, mapper, validationManager);
             s.EnumerateValidationResults().ToList();
         });
 }
Beispiel #39
0
 public void DeleteDocumentWithUniqueKey()
 {
     var mapper = new MReadOnlyMappingManager();
     mapper.getUniqueKey += t => {
         Assert.AreEqual(typeof(TestDocumentWithUniqueKey), t);
         return new SolrFieldModel {
             Property = typeof (TestDocumentWithUniqueKey).GetProperty("id"),
             FieldName = "id",
         };
     };
     var basicServer = new MSolrBasicOperations<TestDocumentWithUniqueKey>();
     basicServer.delete &= x => x.Stub();
     var ops = new SolrServer<TestDocumentWithUniqueKey>(basicServer, mapper, null);
     ops.Delete(new TestDocumentWithUniqueKey());
     Assert.AreEqual(1, mapper.getUniqueKey.Calls);
 }
Beispiel #40
0
 public void DeleteDocumentWithoutUniqueKey_ShouldThrow()
 {
     var mapper = new MReadOnlyMappingManager();
     mapper.getUniqueKey += t => {
         Assert.AreEqual(typeof(TestDocumentWithoutUniqueKey), t);
         return null;
     };
     var ops = new SolrServer<TestDocumentWithoutUniqueKey>(null, mapper, null);
     ops.Delete(new TestDocumentWithoutUniqueKey());
     Assert.AreEqual(1, mapper.getUniqueKey.Calls);
 }
Beispiel #41
0
 public void FacetFieldQuery()
 {
     var mocks = new MockRepository();
     var query = new Dictionary<string, string>();
     query["q"] = "*:*";
     query["facet"] = "true";
     query["facet.field"] = "cat";
     query["rows"] = "0";
     var connection = new MockConnection(query);
     var resultParser = mocks.StrictMock<ISolrQueryResultParser<TestDocumentWithUniqueKey>>();
     var mapper = mocks.StrictMock<IReadOnlyMappingManager>();
     var validationManager = mocks.StrictMock<IMappingValidator>();
     var docSerializer = mocks.StrictMock<ISolrDocumentSerializer<TestDocumentWithUniqueKey>>();
     With.Mocks(mocks).Expecting(() => {
         Expect.On(resultParser)
             .Call(resultParser.Parse(""))
             .IgnoreArguments()
             .Repeat.Once()
             .Return(new SolrQueryResults<TestDocumentWithUniqueKey> {
                 FacetFields = new Dictionary<string, ICollection<KeyValuePair<string, int>>> {
                     {
                         "cat", new List<KeyValuePair<string, int>> {
                             new KeyValuePair<string, int>("electronics", 5),
                             new KeyValuePair<string, int>("hard drive", 3),
                         }
                         }
                 }
             });
     }).Verify(() => {
         var querySerializer = new DefaultQuerySerializer(new DefaultFieldSerializer());
         var facetQuerySerializer = new DefaultFacetQuerySerializer(querySerializer, new DefaultFieldSerializer());
         var queryExecuter = new SolrQueryExecuter<TestDocumentWithUniqueKey>(resultParser, connection, querySerializer, facetQuerySerializer);
         var basicSolr = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, queryExecuter, docSerializer, null, null, null, null, null);
         var solr = new SolrServer<TestDocumentWithUniqueKey>(basicSolr, mapper, validationManager);
         var r = solr.FacetFieldQuery(new SolrFacetFieldQuery("cat"));
         Assert.AreEqual(2, r.Count);
         Assert.AreEqual("electronics", r.First().Key);
     });
 }
Beispiel #42
0
 public void Ping() {
     var basicServer = new MSolrBasicOperations<TestDocument> {
         ping = () => new ResponseHeader {QTime = 2},
     };
     var s = new SolrServer<TestDocument>(basicServer, null, null);
     var r = s.Ping();
     Assert.AreEqual(2, r.QTime);
 }
 public void NullableDateTime()
 {
     var mocks = new MockRepository();
     var connection = mocks.CreateMock<ISolrConnection>();
     var resultParser = mocks.CreateMock<ISolrQueryResultParser<TestDocWithNullable>>();
     var queryExecuter = new SolrQueryExecuter<TestDocWithNullable>(connection, resultParser);
     var mapper = new AttributesMappingManager();
     var docSerializer = new SolrDocumentSerializer<TestDocWithNullable>(mapper, new DefaultFieldSerializer());
     var basicSolr = new SolrBasicServer<TestDocWithNullable>(connection, queryExecuter, docSerializer);
     var solr = new SolrServer<TestDocWithNullable>(basicSolr, mapper);
     string xml = null;
     With.Mocks(mocks)
         .Expecting(() => {
             Expect.Call(connection.Post(null, null))
                 .IgnoreArguments()
                 .Do(new Writer(delegate(string u, string s) {
                     Console.WriteLine(s);
                     xml = s;
                     return null;
                 }));
         })
         .Verify(() => {
             solr.Add(new TestDocWithNullable());
             Assert.AreEqual("<add><doc /></add>", xml);
         });
 }
Beispiel #44
0
 public void DeleteDocumentWithoutUniqueKey_ShouldThrow()
 {
     var mocks = new MockRepository();
     var basicServer = mocks.StrictMock<ISolrBasicOperations<TestDocumentWithoutUniqueKey>>();
     var mapper = mocks.StrictMock<IReadOnlyMappingManager>();
     var validationManager = mocks.StrictMock<IMappingValidator>();
     With.Mocks(mocks)
         .Expecting(() => {
             Expect.On(mapper)
                 .Call(mapper.GetUniqueKey(typeof (TestDocumentWithoutUniqueKey)))
                 .Return(null);
         }).Verify(() => {
             var ops = new SolrServer<TestDocumentWithoutUniqueKey>(basicServer, mapper, validationManager);
             ops.Delete(new TestDocumentWithoutUniqueKey());
         });
 }
Beispiel #45
0
 public void Validate() {
     var basicServer = new MSolrBasicOperations<TestDocument>();
     basicServer.getSchema += () => new SolrSchema();
     var validator = new MMappingValidator();
     validator.enumerate &= x => x.Return(new List<ValidationResult>());
     var s = new SolrServer<TestDocument>(basicServer, null, validator);
     s.EnumerateValidationResults().ToList();
     Assert.AreEqual(1, basicServer.getSchema.Calls);
     Assert.AreEqual(1, validator.enumerate.Calls);
 }
Beispiel #46
0
 public void Add_enumerable_calls_operations_with_null_add_parameters() {
     var basicServer = new MSolrBasicOperations<TestDocument>();
     basicServer.addWithBoost += (docs, p) => {
         Assert.IsNull(p);
         return null;
     };
     var s = new SolrServer<TestDocument>(basicServer, null, null);
     var t = new[] { new TestDocument(), new TestDocument() };
     s.AddRange(t);
     basicServer.addWithBoost.Verify();
 }
Beispiel #47
0
 public void GetSchema() {
     var basicServer = new MSolrBasicOperations<TestDocument>();
     basicServer.getSchema += () => new SolrSchema {UniqueKey = "bla"};            
     var s = new SolrServer<TestDocument>(basicServer, null, null);
     var r = s.GetSchema();
     Assert.AreEqual("bla", r.UniqueKey);
 }
Beispiel #48
0
 public void Rollback() {
     var basicServer = new MSolrBasicOperations<TestDocument>();
     basicServer.rollback += () => new ResponseHeader {QTime = 2};
     var s = new SolrServer<TestDocument>(basicServer, null, null);
     var r = s.Rollback();
     Assert.AreEqual(2, r.QTime);
     Assert.AreEqual(1, basicServer.rollback.Calls);
 }
Beispiel #49
0
 public void Commit() {
     var basicServer = new MSolrBasicOperations<TestDocument> {
         commit = _ => new ResponseHeader { QTime = 2}
     };
     var s = new SolrServer<TestDocument>(basicServer, null, null);
     var r = s.Commit();
     Assert.AreEqual(2, r.QTime);
 }
Beispiel #50
0
 public void DeleteByMultipleId()
 {
     var connection = new MSolrConnection();
     connection.post += (url, content) => {
         Assert.AreEqual("/update", url);
         Assert.AreEqual("<delete><id>0</id><id>0</id></delete>", content);
         return EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml");
     };
     var headerParser = new MSolrHeaderResponseParser();
     headerParser.parse += _ => null;
     var basic = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, null, null, null, headerParser, null, null, null);
     var ops = new SolrServer<TestDocumentWithUniqueKey>(basic, new AttributesMappingManager(), null);
     ops.Delete(new[] {
         new TestDocumentWithUniqueKey(),
         new TestDocumentWithUniqueKey(),
     });
     Assert.AreEqual(1, connection.post.Calls);
 }
 public void DeleteDocumentWithUniqueKey()
 {
     var mocks = new MockRepository();
     var basicServer = mocks.CreateMock<ISolrBasicOperations<TestDocumentWithUniqueKey>>();
     var mapper = mocks.CreateMock<IReadOnlyMappingManager>();
     With.Mocks(mocks)
         .Expecting(() => {
             Expect.Call(basicServer.Send(null))
                 .IgnoreArguments()
                 .Repeat.Once()
                 .Return("");
             Expect.Call(mapper.GetUniqueKey(typeof (TestDocumentWithUniqueKey)))
                 .Return(new KeyValuePair<PropertyInfo, string>(typeof (TestDocumentWithUniqueKey).GetProperty("id"), "id"));
         })
         .Verify(delegate {
             var ops = new SolrServer<TestDocumentWithUniqueKey>(basicServer, mapper);
             ops.Delete(new TestDocumentWithUniqueKey());
         });
 }
Beispiel #52
0
 public void DeleteByMultipleId()
 {
     var mocks = new MockRepository();
     var connection = mocks.StrictMock<ISolrConnection>();
     var headerParser = mocks.StrictMock<ISolrHeaderResponseParser>();
     var executer = mocks.StrictMock<ISolrQueryExecuter<TestDocumentWithUniqueKey>>();
     var docSerializer = mocks.StrictMock<ISolrDocumentSerializer<TestDocumentWithUniqueKey>>();
     var validationManager = mocks.StrictMock<IMappingValidator>();
     With.Mocks(mocks)
         .Expecting(() => {
             Expect.On(connection)
                 .Call(connection.Post("/update", "<delete><id>0</id><id>0</id></delete>"))
                 .Repeat.Once()
                 .Return(EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml"));
             Expect.On(headerParser)
                 .Call(headerParser.Parse(null))
                 .IgnoreArguments()
                 .Return(new ResponseHeader());
         })
         .Verify(() => {
             var basic = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, executer, docSerializer, null, headerParser, null, null, null);
             var ops = new SolrServer<TestDocumentWithUniqueKey>(basic, new AttributesMappingManager(), validationManager);
             ops.Delete(new[] {
                     new TestDocumentWithUniqueKey(),
                     new TestDocumentWithUniqueKey(),
                 });
         });
 }
 public void DeleteDocumentWithoutUniqueKey_ShouldThrow()
 {
     var mocks = new MockRepository();
     var basicServer = mocks.CreateMock<ISolrBasicOperations<TestDocumentWithoutUniqueKey>>();
     var mapper = mocks.CreateMock<IReadOnlyMappingManager>();
     With.Mocks(mocks)
         .Expecting(() => {
             Expect.Call(mapper.GetUniqueKey(typeof (TestDocumentWithoutUniqueKey)))
                 .Throw(new NoUniqueKeyException(typeof(TestDocumentWithoutUniqueKey)));
         }).Verify(() => {
             var ops = new SolrServer<TestDocumentWithoutUniqueKey>(basicServer, mapper);
             ops.Delete(new TestDocumentWithoutUniqueKey());
         });
 }
Beispiel #54
0
 public void DeleteDocumentWithUniqueKey()
 {
     var mocks = new MockRepository();
     var basicServer = mocks.StrictMock<ISolrBasicOperations<TestDocumentWithUniqueKey>>();
     var mapper = mocks.StrictMock<IReadOnlyMappingManager>();
     var validationManager = mocks.StrictMock<IMappingValidator>();
     With.Mocks(mocks)
         .Expecting(() => {
             Expect.On(basicServer)
                 .Call(basicServer.Delete(new[] {"0"}, null))
                 .IgnoreArguments()
                 .Return(new ResponseHeader());
             Expect.On(mapper)
                 .Call(mapper.GetUniqueKey(typeof (TestDocumentWithUniqueKey)))
                 .Return(new SolrFieldModel {
                     Property = typeof(TestDocumentWithUniqueKey).GetProperty("id"),
                     FieldName = "id"
                 });
         })
         .Verify(delegate {
             var ops = new SolrServer<TestDocumentWithUniqueKey>(basicServer, mapper, validationManager);
             ops.Delete(new TestDocumentWithUniqueKey());
         });
 }
 public void DeleteByMultipleId()
 {
     var mocks = new MockRepository();
     var connection = mocks.CreateMock<ISolrConnection>();
     var executer = mocks.CreateMock<ISolrQueryExecuter<TestDocumentWithUniqueKey>>();
     var docSerializer = mocks.CreateMock<ISolrDocumentSerializer<TestDocumentWithUniqueKey>>();
     With.Mocks(mocks)
         .Expecting(() => Expect.Call(connection.Post("/update", "<delete><id>0</id><id>0</id></delete>"))
                              .Repeat.Once()
                              .Return(null))
         .Verify(delegate {
             var basic = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, executer, docSerializer);
             var ops = new SolrServer<TestDocumentWithUniqueKey>(basic, new AttributesMappingManager());
             ops.Delete(new[] {
                 new TestDocumentWithUniqueKey(),
                 new TestDocumentWithUniqueKey(),
             });
         });
 }
Beispiel #56
0
 public void NullableDateTime()
 {
     var mocks = new MockRepository();
     var connection = mocks.StrictMock<ISolrConnection>();
     var responseParser = mocks.DynamicMock<ISolrHeaderResponseParser>();
     var resultParser = mocks.StrictMock<ISolrQueryResultParser<TestDocWithNullable>>();
     var queryExecuter = new SolrQueryExecuter<TestDocWithNullable>(resultParser, connection, null, null);
     var mapper = new AttributesMappingManager();
     var docSerializer = new SolrDocumentSerializer<TestDocWithNullable>(mapper, new DefaultFieldSerializer());
     var validationManager = mocks.StrictMock<IMappingValidator>();
     var basicSolr = new SolrBasicServer<TestDocWithNullable>(connection, queryExecuter, docSerializer, null, responseParser, null, null, null);
     var solr = new SolrServer<TestDocWithNullable>(basicSolr, mapper, validationManager);
     string xml = null;
     With.Mocks(mocks)
         .Expecting(() => {
             Expect.On(connection)
                 .Call(connection.Post(null, null))
                 .IgnoreArguments()
                 .Do(new Writer(delegate(string u, string s) {
                     Console.WriteLine(s);
                     xml = s;
                     return EmbeddedResource.GetEmbeddedString(GetType(), "Resources.response.xml");
                 }));
         })
         .Verify(() => {
             solr.Add(new TestDocWithNullable());
             Assert.AreEqual("<add><doc /></add>", xml);
         });
 }
Beispiel #57
0
 public void Add_enumerable_with_add_parameters_calls_operations_with_same_add_parameters() {
     var parameters = new AddParameters { CommitWithin = 4343 };
     var basicServer = new MSolrBasicOperations<TestDocument>();
     basicServer.addWithBoost += (docs, p) => {
         Assert.AreSame(parameters, p);
         return null;
     };
     var s = new SolrServer<TestDocument>(basicServer, null, null);
     var t = new[] { new TestDocument(), new TestDocument() };
     s.AddRange(t, parameters);
 }