Esempio n. 1
0
        public void QueryAll_with_pagination()
        {
            var querySerializer = new MSolrQuerySerializer();

            querySerializer.serialize += _ => "id:123456";

            var serviceLocator = new MServiceLocator();

            serviceLocator.getService = MServiceLocator.Table(new Dictionary <System.Type, object> {
                { typeof(ISolrReadOnlyOperations <Entity>), mockSolr },
                { typeof(ISolrQuerySerializer), querySerializer },
            });

            ServiceLocator.SetLocatorProvider(() => serviceLocator);

            mockSolr.queryStringOptions += (s, o) => {
                Assert.Equal("id:123456", s);
                Assert.Equal(5, o.Rows);
                Assert.Equal(3, o.Start);
                Assert.Equal(1, o.OrderBy.Count);
                Assert.Equal("pepe asc", o.OrderBy.First().ToString());
                return(new SolrQueryResults <Entity>());
            };
            mockSolr.queryStringOptions &= x => x.Expect(1);

            using (var session = new SolrSession(sessionFactory.OpenSession())) {
                var entities = session.CreateSolrQuery(new SolrQueryByField("id", "123456"))
                               .SetMaxResults(5)
                               .SetFirstResult(3)
                               .SetSort(Order.Asc("pepe"))
                               .List <Entity>();
            }
        }
Esempio n. 2
0
        public void QueryAll_with_pagination()
        {
            var serviceLocator = MockRepository.GenerateMock <IServiceLocator>();

            serviceLocator.Expect(x => x.GetService(typeof(ISolrReadOnlyOperations <Entity>))).Return(mockSolr);
            var querySerializer = MockRepository.GenerateMock <ISolrQuerySerializer>();

            querySerializer.Expect(x => x.Serialize(null))
            .IgnoreArguments()
            .Return("id:123456");
            serviceLocator.Expect(x => x.GetService(typeof(ISolrQuerySerializer))).Return(querySerializer);
            ServiceLocator.SetLocatorProvider(() => serviceLocator);
            mockSolr.Expect(x => x.Query("", new QueryOptions()))
            .IgnoreArguments()
            .Do(new SQuery((s, o) => {
                Assert.AreEqual("id:123456", s);
                Assert.AreEqual(5, o.Rows);
                Assert.AreEqual(3, o.Start);
                Assert.AreEqual(1, o.OrderBy.Count);
                Assert.AreEqual("pepe asc", o.OrderBy.First().ToString());
                return(new SolrQueryResults <Entity>());
            }))
            ;
            using (var session = new SolrSession(sessionFactory.OpenSession())) {
                var entities = session.CreateSolrQuery(new SolrQueryByField("id", "123456"))
                               .SetMaxResults(5)
                               .SetFirstResult(3)
                               .SetSort(Criterion.Order.Asc("pepe"))
                               .List <Entity>();
            }
        }
Esempio n. 3
0
        public void QueryAll_with_pagination() {

            var querySerializer = new MSolrQuerySerializer();
            querySerializer.serialize += _ => "id:123456";

            var serviceLocator = new MServiceLocator();
            serviceLocator.getService = MServiceLocator.Table(new Dictionary<System.Type, object> {
                {typeof (ISolrReadOnlyOperations<Entity>), mockSolr},
                {typeof (ISolrQuerySerializer), querySerializer},
            });

            ServiceLocator.SetLocatorProvider(() => serviceLocator);

            mockSolr.queryStringOptions += (s, o) => {
                Assert.AreEqual("id:123456", s);
                Assert.AreEqual(5, o.Rows);
                Assert.AreEqual(3, o.Start);
                Assert.AreEqual(1, o.OrderBy.Count);
                Assert.AreEqual("pepe asc", o.OrderBy.First().ToString());
                return new SolrQueryResults<Entity>();
            };
            mockSolr.queryStringOptions &= x => x.Expect(1);

            using (var session = new SolrSession(sessionFactory.OpenSession())) {
                var entities = session.CreateSolrQuery(new SolrQueryByField("id", "123456"))
                    .SetMaxResults(5)
                    .SetFirstResult(3)
                    .SetSort(Order.Asc("pepe"))
                    .List<Entity>();
            }
        }
Esempio n. 4
0
 public void QueryAll_with_pagination()
 {
     var serviceLocator = MockRepository.GenerateMock<IServiceLocator>();
     serviceLocator.Expect(x => x.GetService(typeof (ISolrReadOnlyOperations<Entity>))).Return(mockSolr);
     var querySerializer = MockRepository.GenerateMock<ISolrQuerySerializer>();
     querySerializer.Expect(x => x.Serialize(null))
         .IgnoreArguments()
         .Return("id:123456");
     serviceLocator.Expect(x => x.GetService(typeof(ISolrQuerySerializer))).Return(querySerializer);
     ServiceLocator.SetLocatorProvider(() => serviceLocator);
     mockSolr.Expect(x => x.Query("", new QueryOptions()))
         .IgnoreArguments()
         .Do(new SQuery((s, o) => {
             Assert.AreEqual("id:123456", s);
             Assert.AreEqual(5, o.Rows);
             Assert.AreEqual(3, o.Start);
             Assert.AreEqual(1, o.OrderBy.Count);
             Assert.AreEqual("pepe asc", o.OrderBy.First().ToString());
             return new SolrQueryResults<Entity>();
         }))
         ;
     using (var session = new SolrSession(sessionFactory.OpenSession())) {
         var entities = session.CreateSolrQuery(new SolrQueryByField("id", "123456"))
             .SetMaxResults(5)
             .SetFirstResult(3)
             .SetSort(Criterion.Order.Asc("pepe"))
             .List<Entity>();
     }
 }
Esempio n. 5
0
 public void QueryAll()
 {
     var serviceLocator = MockRepository.GenerateMock<IServiceLocator>();
     serviceLocator.Expect(x => x.GetService(typeof (ISolrReadOnlyOperations<Entity>))).Return(mockSolr);
     ServiceLocator.SetLocatorProvider(() => serviceLocator);
     mockSolr.Expect(x => x.Query("*:*", new QueryOptions()))
         .IgnoreArguments()
         .Do(new SQuery((s, o) => {
             Assert.AreEqual("*:*", s);
             return new SolrQueryResults<Entity>();
         }))
         ;
     using (var session = new SolrSession(sessionFactory.OpenSession())) {
         var entities = session.CreateSolrQuery("*:*").List<Entity>();
     }
 }
Esempio n. 6
0
        public void QueryAll()
        {
            var serviceLocator = MockRepository.GenerateMock <IServiceLocator>();

            serviceLocator.Expect(x => x.GetService(typeof(ISolrReadOnlyOperations <Entity>))).Return(mockSolr);
            ServiceLocator.SetLocatorProvider(() => serviceLocator);
            mockSolr.Expect(x => x.Query("*:*", new QueryOptions()))
            .IgnoreArguments()
            .Do(new SQuery((s, o) => {
                Assert.AreEqual("*:*", s);
                return(new SolrQueryResults <Entity>());
            }))
            ;
            using (var session = new SolrSession(sessionFactory.OpenSession())) {
                var entities = session.CreateSolrQuery("*:*").List <Entity>();
            }
        }
Esempio n. 7
0
 public void QueryAll() {
     var serviceLocator = new MServiceLocator();
     serviceLocator.getService += t => {
         if (t == typeof (ISolrReadOnlyOperations<Entity>))
             return mockSolr;
         throw new Exception("unexpected type");
     };
     ServiceLocator.SetLocatorProvider(() => serviceLocator);
     mockSolr.queryStringOptions += (q, opt) => {
         Assert.AreEqual("*:*", q);
         return new SolrQueryResults<Entity>();
     };
     mockSolr.queryStringOptions &= x => x.Expect(1);
     using (var session = new SolrSession(sessionFactory.OpenSession())) {
         var entities = session.CreateSolrQuery("*:*").List<Entity>();
     }
 }
Esempio n. 8
0
        public void QueryAll()
        {
            var serviceLocator = new MServiceLocator();

            serviceLocator.getService += t => {
                if (t == typeof(ISolrReadOnlyOperations <Entity>))
                {
                    return(mockSolr);
                }
                throw new Exception("unexpected type");
            };
            ServiceLocator.SetLocatorProvider(() => serviceLocator);
            mockSolr.queryStringOptions += (q, opt) => {
                Assert.Equal("*:*", q);
                return(new SolrQueryResults <Entity>());
            };
            mockSolr.queryStringOptions &= x => x.Expect(1);
            using (var session = new SolrSession(sessionFactory.OpenSession())) {
                var entities = session.CreateSolrQuery("*:*").List <Entity>();
            }
        }