单元测试中奇怪的NEST客户端问题

时间:2015-12-24 11:38:51

标签: elasticsearch nest

我有一个我在控制器中实例化的客户端:

    public ElasticConnector()
    {
        var node = new Uri(String.Format("http://{0}:{1}", ConfigurationManager.AppSettings["ElasticHost"], ConfigurationManager.AppSettings["ElasticPort"]));

        var settings = new ConnectionSettings(
            node
        ).ExposeRawResponse();

        Client = new ElasticClient(settings);
    }

哪个工作正常,我可以进行查询,但是当在单元测试中实例化同一个类并运行相同的控制器时,客户端会一直返回:

 operation has timed out

单元测试(MSpec):

 public class SearchControllerSpec
    {
        public class setup_controller
        {
            public static SearchController controller;

            public static IHttpActionResult results;

            Establish context = () =>
            {
                var client = new ElasticConnector();
                //ElasticTestInstance.SetupTestInstance(client);

                controller = new SearchController(client);
            };
        }

        public class when_searching_with_a_hyphenated_term : setup_controller
        {
            Because of = () => results = controller.GetResults("anti-emetic");

            It should_return_OK = () => results.ShouldBeOfExactType<OkNegotiatedContentResult<string>>();

}

知道发生了什么事吗?

0 个答案:

没有答案