Пример #1
0
        public void CannotCreateOrUpdateFreeServiceWithIdentity()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();

                string serviceName    = SearchTestUtilities.GenerateServiceName();
                SearchService service = DefineServiceWithSku(SkuName.Free);
                service.Identity      = new Identity(IdentityType.SystemAssigned);

                CloudException e = Assert.Throws <CloudException>(() =>
                                                                  searchMgmt.Services.CreateOrUpdate(Data.ResourceGroupName, serviceName, service));

                Assert.Equal("Resource identity is not supported for the selected SKU", e.Message);

                // retry create without identity
                service.Identity = null;
                service          = searchMgmt.Services.CreateOrUpdate(Data.ResourceGroupName, serviceName, service);
                Assert.NotNull(service);
                Assert.Null(service.Identity);

                // try update the created service by defining an identity
                service.Identity = new Identity();
                e = Assert.Throws <CloudException>(() =>
                                                   searchMgmt.Services.Update(Data.ResourceGroupName, service.Name, service));

                Assert.Equal("Resource identity is not supported for the selected SKU", e.Message);
                searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name);
            });
        }
Пример #2
0
 public static void Run()
 {
     _client = new SearchManagementClient();
     //CreateIndex();
     //CreateDataSource();
     CreateIndexer();
 }
Пример #3
0
 public static void Run()
 {
     _client = new SearchManagementClient();
     _client.DeleteIndex(SearchConfiguration.IndexName);
     _client.DeleteDataSource(SearchConfiguration.DatasourceName);
     _client.DeleteIndexer(SearchConfiguration.IndexerName);
 }
Пример #4
0
        public void CanAddAndRemoveServiceIdentity()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();
                string serviceName    = SearchTestUtilities.GenerateServiceName();
                SearchService service = DefineServiceWithSku(SkuName.Basic);
                service.Identity      = null;
                service = searchMgmt.Services.CreateOrUpdate(Data.ResourceGroupName, serviceName, service);
                Assert.NotNull(service);
                Assert.Equal(IdentityType.None, service.Identity?.Type ?? IdentityType.None);

                // assign an identity of type 'SystemAssigned'
                service.Identity = new Identity(IdentityType.SystemAssigned);
                service          = searchMgmt.Services.Update(Data.ResourceGroupName, service.Name, service);
                Assert.NotNull(service);
                Assert.NotNull(service.Identity);
                Assert.Equal(IdentityType.SystemAssigned, service.Identity.Type);

                string principalId = string.IsNullOrWhiteSpace(service.Identity.PrincipalId) ? null : service.Identity.PrincipalId;
                Assert.NotNull(principalId);

                string tenantId = string.IsNullOrWhiteSpace(service.Identity.TenantId) ? null : service.Identity.TenantId;
                Assert.NotNull(tenantId);

                // remove the identity by setting it's type to 'None'
                service.Identity.Type = IdentityType.None;
                service = searchMgmt.Services.Update(Data.ResourceGroupName, service.Name, service);
                Assert.NotNull(service);
                Assert.Equal(IdentityType.None, service.Identity?.Type ?? IdentityType.None);

                searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name);
            });
        }
Пример #5
0
        private void SetupManagementClients(MockContext context)
        {
            ResourceManagementClient = GetResourceManagementClient(context);
            SearchClient             = GetAzureSearchManagementClient(context);

            _helper.SetupManagementClients(ResourceManagementClient, SearchClient);
        }
        public void CanCreateAndDeleteQueryKeys()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();

                var queryKeys = searchMgmt.QueryKeys.ListBySearchService(Data.ResourceGroupName, Data.SearchServiceName);

                AssertIsDefaultKey(queryKeys.Single());

                QueryKey newKey = searchMgmt.QueryKeys.Create(Data.ResourceGroupName, Data.SearchServiceName, "my key");

                AssertIsValidKey(newKey, "my key");

                queryKeys = searchMgmt.QueryKeys.ListBySearchService(Data.ResourceGroupName, Data.SearchServiceName);

                Assert.Equal(2, queryKeys.Count());
                AssertIsDefaultKey(queryKeys.First());

                Assert.Equal(newKey.Name, queryKeys.ElementAt(1).Name);
                Assert.Equal(newKey.Key, queryKeys.ElementAt(1).Key);

                searchMgmt.QueryKeys.Delete(Data.ResourceGroupName, Data.SearchServiceName, newKey.Key);

                queryKeys = searchMgmt.QueryKeys.ListBySearchService(Data.ResourceGroupName, Data.SearchServiceName);

                AssertIsDefaultKey(queryKeys.Single());
            });
        }
        public SearchServiceFixture()
        {
            SearchManagementClient client =
                TestBase.GetServiceClient <SearchManagementClient>(new CSMTestEnvironmentFactory());

            SearchServiceName = SearchTestUtilities.GenerateServiceName();

            var createServiceParameters =
                new SearchServiceCreateOrUpdateParameters()
            {
                Location   = Location,
                Properties = new SearchServiceProperties()
                {
                    Sku = new Sku(SkuType.Free)
                }
            };

            SearchServiceCreateOrUpdateResponse createServiceResponse =
                client.Services.CreateOrUpdate(ResourceGroupName, SearchServiceName, createServiceParameters);

            Assert.Equal(HttpStatusCode.Created, createServiceResponse.StatusCode);

            AdminKeyResponse adminKeyResponse = client.AdminKeys.List(ResourceGroupName, SearchServiceName);

            Assert.Equal(HttpStatusCode.OK, adminKeyResponse.StatusCode);

            PrimaryApiKey = adminKeyResponse.PrimaryKey;

            ListQueryKeysResponse queryKeyResponse = client.QueryKeys.List(ResourceGroupName, SearchServiceName);

            Assert.Equal(HttpStatusCode.OK, queryKeyResponse.StatusCode);
            Assert.Equal(1, queryKeyResponse.QueryKeys.Count);

            QueryApiKey = queryKeyResponse.QueryKeys[0].Key;
        }
        public void CanListSupportedGroupIds()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();
                SearchService service             = CreateServiceForSku(searchMgmt, SkuName.Basic);

                WaitForProvisioningToComplete(searchMgmt, service);

                IList <PrivateLinkResource> resources =
                    searchMgmt.PrivateLinkResources.ListSupported(Data.ResourceGroupName, service.Name).ToList();

                Assert.NotNull(resources);

                Assert.Equal(1, resources.Count);

                PrivateLinkResource resource = resources.Single();

                Assert.NotNull(resource.Id);
                Assert.NotNull(resource.Properties.GroupId);
                Assert.NotEmpty(resource.Properties.RequiredMembers);
                Assert.NotEmpty(resource.Properties.RequiredZoneNames);
                Assert.NotEmpty(resource.Properties.ShareablePrivateLinkResourceTypes);

                searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name);
            });
        }
 public void CanCreateServiceInPrivateMode()
 {
     Run(() =>
     {
         SearchManagementClient searchMgmt = GetSearchManagementClient();
         CreateServiceForSkuWithDefinitionTemplate(searchMgmt, SkuName.Basic, DefineServiceWithSkuInPrivateMode);
     });
 }
        public ManagementClient(string resourceGroupName, string searchServiceName, string subscriptionId)
        {
            this.resourceGroupName = resourceGroupName;
            this.searchServiceName = searchServiceName;

            var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud);

            _managementClient = new SearchManagementClient(credentials);
            _managementClient.SubscriptionId = subscriptionId;
        }
Пример #11
0
        private void TestCreateService(SearchService service)
        {
            SearchManagementClient searchMgmt = GetSearchManagementClient();
            string serviceName = SearchTestUtilities.GenerateServiceName();

            service = searchMgmt.Services.BeginCreateOrUpdate(Data.ResourceGroupName, serviceName, service);
            service = WaitForProvisioningToComplete(searchMgmt, service);

            searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name);
        }
 public void DeleteQueryKeyIsIdempotent()
 {
     Run(() =>
     {
         SearchManagementClient searchMgmt = GetSearchManagementClient();
         QueryKey newKey = searchMgmt.QueryKeys.Create(Data.ResourceGroupName, Data.SearchServiceName, "my key");
         searchMgmt.QueryKeys.Delete(Data.ResourceGroupName, Data.SearchServiceName, newKey.Key);
         searchMgmt.QueryKeys.Delete(Data.ResourceGroupName, Data.SearchServiceName, newKey.Key);
     });
 }
Пример #13
0
        private string EnsureSearchService(SearchManagementClient client)
        {
            // Ensuring a search service involves creating it, and then waiting until its DNS resolves. The approach
            // we take depends on what kind of test run this is. If it's a Record or Playback run, we need determinism
            // since the mock server has no clue how many times we retried DNS lookup in the original test run. In
            // this case, we can't just delete and re-create the search service if DNS doesn't resolve in a timely
            // manner. However, we do fail fast in the interests of speeding up interactive dev cycles.
            //
            // If we're in None mode (i.e. -- no mock recording or playback), we assume we're running automated tests
            // in batch. In this case, non-determinism is not a problem (because mocks aren't involved), and
            // reliability is paramount. For this reason, we retry the entire sequence several times, deleting and
            // trying to re-create the service each time.
            int maxAttempts = (HttpMockServer.Mode == HttpRecorderMode.None) ? 10 : 1;

            for (int attempt = 0; attempt < maxAttempts; attempt++)
            {
                string searchServiceName = SearchTestUtilities.GenerateServiceName();

                var createServiceParameters =
                    new SearchServiceCreateOrUpdateParameters()
                {
                    Location   = Location,
                    Properties = new SearchServiceProperties()
                    {
                        Sku = new Sku()
                        {
                            Name = SkuType.Free
                        }
                    }
                };

                client.Services.CreateOrUpdate(ResourceGroupName, searchServiceName, createServiceParameters);

                // In the common case, DNS propagation happens in less than 15 seconds. In the uncommon case, it can
                // take many minutes. The timeout we use depends on the mock mode. If we're in Playback, the delay is
                // irrelevant. If we're in Record mode, we can't delete and re-create the service, so we get more
                // reliable results if we wait longer. In "None" mode, we can delete and re-create, which is often
                // faster than waiting a long time for DNS propagation. In that case, rather than force all tests to
                // wait several minutes, we fail fast here.
                TimeSpan maxDelay =
                    (HttpMockServer.Mode == HttpRecorderMode.Record) ?
                    TimeSpan.FromMinutes(1) : TimeSpan.FromSeconds(15);

                if (SearchTestUtilities.WaitForSearchServiceDns(searchServiceName, maxDelay))
                {
                    return(searchServiceName);
                }

                // If the service DNS isn't resolvable in a timely manner, delete it and try to create another one.
                // We need to delete it since there can be only one free service per subscription.
                client.Services.Delete(ResourceGroupName, searchServiceName);
            }

            throw new InvalidOperationException("Failed to provision a search service in a timely manner.");
        }
Пример #14
0
        public void CanUpdateTags()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();
                SearchService service             = CreateFreeService(searchMgmt);

                var testTags =
                    new Dictionary <string, string>()
                {
                    ["testTag"]    = "testValue",
                    ["anotherTag"] = "anotherValue"
                };

                // Add some tags.
                service =
                    searchMgmt.Services.Update(
                        Data.ResourceGroupName,
                        service.Name,
                        new SearchService()
                {
                    Tags = testTags
                });

                Assert.Equal(testTags, service.Tags);

                // Modify a tag.
                testTags["anotherTag"] = "differentValue";

                service =
                    searchMgmt.Services.Update(
                        Data.ResourceGroupName,
                        service.Name,
                        new SearchService()
                {
                    Tags = testTags
                });

                Assert.Equal(testTags, service.Tags);

                // Remove the second tag.
                testTags.Remove("anotherTag");

                service =
                    searchMgmt.Services.Update(
                        Data.ResourceGroupName,
                        service.Name,
                        new SearchService()
                {
                    Tags = testTags
                });

                Assert.Equal(testTags, service.Tags);
            });
        }
Пример #15
0
        public void DeleteServiceIsIdempotent()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();
                SearchService service             = CreateFreeService(searchMgmt);

                searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name);
                searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name);
            });
        }
Пример #16
0
        private SearchService CreateServiceForSku(SearchManagementClient searchMgmt, SkuName sku)
        {
            string serviceName = SearchTestUtilities.GenerateServiceName();

            SearchService service = DefineServiceWithSku(sku);

            service = searchMgmt.Services.BeginCreateOrUpdate(Data.ResourceGroupName, serviceName, service);
            Assert.NotNull(service);

            return(service);
        }
Пример #17
0
        public void UpdatingImmutablePropertiesThrowsCloudException()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();
                SearchService service             = CreateFreeService(searchMgmt);

                CloudException e =
                    Assert.Throws <CloudException>(() =>
                                                   searchMgmt.Services.Update(
                                                       Data.ResourceGroupName,
                                                       service.Name,
                                                       new SearchService()
                {
                    HostingMode = HostingMode.HighDensity
                }));

                Assert.Equal("Updating HostingMode of an existing search service is not allowed.", e.Message);

                // There is currently a validation bug in the Azure Search management API, so we can't
                // test for an exception yet. Instead, just make sure the location doesn't actually change.
                SearchService updatedService =
                    searchMgmt.Services.Update(
                        Data.ResourceGroupName,
                        service.Name,
                        new SearchService()
                {
                    Location = "East US"
                });                                                     // We run live tests in West US.

                Assert.Equal(service.Location, updatedService.Location);

                /*e =
                 *  Assert.Throws<CloudException>(() =>
                 *      searchMgmt.Services.Update(
                 *          Data.ResourceGroupName,
                 *          service.Name,
                 *          new SearchService() { Location = "East US" }));  // We run live tests in West US.
                 *
                 *  Assert.Equal("Updating Location of an existing search service is not allowed.", e.Message);*/

                e =
                    Assert.Throws <CloudException>(() =>
                                                   searchMgmt.Services.Update(
                                                       Data.ResourceGroupName,
                                                       service.Name,
                                                       new SearchService()
                {
                    Sku = new Sku(SkuName.Basic)
                }));

                Assert.Equal("Updating Sku of an existing search service is not allowed.", e.Message);
            });
        }
Пример #18
0
        public void CanCreateAndDeleteService()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();
                SearchService service             = CreateFreeService(searchMgmt);

                searchMgmt.Services.Delete(Data.ResourceGroupName, service.Name);

                Assert.Empty(searchMgmt.Services.ListByResourceGroup(Data.ResourceGroupName));
            });
        }
Пример #19
0
        public void CanCreateAndGetService()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();
                SearchService originalService     = CreateFreeService(searchMgmt);

                SearchService service = searchMgmt.Services.Get(Data.ResourceGroupName, originalService.Name);

                AssertServicesEqual(originalService, service);
            });
        }
Пример #20
0
        public void UpdateServiceWithInvalidNameGivesNotFound()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();

                CloudException e =
                    Assert.Throws <CloudException>(() =>
                                                   searchMgmt.Services.Update(Data.ResourceGroupName, "missing", new SearchService()));

                Assert.Equal(HttpStatusCode.NotFound, e.Response.StatusCode);
            });
        }
Пример #21
0
        public void CheckNameAvailabilitySucceedsOnNewName()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();

                CheckNameAvailabilityOutput result = searchMgmt.Services.CheckNameAvailability("newservice");

                Assert.Null(result.Message);
                Assert.Null(result.Reason);
                Assert.True(result.IsNameAvailable);
            });
        }
Пример #22
0
        public override void Cleanup()
        {
            // Normally we could just rely on resource group deletion to clean things up for us. However, resource
            // group deletion is asynchronous and can be slow, especially when we're running in test environments that
            // aren't 100% reliable. To avoid interfering with other tests by exhausting free service quota, we
            // eagerly delete the search service here.
            if (ResourceGroupName != null && SearchServiceName != null)
            {
                SearchManagementClient client = MockContext.GetServiceClient <SearchManagementClient>();
                client.Services.Delete(ResourceGroupName, SearchServiceName);
            }

            base.Cleanup();
        }
Пример #23
0
        public void CheckNameAvailabilityFailsOnInvalidName()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();

                CheckNameAvailabilityOutput result =
                    searchMgmt.Services.CheckNameAvailability(InvalidServiceName);

                Assert.False(string.IsNullOrEmpty(result.Message));
                Assert.Equal(UnavailableNameReason.Invalid, result.Reason);
                Assert.False(result.IsNameAvailable);
            });
        }
Пример #24
0
        public void CheckNameAvailabilityFailsOnUsedName()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();
                SearchService service             = CreateFreeService(searchMgmt);

                CheckNameAvailabilityOutput result = searchMgmt.Services.CheckNameAvailability(service.Name);

                Assert.Null(result.Message);
                Assert.Equal(UnavailableNameReason.AlreadyExists, result.Reason);
                Assert.False(result.IsNameAvailable);
            });
        }
        public void CanListServicesBySubscription()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();
                SearchService service1            = CreateFreeService(searchMgmt);
                SearchService service2            = CreateFreeService(searchMgmt);

                var services = searchMgmt.Services.ListBySubscription();
                Assert.NotNull(services);
                Assert.Equal(2, services.Count());
                Assert.Contains(service1.Name, services.Select(s => s.Name));
                Assert.Contains(service2.Name, services.Select(s => s.Name));
            });
        }
        public override void Cleanup()
        {
            if (ResourceGroupName != null && StorageAccountName != null)
            {
                StorageManagementClient client = MockContext.GetServiceClient <StorageManagementClient>();
                client.StorageAccounts.Delete(ResourceGroupName, StorageAccountName);
            }

            if (ResourceGroupName != null && ServiceName != null)
            {
                SearchManagementClient searchMgmt = MockContext.GetServiceClient <SearchManagementClient>();
                searchMgmt.Services.Delete(ResourceGroupName, ServiceName);
            }

            base.Cleanup();
        }
Пример #27
0
        public void CanListQueryKeys()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();

                ListQueryKeysResponse queryKeyResponse =
                    searchMgmt.QueryKeys.List(Data.ResourceGroupName, Data.SearchServiceName);

                Assert.Equal(HttpStatusCode.OK, queryKeyResponse.StatusCode);
                Assert.Equal(1, queryKeyResponse.QueryKeys.Count);
                Assert.Null(queryKeyResponse.QueryKeys[0].Name);   // Default key has no name.
                Assert.NotNull(queryKeyResponse.QueryKeys[0].Key);
                Assert.NotEmpty(queryKeyResponse.QueryKeys[0].Key);
            });
        }
Пример #28
0
        private SearchService WaitForProvisioningToComplete(
            SearchManagementClient searchMgmt,
            SearchService service)
        {
            while (service.ProvisioningState == ProvisioningState.Provisioning)
            {
                Assert.Equal(SearchServiceStatus.Provisioning, service.Status);

                SearchTestUtilities.WaitForServiceProvisioning();
                service = searchMgmt.Services.Get(Data.ResourceGroupName, service.Name);
            }

            Assert.Equal(ProvisioningState.Succeeded, service.ProvisioningState);
            Assert.Equal(SearchServiceStatus.Running, service.Status);
            return(service);
        }
        public void RequestIdIsReturnedInResponse()
        {
            Run(() =>
            {
                SearchManagementClient client = GetSearchManagementClient();

                // We need to use a constant GUID so that this test will still work in playback mode.
                var options = new SearchManagementRequestOptions(new Guid("c4cfce79-eb42-4e61-9909-84510c04706f"));

                var listResponse =
                    client.Services.ListByResourceGroupWithHttpMessagesAsync(Data.ResourceGroupName, searchManagementRequestOptions: options).Result;
                Assert.Equal(HttpStatusCode.OK, listResponse.Response.StatusCode);

                Assert.Equal(options.ClientRequestId.Value.ToString("D"), listResponse.RequestId);
            });
        }
Пример #30
0
        public void CanListQueryKeys()
        {
            Run(() =>
            {
                SearchManagementClient searchMgmt = GetSearchManagementClient();

                ListQueryKeysResult queryKeyResult =
                    searchMgmt.QueryKeys.List(Data.ResourceGroupName, Data.SearchServiceName);

                Assert.NotNull(queryKeyResult);
                Assert.Equal(1, queryKeyResult.Value.Count);
                Assert.Null(queryKeyResult.Value[0].Name);   // Default key has no name.
                Assert.NotNull(queryKeyResult.Value[0].Key);
                Assert.NotEmpty(queryKeyResult.Value[0].Key);
            });
        }