當前位置: 首頁>>代碼示例>>C#>>正文


C# Tests.MockConnection類代碼示例

本文整理匯總了C#中SolrNet.Tests.MockConnection的典型用法代碼示例。如果您正苦於以下問題:C# MockConnection類的具體用法?C# MockConnection怎麽用?C# MockConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MockConnection類屬於SolrNet.Tests命名空間,在下文中一共展示了MockConnection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Execute

 public void Execute()
 {
     const string queryString = "id:123456";
     var q = new Dictionary<string, string>();
     q["q"] = queryString;
     var conn = new MockConnection(q);
     var mocks = new MockRepository();
     var parser = mocks.StrictMock<ISolrQueryResultParser<TestDocument>>();
     var mockR = mocks.DynamicMock<SolrQueryResults<TestDocument>>();
     var serializer = mocks.StrictMock<ISolrQuerySerializer>();
     With.Mocks(mocks).Expecting(() => {
         Expect.On(parser)
             .Call(parser.Parse(null))
             .IgnoreArguments()
             .Repeat.Once()
             .Return(mockR);
         Expect.On(serializer)
             .Call(serializer.Serialize(null))
             .IgnoreArguments()
             .Repeat.Once()
             .Return(queryString);
     }).Verify(() => {
         var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, serializer, null, null);
         var r = queryExecuter.Execute(new SolrQuery(queryString), null);
     });
 }
開發者ID:paulcarroll,項目名稱:SolrNet,代碼行數:26,代碼來源:SolrQueryExecuterTests.cs

示例2: Execute

        public void Execute() {
            const string queryString = "id:123456";
            var q = new Dictionary<string, string>();
            q["q"] = queryString;
            var conn = new MockConnection(q);
            var serializer = new MSolrQuerySerializer();
            serializer.serialize += _ => queryString;
            var parser = new MSolrAbstractResponseParser<TestDocument>();
            parser.parse &= x => x.Stub();

            var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, serializer, null, null);
            var r = queryExecuter.Execute(new SolrQuery(queryString), null);
            Assert.AreEqual(1, serializer.serialize.Calls);
        }
開發者ID:Jo1nes,項目名稱:SolrNet,代碼行數:14,代碼來源:SolrQueryExecuterTests.cs

示例3: FilterQueries

 public void FilterQueries()
 {
     var conn = new MockConnection(new Dictionary<string, string> {
         {"fq", "id:0"},
         {"q", "*:*"},
         {"rows", "100000000"},
     });
     var mocks = new MockRepository();
     var queryExec = mocks.StrictMock<ISolrQueryExecuter<Document>>();
     var docSerializer = mocks.StrictMock<ISolrDocumentSerializer<Document>>();
     ISolrBasicReadOnlyOperations<Document> solr = new SolrBasicServer<Document>(conn, queryExec, docSerializer, null, null, null, null, null);
     solr.Query(SolrQuery.All, new QueryOptions {
         FilterQueries = new[] {new SolrQuery("id:0")},
     });
 }
開發者ID:Cort01,項目名稱:SolrNet,代碼行數:15,代碼來源:FilterQueryTests.cs

示例4: Sort

 public void Sort() {
     const string queryString = "id:123456";
     var q = new Dictionary<string, string>();
     q["q"] = queryString;
     q["rows"] = SolrQueryExecuter<TestDocument>.ConstDefaultRows.ToString();
     q["sort"] = "id asc";
     var conn = new MockConnection(q);
     var querySerializer = new SolrQuerySerializerStub(queryString);
     var parser = new MSolrAbstractResponseParser<TestDocument>();
     parser.parse &= x => x.Expect(1);
     var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, querySerializer, null, null);
     var r = queryExecuter.Execute(new SolrQuery(queryString), new QueryOptions {
         OrderBy = new[] { new SortOrder("id") }
     });
     parser.parse.Verify();
 }
開發者ID:Jo1nes,項目名稱:SolrNet,代碼行數:16,代碼來源:SolrQueryExecuterTests.cs

示例5: Boosting

        public void Boosting()
        {
            var conn = new MockConnection(new Dictionary<string, string> {
                {"fq", "id:0"},
                {"q", "*:*"},
                {"rows", "100000000"},
            });
            var mocks = new MockRepository();
            var queryExec = mocks.StrictMock<ISolrQueryExecuter<Document>>();
            var docSerializer = mocks.StrictMock<ISolrDocumentSerializer<Document>>();
            ISolrBasicReadOnlyOperations<Document> solr = new SolrBasicServer<Document>(conn, queryExec, docSerializer, null, null, null, null, null);

            var linqQuery = from doc in solr.AsQueryable()
                            where (doc.Name == "john").Boost(10)
                            select doc;

            QueryOptions qo;
            var resDocs = ((IQueryableSolrNet<Document>)linqQuery).GetSolrQuery(out qo);

            Assert.AreEqual("(name:john)^10", resDocs.Query);
        }
開發者ID:Cort01,項目名稱:SolrNet,代碼行數:21,代碼來源:QueryableSolrNetTester.cs

示例6: AndsOrs

        public void AndsOrs()
        {
            var conn = new MockConnection(new Dictionary<string, string> {
                {"fq", "id:0"},
                {"q", "*:*"},
                {"rows", "100000000"},
            });
            var mocks = new MockRepository();
            var queryExec = mocks.StrictMock<ISolrQueryExecuter<Document>>();
            var docSerializer = mocks.StrictMock<ISolrDocumentSerializer<Document>>();
            ISolrBasicReadOnlyOperations<Document> solr = new SolrBasicServer<Document>(conn, queryExec, docSerializer, null, null, null, null, null);

            var linqQuery = from doc in solr.AsQueryable()
                            where doc.DefaultFieldEquals("aa") && (doc.Price >= 1 || doc.Price <= 11)
                            select doc;

            QueryOptions qo;
            var resDocs = ((IQueryableSolrNet<Document>)linqQuery).GetSolrQuery(out qo);

            Assert.AreEqual("(aa AND ((price:[1 TO *]) OR (price:[* TO  11])))", resDocs.Query);
        }
開發者ID:Cort01,項目名稱:SolrNet,代碼行數:21,代碼來源:QueryableSolrNetTester.cs

示例7: Collection

        public void Collection()
        {
            var conn = new MockConnection(new Dictionary<string, string> {
                {"fq", "id:0"},
                {"q", "*:*"},
                {"rows", "100000000"},
            });
            var mocks = new MockRepository();
            var queryExec = mocks.StrictMock<ISolrQueryExecuter<Document>>();
            var docSerializer = mocks.StrictMock<ISolrDocumentSerializer<Document>>();
            ISolrBasicReadOnlyOperations<Document> solr = new SolrBasicServer<Document>(conn, queryExec, docSerializer, null, null, null, null, null);

            var linqQuery = from doc in solr.AsQueryable()
                            where doc.Categories.AnyItem() == "cat1"
                            select doc;

            QueryOptions qo;
            var resDocs = ((IQueryableSolrNet<Document>)linqQuery).GetSolrQuery(out qo);

            Assert.AreEqual("(cat:cat1)", resDocs.Query);
        }
開發者ID:Cort01,項目名稱:SolrNet,代碼行數:21,代碼來源:QueryableSolrNetTester.cs

示例8: OrderByAscDescMultiple

 public void OrderByAscDescMultiple()
 {
     var query = new Dictionary<string, string> {
         {"q", "((Id:123456))"},
         {"rows", DefaultRows()},
         {"sort", "id asc,name desc"},
     };
     var conn = new MockConnection(query);
     Solr.Connection = conn;
     var doc = new TestDocumentWithId {Id = 123456};
     Solr.Query<TestDocumentWithId>()
         .By("Id").Is("123456")
         .OrderBy("id", Order.ASC)
         .OrderBy("name", Order.DESC)
         .Run();
 }
開發者ID:TomasEkeli,項目名稱:SolrNet,代碼行數:16,代碼來源:DSLTests.cs

示例9: HighlightingWithoutFieldsOutputsPrePost

        public void HighlightingWithoutFieldsOutputsPrePost() {
            const string afterTerm = "after";
            const string beforeTerm = "before";

            var q = new Dictionary<string, string>();
            q["q"] = "";
            q["rows"] = SolrQueryExecuter<TestDocument>.ConstDefaultRows.ToString();
            q["hl"] = "true";
            q["hl.tag.pre"] = beforeTerm;
            q["hl.tag.post"] = afterTerm;
            q["hl.useFastVectorHighlighter"] = "true";

            var conn = new MockConnection(q);
            var querySerializer = new SolrQuerySerializerStub("");

            var parser = new MSolrAbstractResponseParser<TestDocument>();
            parser.parse &= x => x.Stub();
            var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, querySerializer, null, null);
            queryExecuter.Execute(new SolrQuery(""), new QueryOptions {
                Highlight = new HighlightingParameters {
                    AfterTerm = afterTerm,
                    BeforeTerm = beforeTerm,
                    UseFastVectorHighlighter = true,
                }
            });
        }
開發者ID:Jo1nes,項目名稱:SolrNet,代碼行數:26,代碼來源:SolrQueryExecuterTests.cs

示例10: QueryISolrQueryWithPagination

 public void QueryISolrQueryWithPagination()
 {
     const string queryString = "id:123";
     var query = new Dictionary<string, string> {
         {"q", queryString},
         {"start", 10.ToString()},
         {"rows", 20.ToString()}
     };
     var conn = new MockConnection(query);
     Solr.Connection = conn;
     Solr.Query<TestDocument>(new SolrQuery(queryString), 10, 20);
 }
開發者ID:TomasEkeli,項目名稱:SolrNet,代碼行數:12,代碼來源:DSLTests.cs

示例11: Sort

        public void Sort()
        {
            var conn = new MockConnection(new Dictionary<string, string> {
                {"fq", "id:0"},
                {"q", "*:*"},
                {"rows", "100000000"},
            });
            var mocks = new MockRepository();
            var queryExec = mocks.StrictMock<ISolrQueryExecuter<Document>>();
            var docSerializer = mocks.StrictMock<ISolrDocumentSerializer<Document>>();
            ISolrBasicReadOnlyOperations<Document> solr = new SolrBasicServer<Document>(conn, queryExec, docSerializer, null, null, null, null, null);
            int priceVal = 1;
            DateTime dt = new DateTime(2011, 1, 1);
            var linqQuery = from doc in solr.AsQueryable()
                            where (doc.Price >= priceVal || doc.Timestamp >= dt)
                            orderby doc.Id, doc.Price descending
                            select doc;

            QueryOptions qo;
            var resDocs = ((IQueryableSolrNet<Document>)linqQuery).GetSolrQuery(out qo);

            Assert.AreEqual(qo.OrderBy.Count, 2);
            var so = new SortOrder("id", Order.ASC);
            Assert.IsTrue(qo.OrderBy.Contains(so));
            so = new SortOrder("price", Order.DESC);
            Assert.IsTrue(qo.OrderBy.Contains(so));
        }
開發者ID:Cort01,項目名稱:SolrNet,代碼行數:27,代碼來源:QueryableSolrNetTester.cs

示例12: FacetQuery

 public void FacetQuery()
 {
     var mocks = new MockRepository();
     var query = new Dictionary<string, string>();
     query["q"] = "";
     query["rows"] = SolrQueryExecuter<TestDocumentWithUniqueKey>.ConstDefaultRows.ToString();
     query["facet"] = "true";
     query["facet.query"] = "id:1";
     var connection = new MockConnection(query);
     var parser = mocks.StrictMock<ISolrQueryResultParser<TestDocumentWithUniqueKey>>();
     var docSerializer = mocks.StrictMock<ISolrDocumentSerializer<TestDocumentWithUniqueKey>>();
     var querySerializer = new DefaultQuerySerializer(new DefaultFieldSerializer());
     var facetQuerySerializer = new DefaultFacetQuerySerializer(querySerializer, new DefaultFieldSerializer());
     With.Mocks(mocks).Expecting(() => {
         Expect.On(parser)
             .Call(parser.Parse(null))
             .IgnoreArguments()
             .Return(new SolrQueryResults<TestDocumentWithUniqueKey>());
     }).Verify(() => {
         var executer = new SolrQueryExecuter<TestDocumentWithUniqueKey>(parser, connection, querySerializer, facetQuerySerializer);
         var solr = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, executer, docSerializer, null, null, null, null, null);
         var r = solr.Query(new SolrQuery(""), new QueryOptions {
             Facet = new FacetParameters {
                 Queries = new ISolrFacetQuery[] {
                     new SolrFacetQuery(new SolrQuery("id:1")),
                 },
             }
         });
     });
 }
開發者ID:Cort01,項目名稱:SolrNet,代碼行數:30,代碼來源:SolrOperationsTests.cs

示例13: MultipleFacetFields

        public void MultipleFacetFields()
        {
            var conn = new MockConnection(new[] {
                KV.Create("q", ""),
                KV.Create("rows", SolrQueryExecuter<TestDocument>.ConstDefaultRows.ToString()),
                KV.Create("facet", "true"),
                KV.Create("facet.field", "Id"),
                KV.Create("facet.field", "OtherField"),
            });
            var serializer = new DefaultQuerySerializer(new DefaultFieldSerializer());
            var facetQuerySerializer = new DefaultFacetQuerySerializer(serializer, new DefaultFieldSerializer());

            var parser = new MSolrAbstractResponseParser<TestDocument>();
            parser.parse &= x => x.Stub();
            var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, serializer, facetQuerySerializer, null);
            queryExecuter.Execute(new SolrQuery(""), new QueryOptions {
                Facet = new FacetParameters {
                    Queries = new ISolrFacetQuery[] {
                        new SolrFacetFieldQuery("Id"),
                        new SolrFacetFieldQuery("OtherField"),
                    }
                }
            });
        }
開發者ID:pampero,項目名稱:cgFramework,代碼行數:24,代碼來源:SolrQueryExecuterTests.cs

示例14: FilterQuery

        public void FilterQuery()
        {
            var querySerializer = new DefaultQuerySerializer(new DefaultFieldSerializer());
            var conn = new MockConnection(new[] {
                KV.Create("q", "*:*"),
                KV.Create("rows", "10"),
                KV.Create("fq", "id:0"),
                KV.Create("fq", "id:2"),
            });

            var parser = new MSolrAbstractResponseParser<TestDocument>();
            parser.parse &= x => x.Stub();
            var queryExecuter = new SolrQueryExecuter<TestDocument>(parser, conn, querySerializer, null, null) {
                DefaultRows = 10,
            };
            queryExecuter.Execute(SolrQuery.All, new QueryOptions {
                FilterQueries = new[] {
                    new SolrQuery("id:0"),
                    new SolrQuery("id:2"),
                },
            });
        }
開發者ID:pampero,項目名稱:cgFramework,代碼行數:22,代碼來源:SolrQueryExecuterTests.cs

示例15: QueryWithPagination

        public void QueryWithPagination()
        {
            const string qstring = "id:123";
            const int start = 10;
            const int rows = 20;

            var mocks = new MockRepository();
            //var connection = mocks.CreateMock<ISolrConnection>();
            var query = new Dictionary<string, string>();
            query["q"] = qstring;
            query["start"] = start.ToString();
            query["rows"] = rows.ToString();
            var connection = new MockConnection(query);
            var parser = mocks.CreateMock<ISolrQueryResultParser<TestDocumentWithUniqueKey>>();
            var docSerializer = mocks.CreateMock<ISolrDocumentSerializer<TestDocumentWithUniqueKey>>();
            With.Mocks(mocks).Expecting(() => {
                Expect.On(parser).Call(parser.Parse(null))
                    .IgnoreArguments()
                    .Return(new SolrQueryResults<TestDocumentWithUniqueKey>());
            }).Verify(() => {
                var executer = new SolrQueryExecuter<TestDocumentWithUniqueKey>(connection, parser);
                var solr = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, executer, docSerializer);
                var r = solr.Query(new SolrQuery(qstring), new QueryOptions {Start = start, Rows = rows});
            });
        }
開發者ID:osdezwart,項目名稱:SolrNet,代碼行數:25,代碼來源:SolrOperationsTests.cs


注:本文中的SolrNet.Tests.MockConnection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。