public async Task Query_WhenInvalidIndexName_ReturnsErrorCountOfOne()
        {
            ConfigContextBase.SearchUris.Add(new FailureCountingUri("http://10.141.151.101:8091/"));
            var fakeMessageHandler = new FakeMessageHandler
            {
                StatusCode = HttpStatusCode.Forbidden,
                Content    = new StringContent("rest_auth: preparePerm, err: index not found ")
            };

            var client   = new SearchClient(new HttpClient(fakeMessageHandler), new SearchDataMapper());
            var response = await client.QueryAsync(new SearchQuery
            {
                Index = "indexdoesnotexist",
                Query = new MatchQuery("foo")
            });

            Assert.AreEqual(1, response.Metrics.ErrorCount);
        }
        public async Task Query_WhenInvalidUri_MaxScoreIsZero()
        {
            ConfigContextBase.SearchUris.Add(new FailureCountingUri("http://10.141.151.101:8091/"));
            var fakeMessageHandler = new FakeMessageHandler
            {
                StatusCode = HttpStatusCode.NotFound,
                Content    = new StringContent("Requested resource not found. ")
            };

            var client   = new SearchClient(new HttpClient(fakeMessageHandler), new SearchDataMapper());
            var response = await client.QueryAsync(new SearchQuery
            {
                Index = "indexdoesnotexist",
                Query = new MatchQuery("foo")
            });

            Assert.AreEqual(0, response.Metrics.MaxScore);
        }
        public async Task Query_WhenInvalidUri_Returns404()
        {
            ConfigContextBase.SearchUris.Add(new FailureCountingUri("http://10.141.151.101:8091/"));
            var fakeMessageHandler = new FakeMessageHandler
            {
                StatusCode = HttpStatusCode.NotFound,
                Content    = new StringContent("Requested resource not found. ")
            };

            var client   = new SearchClient(new HttpClient(fakeMessageHandler), new SearchDataMapper());
            var response = await client.QueryAsync(new SearchQuery
            {
                Index = "indexdoesnotexist",
                Query = new MatchQuery("foo")
            });

            Assert.IsTrue(response.Exception.Message.Contains("404"));
        }
        public async Task QueryAsync_WhenInvalidIndexName_Returns403()
        {
            ConfigContextBase.SearchUris.Add(new FailureCountingUri("http://10.141.151.101:8091/"));
            var fakeMessageHandler = new FakeMessageHandler
            {
                StatusCode = HttpStatusCode.Forbidden,
                Content    = new StringContent("rest_auth: preparePerm, err: index not found ")
            };

            var client   = new SearchClient(new HttpClient(fakeMessageHandler), new SearchDataMapper(), new ClientConfiguration());
            var response = await client.QueryAsync(new SearchQuery
            {
                Index = "indexdoesnotexist",
                Query = new MatchQuery("foo")
            });

            Assert.IsTrue(response.Exception.Message.Contains("403"));
        }
        public async Task Query_WhenInvalidIndexName_Returns403()
        {
            var context = ContextFactory.GetCouchbaseContext();

            context.SearchUris.Add(new FailureCountingUri("http://10.141.151.101:8091/"));
            var fakeMessageHandler = new FakeMessageHandler
            {
                StatusCode = HttpStatusCode.Forbidden,
                Content    = new StringContent("rest_auth: preparePerm, err: index not found ")
            };

            var client   = new SearchClient(new HttpClient(fakeMessageHandler), new SearchDataMapper(), context);
            var response = await client.QueryAsync(new SearchQuery
            {
                Index = "indexdoesnotexist",
                Query = new MatchQuery("foo")
            });

            Assert.IsTrue(response.Errors.First().Contains("rest_auth: preparePerm, err: index not found"));
        }
        public async Task Query_WhenInvalidUri_FacetsIsEmpty()
        {
            var context = ContextFactory.GetCouchbaseContext();

            context.SearchUris.Add(new FailureCountingUri("http://10.141.151.101:8091/"));
            var fakeMessageHandler = new FakeMessageHandler
            {
                StatusCode = HttpStatusCode.NotFound,
                Content    = new StringContent("Requested resource not found. ")
            };

            var client   = new SearchClient(new HttpClient(fakeMessageHandler), new SearchDataMapper(), context);
            var response = await client.QueryAsync(new SearchQuery
            {
                Index = "indexdoesnotexist",
                Query = new MatchQuery("foo")
            });

            Assert.IsEmpty(response.Facets);
        }
        public async Task Query_WhenInvalidUri_ReturnsErrorMessage()
        {
            var context = ContextFactory.GetCouchbaseContext();

            context.SearchUris.Add(new FailureCountingUri("http://10.141.151.102:8091/"));//assume invalid uri
            var fakeMessageHandler = new FakeMessageHandler
            {
                StatusCode = HttpStatusCode.NotFound,
                Content    = new StringContent("Requested resource not found. ")
            };

            var client   = new SearchClient(new HttpClient(fakeMessageHandler), new SearchDataMapper(), context);
            var response = await client.QueryAsync(new SearchQuery
            {
                Index = "indexist",
                Query = new MatchQuery("foo")
            });

            Assert.IsTrue(response.Errors.First().Contains("Requested resource not found."));
        }
        public async Task Query_WhenInvalidUri_ReturnsErrorCountOfOne()
        {
            ConfigContextBase.SearchUris.Add(new FailureCountingUri("http://10.141.151.101:8091/"));
            var fakeMessageHandler = new FakeMessageHandler
            {
                StatusCode = HttpStatusCode.NotFound,
                Content    = new StringContent("Requested resource not found. ")
            };

            var client = new FakeSearchClient(new BucketConfig(), new ClientConfiguration(), new SearchDataMapper())
            {
                HttpClient = new HttpClient(fakeMessageHandler),
            };

            var response = await client.QueryAsync(new SearchQuery
            {
                Index = "indexdoesnotist",
                Query = new MatchQuery("foo")
            });

            Assert.AreEqual(1, response.ErrorCount);
        }