Beispiel #1
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 #2
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();
        }
Beispiel #3
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 #4
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 #5
0
        public void Add_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.Add(t);
            });
        }
Beispiel #6
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 #7
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 #8
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 #9
0
 public void Add_single_doc_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 TestDocument();
             s.Add(t, parameters);
         });
 }
 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);
         });
 }