本文整理汇总了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);
});
}
示例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);
}
示例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")},
});
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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,
}
});
}
示例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);
}
示例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));
}
示例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")),
},
}
});
});
}
示例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"),
}
}
});
}
示例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"),
},
});
}
示例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});
});
}