Ejemplo n.º 1
0
        public void MoreLikeThisHandlerQuery()
        {
            const string qstring = "id:123";

            RhinoMocks.Logger = new Rhino.Mocks.Impl.TextWriterExpectationLogger(Console.Out);

            var mocks = new MockRepository();
            var query = new Dictionary <string, string>();

            query["q"] = qstring;

            var connection      = mocks.StrictMock <ISolrConnection>();
            var docSerializer   = mocks.StrictMock <ISolrDocumentSerializer <TestDocumentWithUniqueKey> >();
            var querySerializer = mocks.StrictMock <ISolrQuerySerializer>();
            var mlthParser      = mocks.StrictMock <ISolrMoreLikeThisHandlerQueryResultsParser <TestDocumentWithUniqueKey> >();

            With.Mocks(mocks)
            .Expecting(() =>
            {
                Expect.On(querySerializer)
                .Call(querySerializer.Serialize(null))
                .IgnoreArguments()
                .Return(qstring);
                Expect.On(connection)
                .Call(connection.Get(null, null))
                .IgnoreArguments()
                .Return(EmbeddedResource.GetEmbeddedString(GetType(), "Resources.responseWithInterestingTermsDetails.xml"));
                Expect.On(mlthParser)
                .Call(mlthParser.Parse(null))
                .IgnoreArguments()
                .Return(new SolrMoreLikeThisHandlerResults <TestDocumentWithUniqueKey>());
            })
            .Verify(() =>
            {
                var executer = new SolrQueryExecuter <TestDocumentWithUniqueKey>(null, connection, querySerializer, null, mlthParser);
                var solr     = new SolrBasicServer <TestDocumentWithUniqueKey>(connection, executer, docSerializer, null, null, null, null, null);
                var r        = solr.MoreLikeThis(new SolrMoreLikeThisHandlerQuery(new SolrQuery(qstring)), new MoreLikeThisHandlerQueryOptions(new MoreLikeThisHandlerParameters(new string[] { "id" })
                {
                    MatchInclude = true
                }));
            });
        }
Ejemplo n.º 2
0
        public void MoreLikeThisHandlerQuery()
        {
            const string qstring = "id:123";

            var connection = new MSolrConnection();

            connection.get += (url, param) => {
                Assert.AreEqual("/mlt", url);
                var expectedParams = new Dictionary <string, string> {
                    { "q", qstring },
                    { "rows", SolrQueryExecuter <TestDocumentWithUniqueKey> .ConstDefaultRows.ToString() },
                    { "mlt", "true" },
                    { "mlt.fl", "id" },
                    { "mlt.match.include", "true" },
                };
                CollectionAssert.AreEquivalent(expectedParams, param);
                return(EmbeddedResource.GetEmbeddedString(GetType(), "Resources.responseWithInterestingTermsDetails.xml"));
            };

            var querySerializer = new MSolrQuerySerializer();

            querySerializer.serialize &= x => x.Return(qstring);

            var mlthParser = new MSolrMoreLikeThisHandlerQueryResultsParser <TestDocumentWithUniqueKey>();

            mlthParser.parse += _ => new SolrMoreLikeThisHandlerResults <TestDocumentWithUniqueKey>();

            var executer = new SolrQueryExecuter <TestDocumentWithUniqueKey>(null, connection, querySerializer, null, mlthParser);
            var solr     = new SolrBasicServer <TestDocumentWithUniqueKey>(connection, executer, null, null, null, null, null, null);
            var r        = solr.MoreLikeThis(new SolrMoreLikeThisHandlerQuery(new SolrQuery(qstring)), new MoreLikeThisHandlerQueryOptions(new MoreLikeThisHandlerParameters(new[] { "id" })
            {
                MatchInclude = true
            }));

            Assert.AreEqual(1, connection.get.Calls);
        }
Ejemplo n.º 3
0
        public void MoreLikeThisHandlerQuery()
        {
            const string qstring = "id:123";

            var connection = new MSolrConnection();
            connection.get += (url, param) => {
                Assert.AreEqual("/mlt", url);
                var expectedParams = new Dictionary<string, string> {
                    {"q", qstring},
                    {"rows", SolrQueryExecuter<TestDocumentWithUniqueKey>.ConstDefaultRows.ToString() },
                    {"mlt", "true"},
                    {"mlt.fl", "id"},
                    {"mlt.match.include", "true"},
                };
                Assert.AreElementsEqualIgnoringOrder(expectedParams, param);
                return EmbeddedResource.GetEmbeddedString(GetType(), "Resources.responseWithInterestingTermsDetails.xml");
            };

            var querySerializer = new MSolrQuerySerializer();
            querySerializer.serialize &= x => x.Return(qstring);

            var mlthParser = new MSolrMoreLikeThisHandlerQueryResultsParser<TestDocumentWithUniqueKey>();
            mlthParser.parse += _ => new SolrMoreLikeThisHandlerResults<TestDocumentWithUniqueKey>();

            var executer = new SolrQueryExecuter<TestDocumentWithUniqueKey>(null, connection, querySerializer, null, mlthParser);
            var solr = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, executer, null, null, null, null, null, null);
            var r = solr.MoreLikeThis(new SolrMoreLikeThisHandlerQuery(new SolrQuery(qstring)), new MoreLikeThisHandlerQueryOptions(new MoreLikeThisHandlerParameters(new[] { "id" }) { MatchInclude = true }));
            Assert.AreEqual(1, connection.get.Calls);
        }
Ejemplo n.º 4
0
        public void MoreLikeThisHandlerQuery()
        {
            const string qstring = "id:123";

            RhinoMocks.Logger = new Rhino.Mocks.Impl.TextWriterExpectationLogger(Console.Out);

            var mocks = new MockRepository();
            var query = new Dictionary<string, string>();
            query["q"] = qstring;

            var connection = mocks.StrictMock<ISolrConnection>();
            var docSerializer = mocks.StrictMock<ISolrDocumentSerializer<TestDocumentWithUniqueKey>>();
            var querySerializer = mocks.StrictMock<ISolrQuerySerializer>();
            var mlthParser = mocks.StrictMock<ISolrMoreLikeThisHandlerQueryResultsParser<TestDocumentWithUniqueKey>>();

            With.Mocks(mocks)
                .Expecting(() =>
                {
                    Expect.On(querySerializer)
                        .Call(querySerializer.Serialize(null))
                        .IgnoreArguments()
                        .Return(qstring);
                    Expect.On(connection)
                        .Call(connection.Get(null, null))
                        .IgnoreArguments()
                        .Return(EmbeddedResource.GetEmbeddedString(GetType(), "Resources.responseWithInterestingTermsDetails.xml"));
                    Expect.On(mlthParser)
                        .Call(mlthParser.Parse(null))
                        .IgnoreArguments()
                        .Return(new SolrMoreLikeThisHandlerResults<TestDocumentWithUniqueKey>());
                })
                .Verify(() =>
                {
                    var executer = new SolrQueryExecuter<TestDocumentWithUniqueKey>(null, connection, querySerializer, null, mlthParser);
                    var solr = new SolrBasicServer<TestDocumentWithUniqueKey>(connection, executer, docSerializer, null, null, null, null, null);
                    var r = solr.MoreLikeThis(new SolrMoreLikeThisHandlerQuery(new SolrQuery(qstring)), new MoreLikeThisHandlerQueryOptions(new MoreLikeThisHandlerParameters( new string[] { "id" }) { MatchInclude = true }));
                });
        }