Пример #1
0
        public void GetDocumentThrowsWhenRequestIsMalformed()
        {
            Run(() =>
            {
                SearchIndexClient client = Data.GetSearchIndexClient();

                var indexedDoc =
                    new Hotel()
                {
                    HotelId     = "3",
                    BaseRate    = 279.99,
                    Description = "Surprisingly expensive"
                };

                var batch = IndexBatch.Upload(new[] { indexedDoc });
                client.Documents.Index(batch);

                string[] selectedFields = new[] { "hotelId", "ThisFieldDoesNotExist" };

                SearchAssert.ThrowsCloudException(
                    () => client.Documents.Get("3", selectedFields),
                    HttpStatusCode.BadRequest,
                    "Invalid expression: Could not find a property named 'ThisFieldDoesNotExist' on type 'search.document'.");
            });
        }
Пример #2
0
 public void GetIndexerThrowsOnNotFound()
 {
     Run(() =>
     {
         SearchServiceClient searchClient = Data.GetSearchServiceClient();
         SearchAssert.ThrowsCloudException(() => searchClient.Indexers.Get("thisindexerdoesnotexist"), HttpStatusCode.NotFound);
     });
 }
Пример #3
0
 public void GetDocumentThrowsWhenDocumentNotFound()
 {
     Run(() =>
     {
         SearchIndexClient client = Data.GetSearchIndexClient();
         SearchAssert.ThrowsCloudException(() => client.Documents.Get("ThisDocumentDoesNotExist"), HttpStatusCode.NotFound);
     });
 }
        protected void TestSuggestThrowsWhenGivenBadSuggesterName()
        {
            SearchIndexClient client = GetClient();

            SearchAssert.ThrowsCloudException(
                () => client.Documents.Suggest("hotel", "Suggester does not exist", new SuggestParameters()),
                HttpStatusCode.BadRequest,
                "The specified suggester name 'Suggester does not exist' does not exist in this index definition.");
        }
Пример #5
0
        protected void TestAutocompleteThrowsWhenRequestIsMalformed()
        {
            SearchIndexClient client = GetClientForQuery();

            SearchAssert.ThrowsCloudException(
                () => client.Documents.Autocomplete("very po", string.Empty),
                HttpStatusCode.BadRequest,
                "Cannot find fields enabled for suggestions. Please provide a value for 'suggesterName' in the query.\r\nParameter name: suggestions");
        }
Пример #6
0
        public void GetDataSourceThrowsOnNotFound()
        {
            Run(() =>
            {
                SearchServiceClient searchClient = Data.GetSearchServiceClient();

                SearchAssert.ThrowsCloudException(
                    () => searchClient.DataSources.Get("thisdatasourcedoesnotexist"),
                    HttpStatusCode.NotFound);
            });
        }
Пример #7
0
        public void GetSynonymMapThrowsOnNotFound()
        {
            Run(() =>
            {
                SearchServiceClient searchClient = Data.GetSearchServiceClient();

                SearchAssert.ThrowsCloudException(
                    () => searchClient.SynonymMaps.Get("thisSynonymMapdoesnotexist"),
                    HttpStatusCode.NotFound);
            });
        }
Пример #8
0
        protected void TestAutcompleteThrowsWhenGivenBadSuggesterName()
        {
            SearchIndexClient client   = GetClientForQuery();
            var autocompleteParameters = new AutocompleteParameters()
            {
                AutocompleteMode = AutocompleteMode.OneTerm
            };

            SearchAssert.ThrowsCloudException(
                () => client.Documents.Autocomplete("very po", "Invalid suggester", autocompleteParameters),
                HttpStatusCode.BadRequest,
                "The specified suggester name 'Invalid suggester' does not exist in this index definition.\r\nParameter name: name");
        }
Пример #9
0
        protected void TestSearchThrowsWhenRequestIsMalformed()
        {
            SearchIndexClient client = GetClient();

            var invalidParameters = new SearchParameters()
            {
                Filter = "This is not a valid filter."
            };

            SearchAssert.ThrowsCloudException(
                () => client.Documents.Search("*", invalidParameters),
                HttpStatusCode.BadRequest,
                "Invalid expression: Syntax error at position 7 in 'This is not a valid filter.'");
        }
        internal static void CreateOrUpdateIfNotExistsFailsOnExistingResource <T>(
            Func <T, SearchRequestOptions, AccessCondition, T> createOrUpdateFunc,
            Func <T> newResourceDefinition,
            Func <T, T> mutateResourceDefinition)
            where T : IResourceWithETag
        {
            Func <T, AccessCondition, T> createOrUpdate = (a, b) => createOrUpdateFunc(a, null, b);
            var createdResource = createOrUpdate(newResourceDefinition(), AccessCondition.GenerateEmptyCondition());
            var mutatedResource = mutateResourceDefinition(createdResource);

            SearchAssert.ThrowsCloudException(
                () => createOrUpdate(mutatedResource, AccessCondition.GenerateIfNotExistsCondition()),
                e => e.IsAccessConditionFailed());
        }
Пример #11
0
        protected void TestSearchThrowsWhenSpecialCharInRegexIsUnescaped()
        {
            SearchIndexClient client = GetClient();

            var searchParameters = new SearchParameters()
            {
                QueryType = QueryType.Full
            };

            SearchAssert.ThrowsCloudException(
                () => client.Documents.Search(@"/.*/.*/", searchParameters),
                HttpStatusCode.BadRequest,
                "Failed to parse query string at line 1, column 8.");
        }
Пример #12
0
        public void IndexWithInvalidDocumentThrowsException()
        {
            Run(() =>
            {
                SearchIndexClient client = Data.GetSearchIndexClient();

                var batch = IndexBatch.Upload(new[] { new Document() });

                SearchAssert.ThrowsCloudException(
                    () => client.Documents.Index(batch),
                    HttpStatusCode.BadRequest,
                    "The request is invalid. Details: actions : 0: Document key cannot be missing or empty.");
            });
        }
        protected void TestSuggestThrowsWhenRequestIsMalformed()
        {
            SearchIndexClient client = GetClient();

            var invalidParameters = new SuggestParameters()
            {
                OrderBy = new[] { "This is not a valid orderby." }
            };

            SearchAssert.ThrowsCloudException(
                () => client.Documents.Suggest("hotel", "sg", invalidParameters),
                HttpStatusCode.BadRequest,
                "Invalid expression: Syntax error at position 7 in 'This is not a valid orderby.'");
        }
Пример #14
0
        public void CreateDataSourceFailsWithUsefulMessageOnUserError()
        {
            Run(() =>
            {
                SearchServiceClient searchClient = Data.GetSearchServiceClient();

                DataSource dataSource = CreateTestDataSource();
                dataSource.Type       = "thistypedoesnotexist";

                SearchAssert.ThrowsCloudException(
                    () => searchClient.DataSources.Create(dataSource),
                    HttpStatusCode.BadRequest,
                    "Data source type 'thistypedoesnotexist' is not supported");
            });
        }
Пример #15
0
        public void CreateSynonymMapFailsWithUsefulMessageOnUserError()
        {
            Run(() =>
            {
                SearchServiceClient searchClient = Data.GetSearchServiceClient();

                SynonymMap synonymMap = CreateTestSynonymMap();
                synonymMap.Synonyms   = "a => b => c"; // invalid

                SearchAssert.ThrowsCloudException(
                    () => searchClient.SynonymMaps.Create(synonymMap),
                    HttpStatusCode.BadRequest,
                    "Syntax error in line 1: 'a => b => c'. Only one explicit mapping (=>) can be specified in a synonym rule.");
            });
        }
        internal static void DeleteIfExistsWorksOnlyWhenResourceExists <T>(
            Action <string, SearchRequestOptions, AccessCondition> deleteAction,
            Func <T> createResource,
            string resourceName)
            where T : IResourceWithETag
        {
            Action <string, AccessCondition> delete = (a, b) => deleteAction(a, null, b);

            createResource();

            delete(resourceName, AccessCondition.GenerateIfExistsCondition());
            SearchAssert.ThrowsCloudException(
                () => delete(resourceName, AccessCondition.GenerateIfExistsCondition()),
                e => e.IsAccessConditionFailed());
        }
        internal static void UpdateIfExistsFailsOnNoResource <T>(
            Func <T, SearchRequestOptions, AccessCondition, T> createOrUpdateFunc,
            Func <T> newResourceDefinition)
            where T : IResourceWithETag
        {
            Func <T, AccessCondition, T> createOrUpdate = (a, b) => createOrUpdateFunc(a, null, b);
            var resource = newResourceDefinition();

            SearchAssert.ThrowsCloudException(
                () => createOrUpdate(resource, AccessCondition.GenerateIfExistsCondition()),
                e => e.IsAccessConditionFailed());

            // The resource should never have been created on the server, and thus it should not have an ETag
            Assert.Null(resource.ETag);
        }
Пример #18
0
        public void CreateIndexerFailsWithUsefulMessageOnUserError()
        {
            Run(() =>
            {
                SearchServiceClient searchClient = Data.GetSearchServiceClient();

                Indexer indexer        = Data.CreateTestIndexer();
                indexer.DataSourceName = "thisdatasourcedoesnotexist";

                SearchAssert.ThrowsCloudException(
                    () => searchClient.Indexers.Create(indexer),
                    HttpStatusCode.BadRequest,
                    "This indexer refers to a data source 'thisdatasourcedoesnotexist' that doesn't exist");
            });
        }
        internal static void DeleteIfNotChangedWorksOnlyOnCurrentResource <T>(
            Action <string, SearchRequestOptions, AccessCondition> deleteAction,
            Func <T> createResource,
            Func <T, T> updateResource,
            string resourceName)
            where T : IResourceWithETag
        {
            Action <string, AccessCondition> delete = (a, b) => deleteAction(a, null, b);
            var staleResource   = createResource();
            var currentResource = updateResource(staleResource);

            SearchAssert.ThrowsCloudException(
                () => delete(resourceName, AccessCondition.IfNotChanged(staleResource)),
                e => e.IsAccessConditionFailed());
            delete(resourceName, AccessCondition.IfNotChanged(currentResource));
        }
        public void AddingCustomAnalyzerThrowsCloudExceptionByDefault()
        {
            Run(() =>
            {
                SearchServiceClient client = Data.GetSearchServiceClient();

                Index index     = CreateTestIndex();
                index.Analyzers = new List <Analyzer>()
                {
                    new StopAnalyzer("a1")
                };

                client.Indexes.Create(index);

                index.Analyzers.Add(new StopAnalyzer("a2"));

                SearchAssert.ThrowsCloudException(() => client.Indexes.CreateOrUpdate(index), HttpStatusCode.BadRequest);
            });
        }
        internal static void UpdateIfNotChangedFailsWhenResourceChanged <T>(
            Func <T, SearchRequestOptions, AccessCondition, T> createOrUpdateFunc,
            Func <T> newResourceDefinition,
            Func <T, T> mutateResourceDefinition)
            where T : IResourceWithETag
        {
            Func <T, AccessCondition, T> createOrUpdate = (a, b) => createOrUpdateFunc(a, null, b);
            var createdResource = createOrUpdate(newResourceDefinition(), AccessCondition.GenerateEmptyCondition());
            var mutatedResource = mutateResourceDefinition(createdResource);
            var updatedResource = createOrUpdate(mutatedResource, AccessCondition.GenerateEmptyCondition());

            SearchAssert.ThrowsCloudException(
                () => createOrUpdate(updatedResource, AccessCondition.IfNotChanged(createdResource)),
                e => e.IsAccessConditionFailed());

            Assert.NotEmpty(createdResource.ETag);
            Assert.NotEmpty(updatedResource.ETag);
            Assert.NotEqual(createdResource.ETag, updatedResource.ETag);
        }
Пример #22
0
        public void CreateIndexFailsWithUsefulMessageOnUserError()
        {
            Run(() =>
            {
                SearchServiceClient searchClient = Data.GetSearchServiceClient();

                Index index           = CreateTestIndex();
                index.Fields[0].IsKey = false;

                const string ExpectedMessageFormat =
                    "The request is invalid. Details: index : Found 0 key fields in index '{0}'. " +
                    "Each index must have exactly one key field.";

                SearchAssert.ThrowsCloudException(
                    () => searchClient.Indexes.Create(index),
                    HttpStatusCode.BadRequest,
                    String.Format(ExpectedMessageFormat, index.Name));
            });
        }