public void TestListSkus() { using (MockContext context = MockContext.Start(this.GetType())) { var computeClient = ComputeManagementTestUtilities.GetComputeManagementClient(context, new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }); IPage <ResourceSku> skus = computeClient.ResourceSkus.List(includeExtendedLocations: "true"); Assert.True(skus.Any(), "Assert that the array of skus has at least 1 member."); Assert.True(skus.Any(sku => sku.ResourceType == "availabilitySets"), "Assert that the sku list at least contains" + "one availability set."); Assert.True(skus.Any(sku => sku.ResourceType == "virtualMachines"), "Assert that the sku list at least contains" + "one virtual machine."); Assert.True(skus.Any(sku => sku.LocationInfo != null), "Assert that the sku list has non null location info in it."); //Removing below Assert because API now returns some skus without location. Get-AzComputeResourceSku | Where-Object { $_.LocationInfo.count -ne 1} //Assert.True(skus.All(sku => sku.LocationInfo.Count == 1), "There should be exactly one location info per entry."); Assert.True(skus.Any(sku => sku.LocationInfo[0].Location.Equals("westus", StringComparison.Ordinal)), "Assert that it has entry for one of the CRP regions (randomly picked)."); // EastUS2EUAP is one of the regions where UltraSSD is enabled, hence verifying that CRP and ARM are returning correct // properties related to UltraSSD in the SKUs API var vmSkusInEastUS2Euap = skus.Where( s => s.Locations[0].Equals("eastus2euap", StringComparison.OrdinalIgnoreCase) && s.ResourceType == "virtualMachines").ToList(); var ultraSSDSupportingSku = vmSkusInEastUS2Euap.First(s => s.Name == "Standard_B2s"); var nonUltraSSDSupportingSku = vmSkusInEastUS2Euap.First(s => s.Name == "Standard_A7"); Assert.NotNull(ultraSSDSupportingSku.LocationInfo); Assert.Equal(2, ultraSSDSupportingSku.LocationInfo.Count); Assert.NotNull(ultraSSDSupportingSku.LocationInfo[0].ZoneDetails); Assert.Equal(1, ultraSSDSupportingSku.LocationInfo[0].ZoneDetails.Count); Assert.NotNull(ultraSSDSupportingSku.LocationInfo[0].ZoneDetails[0].Name); Assert.NotNull(ultraSSDSupportingSku.LocationInfo[0].ZoneDetails[0].Capabilities); Assert.Equal(1, ultraSSDSupportingSku.LocationInfo[0].ZoneDetails[0].Capabilities.Count); Assert.Equal("UltraSSDAvailable", ultraSSDSupportingSku.LocationInfo[0].ZoneDetails[0].Capabilities[0].Name); Assert.Equal("True", ultraSSDSupportingSku.LocationInfo[0].ZoneDetails[0].Capabilities[0].Value); Assert.NotNull(nonUltraSSDSupportingSku.LocationInfo); // ZoneDetails should not be set for a SKU which does not support ultraSSD. This is because we do not have any // other zonal capability currently. //Assert.Null(nonUltraSSDSupportingSku.LocationInfo[0].ZoneDetails); Assert.Equal(0, nonUltraSSDSupportingSku.LocationInfo[0].ZoneDetails.Count); // Validate that extendedlocations are included for a supported sku Assert.NotEmpty(vmSkusInEastUS2Euap.Where(s => s.Name == "Standard_D4s_v3").First().LocationInfo.Where(info => info.ExtendedLocations != null)); // Validate that extendedlocations are not included for an unsupported sku Assert.Empty(vmSkusInEastUS2Euap.Where(s => s.Name == "Basic_A0").First().LocationInfo.Where(info => info.ExtendedLocations != null)); } }
private void ReplicateStreamingEndpointsPage(IPage <StreamingEndpoint> streamingEndpointsPage) { if (streamingEndpointsPage.Any()) { foreach (var streamingEndpoint in streamingEndpointsPage) { Helpers.WriteLine($"Copying streaming endpoint '{streamingEndpoint.Name}'...", 2); if (DestinationOperations.Get(DestinationAuth.ResourceGroup, DestinationAuth.AccountName, streamingEndpoint.Name) == null) { streamingEndpoint.Location = DestinationAuth.Location; DestinationOperations.Create(DestinationAuth.ResourceGroup, DestinationAuth.AccountName, streamingEndpoint.Name, streamingEndpoint); Helpers.WriteLine("Done", 3); } else { Helpers.WriteLine("Already exists", 3); } } } else { Helpers.WriteLine("No streaming endpoints to copy", 2); } }
private void ReplicateStreamingLocatorsPage(IPage <StreamingLocator> streamingLocatorsPage) { if (streamingLocatorsPage.Any()) { foreach (var streamingLocator in streamingLocatorsPage) { Helpers.WriteLine($"Copying streaming locator '{streamingLocator.Name}'...", 2); if (DestinationOperations.Get(DestinationAuth.ResourceGroup, DestinationAuth.AccountName, streamingLocator.Name) == null) { DestinationOperations.Create(DestinationAuth.ResourceGroup, DestinationAuth.AccountName, streamingLocator.Name, new StreamingLocator() { AssetName = streamingLocator.AssetName, StreamingPolicyName = streamingLocator.StreamingPolicyName, StartTime = streamingLocator.StartTime, EndTime = streamingLocator.EndTime, DefaultContentKeyPolicyName = streamingLocator.DefaultContentKeyPolicyName, ContentKeys = streamingLocator.ContentKeys.Count == 0 ? null : streamingLocator.ContentKeys, Filters = streamingLocator.Filters.Count == 0 ? null : streamingLocator.Filters }); Helpers.WriteLine("Done", 3); } else { Helpers.WriteLine($"Already exists", 3); } } } else { Helpers.WriteLine($"No streaming locators to replicate", 2); } }
public static async Task UploadTestApplicationPackageIfNotAlreadyUploadedAsync( string appPackageName, string applicationVersion, string accountName, string resourceGroupName) { using BatchManagementClient mgmtClient = IntegrationTestCommon.OpenBatchManagementClient(); IPage <Application> applicationSummaries = await mgmtClient.Application.ListAsync(resourceGroupName, accountName).ConfigureAwait(false); bool testPackageAlreadyUploaded = applicationSummaries.Any(a => string.Equals(appPackageName, a.Id, StringComparison.OrdinalIgnoreCase)); if (!testPackageAlreadyUploaded) { const string format = "zip"; var addResponse = await mgmtClient.ApplicationPackage.CreateAsync(resourceGroupName, accountName, appPackageName, applicationVersion) .ConfigureAwait(false); var storageUrl = addResponse.StorageUrl; await IntegrationTestCommon.UploadTestApplicationAsync(storageUrl).ConfigureAwait(false); await mgmtClient.ApplicationPackage.ActivateAsync( resourceGroupName, accountName, appPackageName, applicationVersion, format).ConfigureAwait(false); } }
public void FindAService() { var identity = new CloudIdentity { Username = "******", APIKey = "{api-key}" }; IIdentityProvider identityProvider = new CloudIdentityProvider(identity); var service = new ContentDeliveryNetworkService(identityProvider, "DFW"); IPage <Service> currentPage = service.ListServices(); Service myService; do { myService = currentPage.FirstOrDefault(x => x.Name == "MyService"); if (myService != null) { break; } currentPage = currentPage.GetNextPage(); } while (currentPage.Any()); if (myService == null) { Console.Error.WriteLine("Could not find MyService!"); return; } Console.WriteLine("MyService: {0}", myService.Status); }
private void ReplicateLiveOutputsPage(string liveEventName, IPage <LiveOutput> liveOutputsPage) { if (liveOutputsPage.Any()) { foreach (var liveOutput in liveOutputsPage) { Helpers.WriteLine($"Copying live output {liveOutput.Name}...", 4); string tempResult = ""; if (_destinationLiveOutputOperations.Get(DestinationAuth.ResourceGroup, DestinationAuth.AccountName, liveEventName, liveOutput.Name) == null) { _destinationLiveOutputOperations.Create(DestinationAuth.ResourceGroup, DestinationAuth.AccountName, liveEventName, liveOutput.Name, liveOutput); tempResult = "Done"; } else { tempResult = "Already exists"; } Helpers.WriteLine(tempResult, 5); } } else { Helpers.WriteLine("No live outputs", 4); } }
public void ListOperations() { using (MockContext context = MockContext.Start(this.GetType())) { var backupClient = context.GetServiceClient <RecoveryServicesBackupClient>(); IPage <ClientDiscoveryValueForSingleApi> operations = backupClient.Operations.List(); Assert.NotNull(operations); Assert.True(operations.Any()); } }
private async Task AddCollection(IPage <InnerResourceT> currentPage, PagedCollection <IFluentResourceT, InnerResourceT> pagedCollection, CancellationToken cancellationToken) { if (currentPage != null && currentPage.Any()) { pagedCollection.NextPageLink = currentPage.NextPageLink; var resources = await Task.WhenAll(currentPage.Select(async(inner) => await this.WrapModelAsyncDelegate(inner, cancellationToken))); ((List <IFluentResourceT>)pagedCollection.innerCollection).AddRange(resources); } }
public void TestListSkus() { using (MockContext context = MockContext.Start(this.GetType().FullName)) { var computeClient = ComputeManagementTestUtilities.GetComputeManagementClient(context, new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }); IPage <ResourceSku> skus = computeClient.ResourceSkus.List(); Assert.True(skus.Any(), "Assert that the array of skus has at least 1 member."); Assert.True(skus.Any(sku => sku.ResourceType == "availabilitySets"), "Assert that the sku list at least contains" + "one availability set."); Assert.True(skus.Any(sku => sku.ResourceType == "virtualMachines"), "Assert that the sku list at least contains" + "one virtual machine."); Assert.True(skus.Any(sku => sku.LocationInfo != null), "Assert that the sku list has non null location info in it."); Assert.True(skus.All(sku => sku.LocationInfo.Count == 1), "There should be exactly one location info per entry."); Assert.True(skus.Any(sku => sku.LocationInfo[0].Location.Equals("westus", StringComparison.Ordinal)), "Assert that it has entry for one of the CRP regions (randomly picked)."); } }
private async Task <string> GetTriggerNameAsync() { IPage <WorkflowTrigger> triggers = await _logicManagementClient.WorkflowTriggers.ListAsync(_resourceGroup, _logicAppName); if (triggers.Any()) { return(triggers.First().Name); } throw new LogicAppTriggerNotFoundException(_logicManagementClient.SubscriptionId, _resourceGroup, _logicAppName, $"Cannot find any trigger for logic app '{_logicAppName}' in resource group '{_resourceGroup}'"); }
private void ReplicateLiveEventsPage(IPage <LiveEvent> liveEventsPage) { if (liveEventsPage.Any()) { foreach (var liveEvent in liveEventsPage) { Helpers.WriteLine($"Replicating live event '{liveEvent.Name}'...", 2); string tempResult = ""; if (DestinationOperations.Get(DestinationAuth.ResourceGroup, DestinationAuth.AccountName, liveEvent.Name) == null) { Helpers.WriteLine($"Copying live event...", 3); LiveEvent tempLiveEvent = new LiveEvent() { CrossSiteAccessPolicies = liveEvent.CrossSiteAccessPolicies, Description = liveEvent.Description, Encoding = liveEvent.Encoding, Input = liveEvent.Input, StreamOptions = liveEvent.StreamOptions, Tags = liveEvent.Tags, Transcriptions = liveEvent.Transcriptions, UseStaticHostname = liveEvent.UseStaticHostname, HostnamePrefix = liveEvent.HostnamePrefix, Location = DestinationAuth.Location, Preview = liveEvent.Preview }; tempLiveEvent.Input.Endpoints = null; tempLiveEvent.Preview.PreviewLocator = ""; DestinationOperations.Create(DestinationAuth.ResourceGroup, DestinationAuth.AccountName, liveEvent.Name, tempLiveEvent); tempResult = "Done"; } else { tempResult = "Already exists"; } Helpers.WriteLine(tempResult, 4); ReplicateLiveOutputs(liveEvent.Name); } } else { Helpers.WriteLine("No live events to copy", 2); } }
private void ReplicateAccountFiltersPage(IPage <AccountFilter> accountFilterPage) { if (accountFilterPage.Any()) { foreach (var accountFilter in accountFilterPage) { Helpers.WriteLine($"Replicating account filter {accountFilter.Name}...", 2); DestinationOperations.CreateOrUpdate(DestinationAuth.ResourceGroup, DestinationAuth.AccountName, accountFilter.Name, accountFilter); Helpers.WriteLine("Done", 3); } } else { Helpers.WriteLine("No account filters to copy", 2); } }
private void ReplicateTeansformsPage(IPage <Transform> transforms) { if (transforms.Any()) { foreach (var transform in transforms) { Helpers.WriteLine($"Copying transform '{transform.Name}'...", 2); DestinationOperations.CreateOrUpdate(DestinationAuth.ResourceGroup, DestinationAuth.AccountName, transform.Name, transform.Outputs, transform.Description); Helpers.WriteLine($"Done", 3); } } else { Helpers.WriteLine("No transforms to copy", 2); } }
private void ReplicateContentKeyPolicyPage(IPage <ContentKeyPolicy> contentKeyPolicies) { if (contentKeyPolicies.Any()) { foreach (var contentKeyPolicy in contentKeyPolicies) { Helpers.WriteLine($"Copying content key policy '{contentKeyPolicy.Name}'...", 2); ContentKeyPolicyProperties tempContentKey = SourceOperations.GetPolicyPropertiesWithSecrets(SourceAuth.ResourceGroup, SourceAuth.AccountName, contentKeyPolicy.Name); DestinationOperations.CreateOrUpdate(DestinationAuth.ResourceGroup, DestinationAuth.AccountName, contentKeyPolicy.Name, tempContentKey.Options, tempContentKey.Description); Helpers.WriteLine($"Done", 3); } } else { Helpers.WriteLine($"No content key policies to replicate", 2); } }
private void ReplicateAssetPage(IPage <Asset> assetPage) { if (assetPage.Any()) { //Loop through page assets and move them to the destination foreach (var asset in assetPage) { Helpers.WriteLine($"Replicating asset '{asset.Name}'...", 2); Helpers.WriteLine($"Copying asset's blobs...", 3); Asset destinationAsset = DestinationOperations.Get(DestinationAuth.ResourceGroup, DestinationAuth.AccountName, asset.Name); //Create destination asset if it does not exists if (destinationAsset == null) { destinationAsset = DestinationOperations.CreateOrUpdate(DestinationAuth.ResourceGroup, DestinationAuth.AccountName, asset.Name, new Asset() { AlternateId = asset.AlternateId, Description = asset.Description }); } //Used to update asset info. sometimes it will be empty destinationAsset = DestinationOperations.Get(DestinationAuth.ResourceGroup, DestinationAuth.AccountName, destinationAsset.Name); CloudBlobContainer sourceContainer = GetCloudBlobContainer(SourceAuth, asset.Container); CloudBlobContainer destinationContainer = GetCloudBlobContainer(DestinationAuth, destinationAsset.Container); CopyAsset(sourceContainer, destinationContainer); if (_sourceAssetFilterOperations != null && _destinationAssetFilterOperations != null) { Helpers.WriteLine($"Copying asset's filters...", 3); ReplicateAssetFilter(asset.Name); } } } else { Helpers.WriteLine("No assets to copy", 2); } }
private bool RenderOutput(IPage <GenericResource> resources) { bool isrendered = false; if (resources == null && !resources.Any()) { isrendered = false; MessageBox.Show("No resource found"); } else { var template = Template.Parse(@" <table border='1' width='100%'> <tr> <th>Resource Name</th> <th>KUDU Link</th> <th>App Editor Link</th> <th>Website Link</th> </tr> {{ for resource in resources }} <tr> <td>{{ resource.name }}</td> <td><a href='https://{{ resource.name }}.scm.azurewebsites.net/DebugConsole' target='_blank'>KUDU</a></td> <td><a href='https://{{ resource.name }}.scm.azurewebsites.net/dev/wwwroot/' target='_blank'>App Editor</a></td> <td><a href='https://{{ resource.name }}.azurewebsites.net/' target='_blank'>Website</a></td> </tr> {{ end }} </table>"); var resourcesList = resources.ToList(); var result = template.Render(new { Resources = resourcesList }); webBrowser1.DocumentText = result; isrendered = true; } return(isrendered); }
/// <summary> /// Select the subscription id to use in the rest of the sample. /// </summary> /// <param name="client">The <see cref="Microsoft.Azure.Management.ResourceManager.SubscriptionClient"/> to use to get all the subscriptions /// under the user's Azure account.</param> /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns> /// <remarks>If the user has 1 subscription under their Azure account, it is chosen automatically. If the user has more than /// one, they are prompted to make a selection.</remarks> private static async Task <string> SelectSubscriptionAsync(SubscriptionClient client) { IPage <Subscription> subs = await client.Subscriptions.ListAsync(); if (subs.Any()) { var subscriptionsList = new List <Subscription>(); subscriptionsList.AddRange(subs); var nextLink = subs.NextPageLink; while (nextLink != null) { subs = await client.Subscriptions.ListNextAsync(nextLink); subscriptionsList.AddRange(subs); nextLink = subs.NextPageLink; } if (subscriptionsList.Count > 1) { // More than 1 subscription found under the Azure account, prompt the user for the subscription to use string[] subscriptionNames = subscriptionsList.Select(s => s.DisplayName).ToArray(); string selectedSubscription = PromptForSelectionFromCollection(subscriptionNames, "Enter the number of the Azure subscription to use: "); Subscription selectedSub = subscriptionsList.First(s => s.DisplayName.Equals(selectedSubscription)); return(selectedSub.SubscriptionId); } else { // Only one subscription found, use that one return(subscriptionsList.First().SubscriptionId); } } else { throw new InvalidOperationException("No subscriptions found in account. Please create at least one subscription within your Azure account."); } }
/// <summary> /// Retrieve a list of all active values matching the provided secretname. /// </summary> /// <param name="keyVaultBaseUrl">The base URL to the Azure Key Vault</param> /// <param name="secretName">The identifier name of the secret to retrieve.</param> /// <returns>A list of <see cref="SecretValue"/> containg all currently active values matching the provided secretname.</returns> public async Task <List <SecretValue> > GetActiveSecretValues(string keyVaultBaseUrl, string secretName) { IPage <SecretItem> secrets = await KeyVaultClient.GetSecretVersionsAsync(keyVaultBaseUrl, secretName); List <SecretValue> activeSecrets = new List <SecretValue>(); if (secrets == null || !secrets.Any()) { return(activeSecrets); } foreach (var secret in secrets) { if (IsSecretActive(secret)) { var secretBundle = await KeyVaultClient.GetSecretAsync(keyVaultBaseUrl, secretName, secret.Identifier.Version) .ConfigureAwait(false); activeSecrets.Add(new SecretValue(secretBundle.Value)); } } return(activeSecrets); }
public void SystemTopicCreateGetUpdateDelete() { using (MockContext context = MockContext.Start(this.GetType())) { this.InitializeClients(context); var location = this.ResourceManagementClient.GetLocationFromProvider(); string resourceGroup = "testtobedeleted"; var systemTopicName = TestUtilities.GenerateName(EventGridManagementHelper.SystemTopicPrefix); // Temporarily commenting this out as this is not yet enabled for the new API version // var operationsResponse = this.EventGridManagementClient.Operations.List(); var originalTagsDictionary = new Dictionary <string, string>() { { "originalTag1", "originalValue1" }, { "originalTag2", "originalValue2" } }; SystemTopic systemTopic = new SystemTopic() { Location = location, Tags = originalTagsDictionary, TopicType = "microsoft.storage.storageaccounts", Source = "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/testtobedeleted/providers/Microsoft.Storage/storageAccounts/testtrackedsourcev2", }; try { var createSystemTopicResponse = this.EventGridManagementClient.SystemTopics.CreateOrUpdateAsync(resourceGroup, systemTopicName, systemTopic).Result; Assert.NotNull(createSystemTopicResponse); Assert.Equal(createSystemTopicResponse.Name, systemTopicName); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // Get the created systemTopic var getSystemTopicResponse = this.EventGridManagementClient.SystemTopics.Get(resourceGroup, systemTopicName); if (string.Compare(getSystemTopicResponse.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getSystemTopicResponse = this.EventGridManagementClient.SystemTopics.Get(resourceGroup, systemTopicName); Assert.NotNull(getSystemTopicResponse); Assert.Equal("Succeeded", getSystemTopicResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(location, getSystemTopicResponse.Location, StringComparer.CurrentCultureIgnoreCase); // Get all systemTopics created within a resourceGroup IPage <SystemTopic> systemTopicsInResourceGroupPage = this.EventGridManagementClient.SystemTopics.ListByResourceGroupAsync(resourceGroup).Result; var systemTopicsInResourceGroupList = new List <SystemTopic>(); if (systemTopicsInResourceGroupPage.Any()) { systemTopicsInResourceGroupList.AddRange(systemTopicsInResourceGroupPage); var nextLink = systemTopicsInResourceGroupPage.NextPageLink; while (nextLink != null) { systemTopicsInResourceGroupPage = this.EventGridManagementClient.SystemTopics.ListByResourceGroupNextAsync(nextLink).Result; systemTopicsInResourceGroupList.AddRange(systemTopicsInResourceGroupPage); nextLink = systemTopicsInResourceGroupPage.NextPageLink; } } Assert.NotNull(systemTopicsInResourceGroupList); Assert.True(systemTopicsInResourceGroupList.Count() >= 1); Assert.Contains(systemTopicsInResourceGroupList, t => t.Name == systemTopicName); Assert.True(systemTopicsInResourceGroupList.All(ns => ns.Id.Contains(resourceGroup))); IPage <SystemTopic> systemTopicsInResourceGroupPageWithTop = this.EventGridManagementClient.SystemTopics.ListByResourceGroupAsync(resourceGroup, null, 5).Result; var systemTopicsInResourceGroupListWithTop = new List <SystemTopic>(); if (systemTopicsInResourceGroupPageWithTop.Any()) { systemTopicsInResourceGroupListWithTop.AddRange(systemTopicsInResourceGroupPageWithTop); var nextLink = systemTopicsInResourceGroupPageWithTop.NextPageLink; while (nextLink != null) { systemTopicsInResourceGroupPageWithTop = this.EventGridManagementClient.SystemTopics.ListByResourceGroupNextAsync(nextLink).Result; systemTopicsInResourceGroupListWithTop.AddRange(systemTopicsInResourceGroupPageWithTop); nextLink = systemTopicsInResourceGroupPageWithTop.NextPageLink; } } Assert.NotNull(systemTopicsInResourceGroupListWithTop); Assert.True(systemTopicsInResourceGroupListWithTop.Count() >= 1); Assert.Contains(systemTopicsInResourceGroupListWithTop, t => t.Name == systemTopicName); Assert.True(systemTopicsInResourceGroupListWithTop.All(ns => ns.Id.Contains(resourceGroup))); // Get all systemTopics created within the subscription irrespective of the resourceGroup IPage <SystemTopic> systemTopicsInAzureSubscription = this.EventGridManagementClient.SystemTopics.ListBySubscriptionAsync(null, 100).Result; var systemTopicsInAzureSubscriptionList = new List <SystemTopic>(); if (systemTopicsInAzureSubscription.Any()) { systemTopicsInAzureSubscriptionList.AddRange(systemTopicsInAzureSubscription); var nextLink = systemTopicsInAzureSubscription.NextPageLink; while (nextLink != null) { try { systemTopicsInAzureSubscription = this.EventGridManagementClient.SystemTopics.ListBySubscriptionNextAsync(nextLink).Result; systemTopicsInAzureSubscriptionList.AddRange(systemTopicsInAzureSubscription); nextLink = systemTopicsInAzureSubscription.NextPageLink; } catch (Exception ex) { Console.WriteLine(ex); break; } } } Assert.NotNull(systemTopicsInAzureSubscriptionList); Assert.True(systemTopicsInAzureSubscriptionList.Count() >= 1); Assert.Contains(systemTopicsInAzureSubscriptionList, t => t.Name == systemTopicName); var replaceSystemTopicTagsDictionary = new Dictionary <string, string>() { { "replacedTag1", "replacedValue1" }, { "replacedTag2", "replacedValue2" } }; // Replace the systemTopic systemTopic.Tags = replaceSystemTopicTagsDictionary; var replaceSystemTopicResponse = this.EventGridManagementClient.SystemTopics.CreateOrUpdateAsync(resourceGroup, systemTopicName, systemTopic).Result; Assert.Contains(replaceSystemTopicResponse.Tags, tag => tag.Key == "replacedTag1"); Assert.DoesNotContain(replaceSystemTopicResponse.Tags, tag => tag.Key == "originalTag1"); // Update the systemTopic with tags & allow traffic from all ips SystemTopicUpdateParameters systemTopicUpdateParameters = new SystemTopicUpdateParameters(); systemTopicUpdateParameters.Tags = new Dictionary <string, string>() { { "updatedTag1", "updatedValue1" }, { "updatedTag2", "updatedValue2" } }; var updateSystemTopicResponse = this.EventGridManagementClient.SystemTopics.UpdateAsync(resourceGroup, systemTopicName, systemTopicUpdateParameters.Tags).Result; Assert.Contains(updateSystemTopicResponse.Tags, tag => tag.Key == "updatedTag1"); Assert.DoesNotContain(updateSystemTopicResponse.Tags, tag => tag.Key == "replacedTag1"); } finally { // Delete systemTopic this.EventGridManagementClient.SystemTopics.DeleteAsync(resourceGroup, systemTopicName).Wait(); } } }
public void PartnerCreateGetUpdateDelete() { using (MockContext context = MockContext.Start(this.GetType())) { this.InitializeClients(context); var location = this.ResourceManagementClient.GetLocationFromProvider(); var resourceGroup = this.ResourceManagementClient.TryGetResourceGroup(location); if (string.IsNullOrWhiteSpace(resourceGroup)) { resourceGroup = TestUtilities.GenerateName(EventGridManagementHelper.ResourceGroupPrefix); this.ResourceManagementClient.TryRegisterResourceGroup(location, resourceGroup); } bool partnerRegistrationCreated = false; bool partnerNamespaceCreated = false; bool eventChannelCreated = false; bool partnerTopicCreated = false; bool eventSubscriptionCreated = false; var partnerNamespaceName = TestUtilities.GenerateName(EventGridManagementHelper.PartnerNamespacePrefix); var eventChannelName = TestUtilities.GenerateName(EventGridManagementHelper.EventChannelPrefix); var partnerTopicName = TestUtilities.GenerateName(EventGridManagementHelper.PartnerTopicPrefix); var eventSubscriptionName = TestUtilities.GenerateName(EventGridManagementHelper.EventSubscriptionPrefix); var partnerRegistrationName = TestUtilities.GenerateName(EventGridManagementHelper.PartnerRegistrationPrefix); // Temporarily commenting this out as this is not yet enabled for the new API version // var operationsResponse = this.EventGridManagementClient.Operations.List(); var originalTagsDictionary = new Dictionary <string, string>() { { "originalTag1", "originalValue1" }, { "originalTag2", "originalValue2" } }; Guid uniqueId = Guid.NewGuid(); string subId = "5b4b650e-28b9-4790-b3ab-ddbd88d727c4"; try { PartnerRegistration partnerRegistration = new PartnerRegistration() { Location = "global", Tags = originalTagsDictionary, LogoUri = "https://www.contoso.com/logo.png", SetupUri = "https://www.contoso.com/setup.html", PartnerName = "Contoso", PartnerResourceTypeName = $"Accounts.{uniqueId}", PartnerResourceTypeDisplayName = $"DisplayName Text -- {uniqueId}", PartnerResourceTypeDescription = $"Description Text -- {uniqueId}", AuthorizedAzureSubscriptionIds = new List <string> { subId }, }; var createPartnerRegistrationResponse = this.EventGridManagementClient.PartnerRegistrations.CreateOrUpdateAsync(resourceGroup, partnerRegistrationName, partnerRegistration).Result; partnerRegistrationCreated = true; Assert.NotNull(createPartnerRegistrationResponse); Assert.Equal(createPartnerRegistrationResponse.Name, partnerRegistrationName); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // Get the created partnerRegistration var getPartnerRegistrationResponse = this.EventGridManagementClient.PartnerRegistrations.Get(resourceGroup, partnerRegistrationName); if (string.Compare(getPartnerRegistrationResponse.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getPartnerRegistrationResponse = this.EventGridManagementClient.PartnerRegistrations.Get(resourceGroup, partnerRegistrationName); Assert.NotNull(getPartnerRegistrationResponse); Assert.Equal("Succeeded", getPartnerRegistrationResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal("global", getPartnerRegistrationResponse.Location, StringComparer.CurrentCultureIgnoreCase); Assert.Contains(getPartnerRegistrationResponse.Tags, tag => tag.Key == "originalTag1"); // Get all partnerRegistrations created within a resourceGroup IPage <PartnerRegistration> partnerRegistrationsInResourceGroupPage = this.EventGridManagementClient.PartnerRegistrations.ListByResourceGroupAsync(resourceGroup).Result; var partnerRegistrationsInResourceGroupList = new List <PartnerRegistration>(); if (partnerRegistrationsInResourceGroupPage.Any()) { partnerRegistrationsInResourceGroupList.AddRange(partnerRegistrationsInResourceGroupPage); var nextLink = partnerRegistrationsInResourceGroupPage.NextPageLink; while (nextLink != null) { partnerRegistrationsInResourceGroupPage = this.EventGridManagementClient.PartnerRegistrations.ListByResourceGroupNextAsync(nextLink).Result; partnerRegistrationsInResourceGroupList.AddRange(partnerRegistrationsInResourceGroupPage); nextLink = partnerRegistrationsInResourceGroupPage.NextPageLink; } } Assert.NotNull(partnerRegistrationsInResourceGroupList); Assert.True(partnerRegistrationsInResourceGroupList.Count() >= 1); Assert.Contains(partnerRegistrationsInResourceGroupList, t => t.Name == partnerRegistrationName); Assert.True(partnerRegistrationsInResourceGroupList.All(ns => ns.Id.Contains(resourceGroup))); IPage <PartnerRegistration> partnerRegistrationsInResourceGroupPageWithTop = this.EventGridManagementClient.PartnerRegistrations.ListByResourceGroupAsync(resourceGroup, null, 5).Result; var partnerRegistrationsInResourceGroupListWithTop = new List <PartnerRegistration>(); if (partnerRegistrationsInResourceGroupPageWithTop.Any()) { partnerRegistrationsInResourceGroupListWithTop.AddRange(partnerRegistrationsInResourceGroupPageWithTop); var nextLink = partnerRegistrationsInResourceGroupPageWithTop.NextPageLink; while (nextLink != null) { partnerRegistrationsInResourceGroupPageWithTop = this.EventGridManagementClient.PartnerRegistrations.ListByResourceGroupNextAsync(nextLink).Result; partnerRegistrationsInResourceGroupListWithTop.AddRange(partnerRegistrationsInResourceGroupPageWithTop); nextLink = partnerRegistrationsInResourceGroupPageWithTop.NextPageLink; } } Assert.NotNull(partnerRegistrationsInResourceGroupListWithTop); Assert.True(partnerRegistrationsInResourceGroupListWithTop.Count() >= 1); Assert.Contains(partnerRegistrationsInResourceGroupListWithTop, t => t.Name == partnerRegistrationName); Assert.True(partnerRegistrationsInResourceGroupListWithTop.All(ns => ns.Id.Contains(resourceGroup))); // Get all partnerRegistrations created within the subscription irrespective of the resourceGroup IPage <PartnerRegistration> partnerRegistrationsInAzureSubscription = this.EventGridManagementClient.PartnerRegistrations.ListBySubscriptionAsync(null, 100).Result; var partnerRegistrationsInAzureSubscriptionList = new List <PartnerRegistration>(); if (partnerRegistrationsInAzureSubscription.Any()) { partnerRegistrationsInAzureSubscriptionList.AddRange(partnerRegistrationsInAzureSubscription); var nextLink = partnerRegistrationsInAzureSubscription.NextPageLink; while (nextLink != null) { try { partnerRegistrationsInAzureSubscription = this.EventGridManagementClient.PartnerRegistrations.ListBySubscriptionNextAsync(nextLink).Result; partnerRegistrationsInAzureSubscriptionList.AddRange(partnerRegistrationsInAzureSubscription); nextLink = partnerRegistrationsInAzureSubscription.NextPageLink; } catch (Exception ex) { Console.WriteLine(ex); break; } } } Assert.NotNull(partnerRegistrationsInAzureSubscriptionList); Assert.True(partnerRegistrationsInAzureSubscriptionList.Count() >= 1); Assert.Contains(partnerRegistrationsInAzureSubscriptionList, t => t.Name == partnerRegistrationName); var replacePartnerRegistrationTagsDictionary = new Dictionary <string, string>() { { "replacedTag1", "replacedValue1" }, { "replacedTag2", "replacedValue2" } }; // Replace the partnerRegistration partnerRegistration.Tags = replacePartnerRegistrationTagsDictionary; var replacePartnerRegistrationResponse = this.EventGridManagementClient.PartnerRegistrations.CreateOrUpdateAsync(resourceGroup, partnerRegistrationName, partnerRegistration).Result; Assert.Contains(replacePartnerRegistrationResponse.Tags, tag => tag.Key == "replacedTag1"); Assert.DoesNotContain(replacePartnerRegistrationResponse.Tags, tag => tag.Key == "originalTag1"); // Update the partnerRegistration with tags //////PartnerRegistrationUpdateParameters partnerRegistrationUpdateParameters = new PartnerRegistrationUpdateParameters(); //////partnerRegistrationUpdateParameters.Tags = new Dictionary<string, string>() //////{ ////// { "updatedTag1", "updatedValue1" }, ////// { "updatedTag2", "updatedValue2" } //////}; //////var updatePartnerRegistrationResponse = this.EventGridManagementClient.PartnerRegistrations.UpdateAsync(resourceGroup, partnerRegistrationName, partnerRegistrationUpdateParameters).Result; //////Assert.Contains(updatePartnerRegistrationResponse.Tags, tag => tag.Key == "updatedTag1"); //////Assert.DoesNotContain(updatePartnerRegistrationResponse.Tags, tag => tag.Key == "replacedTag1"); // Partner namespace operations var originalNamespaceTagsDictionary = new Dictionary <string, string>() { { "originalTag111", "originalValue111" }, { "originalTag222", "originalValue222" } }; PartnerNamespace partnerNamespace = new PartnerNamespace() { Location = location, Tags = originalNamespaceTagsDictionary, PartnerRegistrationFullyQualifiedId = getPartnerRegistrationResponse.Id }; var createPartnerNamespaceResponse = this.EventGridManagementClient.PartnerNamespaces.CreateOrUpdateAsync(resourceGroup, partnerNamespaceName, partnerNamespace).Result; partnerNamespaceCreated = true; Assert.NotNull(createPartnerNamespaceResponse); Assert.Equal(createPartnerNamespaceResponse.Name, partnerNamespaceName); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // Get the created partnerNamespace var getPartnerNamespaceResponse = this.EventGridManagementClient.PartnerNamespaces.Get(resourceGroup, partnerNamespaceName); if (string.Compare(getPartnerNamespaceResponse.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getPartnerNamespaceResponse = this.EventGridManagementClient.PartnerNamespaces.Get(resourceGroup, partnerNamespaceName); Assert.NotNull(getPartnerNamespaceResponse); Assert.Equal("Succeeded", getPartnerNamespaceResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(location, getPartnerNamespaceResponse.Location, StringComparer.CurrentCultureIgnoreCase); Assert.Contains(getPartnerNamespaceResponse.Tags, tag => tag.Key == "originalTag111"); // Get all partnerNamespaces created within a resourceGroup IPage <PartnerNamespace> partnerNamespacesInResourceGroupPage = this.EventGridManagementClient.PartnerNamespaces.ListByResourceGroupAsync(resourceGroup).Result; var partnerNamespacesInResourceGroupList = new List <PartnerNamespace>(); if (partnerNamespacesInResourceGroupPage.Any()) { partnerNamespacesInResourceGroupList.AddRange(partnerNamespacesInResourceGroupPage); var nextLink = partnerNamespacesInResourceGroupPage.NextPageLink; while (nextLink != null) { partnerNamespacesInResourceGroupPage = this.EventGridManagementClient.PartnerNamespaces.ListByResourceGroupNextAsync(nextLink).Result; partnerNamespacesInResourceGroupList.AddRange(partnerNamespacesInResourceGroupPage); nextLink = partnerNamespacesInResourceGroupPage.NextPageLink; } } Assert.NotNull(partnerNamespacesInResourceGroupList); Assert.True(partnerNamespacesInResourceGroupList.Count() >= 1); Assert.Contains(partnerNamespacesInResourceGroupList, t => t.Name == partnerNamespaceName); Assert.True(partnerNamespacesInResourceGroupList.All(ns => ns.Id.Contains(resourceGroup))); IPage <PartnerNamespace> partnerNamespacesInResourceGroupPageWithTop = this.EventGridManagementClient.PartnerNamespaces.ListByResourceGroupAsync(resourceGroup, null, 5).Result; var partnerNamespacesInResourceGroupListWithTop = new List <PartnerNamespace>(); if (partnerNamespacesInResourceGroupPageWithTop.Any()) { partnerNamespacesInResourceGroupListWithTop.AddRange(partnerNamespacesInResourceGroupPageWithTop); var nextLink = partnerNamespacesInResourceGroupPageWithTop.NextPageLink; while (nextLink != null) { partnerNamespacesInResourceGroupPageWithTop = this.EventGridManagementClient.PartnerNamespaces.ListByResourceGroupNextAsync(nextLink).Result; partnerNamespacesInResourceGroupListWithTop.AddRange(partnerNamespacesInResourceGroupPageWithTop); nextLink = partnerNamespacesInResourceGroupPageWithTop.NextPageLink; } } Assert.NotNull(partnerNamespacesInResourceGroupListWithTop); Assert.True(partnerNamespacesInResourceGroupListWithTop.Count() >= 1); Assert.Contains(partnerNamespacesInResourceGroupListWithTop, t => t.Name == partnerNamespaceName); Assert.True(partnerNamespacesInResourceGroupListWithTop.All(ns => ns.Id.Contains(resourceGroup))); // Get all partnerNamespaces created within the subscription irrespective of the resourceGroup IPage <PartnerNamespace> partnerNamespacesInAzureSubscription = this.EventGridManagementClient.PartnerNamespaces.ListBySubscriptionAsync(null, 100).Result; var partnerNamespacesInAzureSubscriptionList = new List <PartnerNamespace>(); if (partnerNamespacesInAzureSubscription.Any()) { partnerNamespacesInAzureSubscriptionList.AddRange(partnerNamespacesInAzureSubscription); var nextLink = partnerNamespacesInAzureSubscription.NextPageLink; while (nextLink != null) { try { partnerNamespacesInAzureSubscription = this.EventGridManagementClient.PartnerNamespaces.ListBySubscriptionNextAsync(nextLink).Result; partnerNamespacesInAzureSubscriptionList.AddRange(partnerNamespacesInAzureSubscription); nextLink = partnerNamespacesInAzureSubscription.NextPageLink; } catch (Exception ex) { Console.WriteLine(ex); break; } } } Assert.NotNull(partnerNamespacesInAzureSubscriptionList); Assert.True(partnerNamespacesInAzureSubscriptionList.Count() >= 1); Assert.Contains(partnerNamespacesInAzureSubscriptionList, t => t.Name == partnerNamespaceName); var replacePartnerNamespaceTagsDictionary = new Dictionary <string, string>() { { "replacedTag111", "replacedValue111" }, { "replacedTag222", "replacedValue222" } }; // Replace the partnerNamespace partnerNamespace.Tags = replacePartnerNamespaceTagsDictionary; var replacePartnerNamespaceResponse = this.EventGridManagementClient.PartnerNamespaces.CreateOrUpdateAsync(resourceGroup, partnerNamespaceName, partnerNamespace).Result; Assert.Contains(replacePartnerNamespaceResponse.Tags, tag => tag.Key == "replacedTag111"); Assert.DoesNotContain(replacePartnerNamespaceResponse.Tags, tag => tag.Key == "originalTag111"); // EventChannel/PartnerTopic operations var originalPartnerTopicTagsDictionary = new Dictionary <string, string>() { { "originalTag11111", "originalValue11111" }, { "originalTag22222", "originalValue22222" } }; EventChannel eventChannel = new EventChannel() { Source = new EventChannelSource { Source = $"Accounts.User.{uniqueId}", }, Destination = new EventChannelDestination { AzureSubscriptionId = subId, ResourceGroup = resourceGroup, PartnerTopicName = partnerTopicName }, }; var createEventChannelResponse = this.EventGridManagementClient.EventChannels.CreateOrUpdateAsync(resourceGroup, partnerNamespaceName, eventChannelName, eventChannel).Result; eventChannelCreated = true; partnerTopicCreated = true; Assert.NotNull(createEventChannelResponse); Assert.Equal(createEventChannelResponse.Name, eventChannelName); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // Get the created eventChannel var getEventChannelResponse = this.EventGridManagementClient.EventChannels.Get(resourceGroup, partnerNamespaceName, eventChannelName); if (string.Compare(getEventChannelResponse.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getEventChannelResponse = this.EventGridManagementClient.EventChannels.Get(resourceGroup, partnerNamespaceName, eventChannelName); Assert.NotNull(getEventChannelResponse); Assert.Equal("Succeeded", getEventChannelResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); // Get all eventChannels created within a partnerNamespace IPage <EventChannel> eventChannelsInPartnerNamespacePage = this.EventGridManagementClient.EventChannels.ListByPartnerNamespaceAsync(resourceGroup, partnerNamespaceName).Result; var eventChannelsInPartnerNamespaceList = new List <EventChannel>(); if (eventChannelsInPartnerNamespacePage.Any()) { eventChannelsInPartnerNamespaceList.AddRange(eventChannelsInPartnerNamespacePage); var nextLink = eventChannelsInPartnerNamespacePage.NextPageLink; while (nextLink != null) { eventChannelsInPartnerNamespacePage = this.EventGridManagementClient.EventChannels.ListByPartnerNamespaceNextAsync(nextLink).Result; eventChannelsInPartnerNamespaceList.AddRange(eventChannelsInPartnerNamespacePage); nextLink = eventChannelsInPartnerNamespacePage.NextPageLink; } } Assert.NotNull(eventChannelsInPartnerNamespaceList); Assert.True(eventChannelsInPartnerNamespaceList.Count() >= 1); Assert.Contains(eventChannelsInPartnerNamespaceList, t => t.Name == eventChannelName); Assert.True(eventChannelsInPartnerNamespaceList.All(ns => ns.Id.Contains(resourceGroup))); // Partner topic operations // Get the created partnerTopic var getPartnerTopicResponse = this.EventGridManagementClient.PartnerTopics.Get(resourceGroup, partnerTopicName); if (string.Compare(getPartnerTopicResponse.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getPartnerTopicResponse = this.EventGridManagementClient.PartnerTopics.Get(resourceGroup, partnerTopicName); Assert.NotNull(getPartnerTopicResponse); Assert.Equal("Succeeded", getPartnerTopicResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(location, getPartnerTopicResponse.Location, StringComparer.CurrentCultureIgnoreCase); Assert.Null(getPartnerTopicResponse.Tags); // Get all partnerTopics created within a resourceGroup IPage <PartnerTopic> partnerTopicsInResourceGroupPage = this.EventGridManagementClient.PartnerTopics.ListByResourceGroupAsync(resourceGroup).Result; var partnerTopicsInResourceGroupList = new List <PartnerTopic>(); if (partnerTopicsInResourceGroupPage.Any()) { partnerTopicsInResourceGroupList.AddRange(partnerTopicsInResourceGroupPage); var nextLink = partnerTopicsInResourceGroupPage.NextPageLink; while (nextLink != null) { partnerTopicsInResourceGroupPage = this.EventGridManagementClient.PartnerTopics.ListByResourceGroupNextAsync(nextLink).Result; partnerTopicsInResourceGroupList.AddRange(partnerTopicsInResourceGroupPage); nextLink = partnerTopicsInResourceGroupPage.NextPageLink; } } Assert.NotNull(partnerTopicsInResourceGroupList); Assert.True(partnerTopicsInResourceGroupList.Count() >= 1); Assert.Contains(partnerTopicsInResourceGroupList, t => t.Name == partnerTopicName); Assert.True(partnerTopicsInResourceGroupList.All(ns => ns.Id.Contains(resourceGroup))); IPage <PartnerTopic> partnerTopicsInResourceGroupPageWithTop = this.EventGridManagementClient.PartnerTopics.ListByResourceGroupAsync(resourceGroup, null, 5).Result; var partnerTopicsInResourceGroupListWithTop = new List <PartnerTopic>(); if (partnerTopicsInResourceGroupPageWithTop.Any()) { partnerTopicsInResourceGroupListWithTop.AddRange(partnerTopicsInResourceGroupPageWithTop); var nextLink = partnerTopicsInResourceGroupPageWithTop.NextPageLink; while (nextLink != null) { partnerTopicsInResourceGroupPageWithTop = this.EventGridManagementClient.PartnerTopics.ListByResourceGroupNextAsync(nextLink).Result; partnerTopicsInResourceGroupListWithTop.AddRange(partnerTopicsInResourceGroupPageWithTop); nextLink = partnerTopicsInResourceGroupPageWithTop.NextPageLink; } } Assert.NotNull(partnerTopicsInResourceGroupListWithTop); Assert.True(partnerTopicsInResourceGroupListWithTop.Count() >= 1); Assert.Contains(partnerTopicsInResourceGroupListWithTop, t => t.Name == partnerTopicName); Assert.True(partnerTopicsInResourceGroupListWithTop.All(ns => ns.Id.Contains(resourceGroup))); // Get all partnerTopics created within the subscription irrespective of the resourceGroup IPage <PartnerTopic> partnerTopicsInAzureSubscription = this.EventGridManagementClient.PartnerTopics.ListBySubscriptionAsync(null, 100).Result; var partnerTopicsInAzureSubscriptionList = new List <PartnerTopic>(); if (partnerTopicsInAzureSubscription.Any()) { partnerTopicsInAzureSubscriptionList.AddRange(partnerTopicsInAzureSubscription); var nextLink = partnerTopicsInAzureSubscription.NextPageLink; while (nextLink != null) { try { partnerTopicsInAzureSubscription = this.EventGridManagementClient.PartnerTopics.ListBySubscriptionNextAsync(nextLink).Result; partnerTopicsInAzureSubscriptionList.AddRange(partnerTopicsInAzureSubscription); nextLink = partnerTopicsInAzureSubscription.NextPageLink; } catch (Exception ex) { Console.WriteLine(ex); break; } } } Assert.NotNull(partnerTopicsInAzureSubscriptionList); Assert.True(partnerTopicsInAzureSubscriptionList.Count() >= 1); Assert.Contains(partnerTopicsInAzureSubscriptionList, t => t.Name == partnerTopicName); EventSubscription eventSubscription = new EventSubscription() { Destination = new StorageQueueEventSubscriptionDestination() { QueueName = "queue1", ResourceId = "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/DevExpRg/providers/Microsoft.Storage/storageAccounts/devexpstg" }, Filter = new EventSubscriptionFilter() { IncludedEventTypes = null, IsSubjectCaseSensitive = true, SubjectBeginsWith = "TestPrefix", SubjectEndsWith = "TestSuffix" }, Labels = new List <string>() { "TestLabel1", "TestLabel2" } }; var eventSubscriptionResponse = this.EventGridManagementClient.PartnerTopicEventSubscriptions.CreateOrUpdateAsync(resourceGroup, partnerTopicName, eventSubscriptionName, eventSubscription).Result; eventSubscriptionCreated = true; Assert.NotNull(eventSubscriptionResponse); Assert.Equal(eventSubscriptionResponse.Name, eventSubscriptionName); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // Get the created event subscription eventSubscriptionResponse = EventGridManagementClient.PartnerTopicEventSubscriptions.Get(resourceGroup, partnerTopicName, eventSubscriptionName); if (string.Compare(eventSubscriptionResponse.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } eventSubscriptionResponse = EventGridManagementClient.PartnerTopicEventSubscriptions.Get(resourceGroup, partnerTopicName, eventSubscriptionName); Assert.NotNull(eventSubscriptionResponse); Assert.Equal("Succeeded", eventSubscriptionResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal("TestPrefix", eventSubscriptionResponse.Filter.SubjectBeginsWith, StringComparer.CurrentCultureIgnoreCase); Assert.Equal("TestSuffix", eventSubscriptionResponse.Filter.SubjectEndsWith, StringComparer.CurrentCultureIgnoreCase); // Update the event subscription var eventSubscriptionUpdateParameters = new EventSubscriptionUpdateParameters() { Destination = new StorageQueueEventSubscriptionDestination() { QueueName = "queue1", ResourceId = "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/DevExpRg/providers/Microsoft.Storage/storageAccounts/devexpstg" }, Filter = new EventSubscriptionFilter() { IncludedEventTypes = new List <string>() { "Event1", "Event2" }, SubjectEndsWith = ".jpg", SubjectBeginsWith = "TestPrefix" }, Labels = new List <string>() { "UpdatedLabel1", "UpdatedLabel2", } }; eventSubscriptionResponse = this.eventGridManagementClient.PartnerTopicEventSubscriptions.UpdateAsync(resourceGroup, partnerTopicName, eventSubscriptionName, eventSubscriptionUpdateParameters).Result; Assert.Equal(".jpg", eventSubscriptionResponse.Filter.SubjectEndsWith, StringComparer.CurrentCultureIgnoreCase); Assert.Contains(eventSubscriptionResponse.Labels, label => label == "UpdatedLabel1"); // List event subscriptions ////////var eventSubscriptionsPage = this.EventGridManagementClient.PartnerTopicEventSubscriptions.ListByPartnerTopicAsync(resourceGroup, partnerTopicName).Result; ////////List<EventSubscription> eventSubscriptionsList = new List<EventSubscription>(); ////////string nextLink = null; ////////if (eventSubscriptionsPage != null) ////////{ //////// eventSubscriptionsList.AddRange(eventSubscriptionsPage); //////// nextLink = eventSubscriptionsPage.NextPageLink; //////// while (nextLink != null) //////// { //////// eventSubscriptionsPage = this.EventGridManagementClient.EventSubscriptions.ListRegionalByResourceGroupNextAsync(nextLink).Result; //////// eventSubscriptionsList.AddRange(eventSubscriptionsPage); //////// nextLink = eventSubscriptionsPage.NextPageLink; //////// } ////////} } finally { if (eventSubscriptionCreated) { // Delete the event subscription EventGridManagementClient.PartnerTopicEventSubscriptions.DeleteAsync(resourceGroup, partnerTopicName, eventSubscriptionName).Wait(); } if (partnerTopicCreated) { // Delete partnerTopic this.EventGridManagementClient.PartnerTopics.DeleteAsync(resourceGroup, partnerTopicName).Wait(); } if (eventChannelCreated) { // Delete eventChannel this.EventGridManagementClient.EventChannels.DeleteAsync(resourceGroup, partnerNamespaceName, eventChannelName).Wait(); } if (partnerNamespaceCreated) { // Delete partnerNamespace this.EventGridManagementClient.PartnerNamespaces.DeleteAsync(resourceGroup, partnerNamespaceName).Wait(); } if (partnerRegistrationCreated) { // Delete partnerRegistration this.EventGridManagementClient.PartnerRegistrations.DeleteAsync(resourceGroup, partnerRegistrationName).Wait(); } } } }
public void SystemTopicEventSubscriptionCreateGetUpdateDelete() { using (MockContext context = MockContext.Start(this.GetType())) { this.InitializeClients(context); var location = this.ResourceManagementClient.GetLocationFromProvider(); string resourcegroup = "testtobedeleted"; var systemtopicname = TestUtilities.GenerateName(EventGridManagementHelper.SystemTopicPrefix); var eventSubscriptionName = TestUtilities.GenerateName(EventGridManagementHelper.EventSubscriptionPrefix); // Create system topic var originaltagsdictionary = new Dictionary <string, string>() { { "originaltag1", "originalvalue1" }, { "originaltag2", "originalvalue2" } }; SystemTopic systemtopic = new SystemTopic() { Location = location, Tags = originaltagsdictionary, TopicType = "microsoft.storage.storageaccounts", Source = "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourcegroups/testtobedeleted/providers/microsoft.storage/storageaccounts/testtrackedsourcev2", }; try { var createsystemtopicresponse = this.EventGridManagementClient.SystemTopics.CreateOrUpdateAsync(resourcegroup, systemtopicname, systemtopic).Result; Assert.NotNull(createsystemtopicresponse); Assert.Equal(createsystemtopicresponse.Name, systemtopicname); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // get the created systemtopic var getsystemtopicresponse = this.EventGridManagementClient.SystemTopics.Get(resourcegroup, systemtopicname); if (string.Compare(getsystemtopicresponse.ProvisioningState, "succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getsystemtopicresponse = this.EventGridManagementClient.SystemTopics.Get(resourcegroup, systemtopicname); Assert.NotNull(getsystemtopicresponse); Assert.Equal("succeeded", getsystemtopicresponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(location, getsystemtopicresponse.Location, StringComparer.CurrentCultureIgnoreCase); // Create Event Subscription to system topic string scope = $"/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourceGroups/{resourcegroup}/providers/Microsoft.EventGrid/topics/{systemtopicname}"; EventSubscription eventSubscription = new EventSubscription() { Destination = new WebHookEventSubscriptionDestination() { EndpointUrl = AzureFunctionEndpointUrl }, Filter = new EventSubscriptionFilter() { IncludedEventTypes = null, IsSubjectCaseSensitive = true, SubjectBeginsWith = "TestPrefix", SubjectEndsWith = "TestSuffix" }, Labels = new List <string>() { "TestLabel1", "TestLabel2" } }; var createsystemtopiceventsubscriptionresponse = this.EventGridManagementClient.SystemTopicEventSubscriptions.CreateOrUpdateWithHttpMessagesAsync(resourcegroup, systemtopicname, eventSubscriptionName, eventSubscription); createsystemtopiceventsubscriptionresponse.Wait(); Assert.NotNull(createsystemtopiceventsubscriptionresponse); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // get the created systemtopiceventsubscription var getsystemtopiceventsubscriptionresponse = this.EventGridManagementClient.SystemTopicEventSubscriptions.Get(resourcegroup, systemtopicname, eventSubscriptionName); if (string.Compare(getsystemtopiceventsubscriptionresponse.ProvisioningState, "succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } Assert.Equal("succeeded", getsystemtopicresponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(location, getsystemtopicresponse.Location, StringComparer.CurrentCultureIgnoreCase); // list all systemtopiceventsubscriptions and check previously created event subscription is there var listsystemtopiceventsubscriptionresponse = this.EventGridManagementClient.SystemTopicEventSubscriptions.ListBySystemTopic(resourcegroup, systemtopicname); Assert.NotNull(listsystemtopiceventsubscriptionresponse); Assert.True(listsystemtopiceventsubscriptionresponse.Count() >= 1); //Assert.True(listsystemtopiceventsubscriptionresponse.FirstOrDefault().Name== eventSubscriptionName); var doesEventSubscriptionExist = listsystemtopiceventsubscriptionresponse.Any(ns => ns.Name.Equals(eventSubscriptionName)); Assert.True(doesEventSubscriptionExist); // delete Event Subscription this.EventGridManagementClient.SystemTopicEventSubscriptions.DeleteAsync(resourcegroup, systemtopicname, eventSubscriptionName).Wait(); listsystemtopiceventsubscriptionresponse = this.EventGridManagementClient.SystemTopicEventSubscriptions.ListBySystemTopic(resourcegroup, systemtopicname); doesEventSubscriptionExist = listsystemtopiceventsubscriptionresponse.Any(ns => ns.Name.Equals(eventSubscriptionName)); Assert.False(doesEventSubscriptionExist); // delete systemtopic this.EventGridManagementClient.SystemTopics.DeleteAsync(resourcegroup, systemtopicname).Wait(); } finally { var listsystemtopicresponse = this.EventGridManagementClient.SystemTopics.ListByResourceGroup(resourcegroup); var doessystemtopicexist = listsystemtopicresponse.Any(ns => ns.Name.Equals(systemtopicname)); // delete Event Subscription IPage <EventSubscription> listsystemtopiceventsubscriptionresponse = null; if (doessystemtopicexist) { listsystemtopiceventsubscriptionresponse = this.EventGridManagementClient.SystemTopicEventSubscriptions.ListBySystemTopic(resourcegroup, systemtopicname); var doesEventSubscriptionExist = listsystemtopiceventsubscriptionresponse.Any(ns => ns.Name.Equals(eventSubscriptionName)); if (doesEventSubscriptionExist) { this.EventGridManagementClient.SystemTopicEventSubscriptions.DeleteAsync(resourcegroup, systemtopicname, eventSubscriptionName).Wait(); } } // delete systemtopic if (doessystemtopicexist) { this.EventGridManagementClient.SystemTopics.DeleteAsync(resourcegroup, systemtopicname).Wait(); } } } }
public override void ExecuteCmdlet() { try { var endDate = DateTime.Now; var oneYearSpan = endDate.Subtract(new TimeSpan(365, 0, 0, 0)); var startDate = new DateTime(oneYearSpan.Year, oneYearSpan.Month, 1); if (PeriodStartDate != null && PeriodEndDate != null) { startDate = PeriodStartDate.Value; endDate = PeriodEndDate.Value; } var periodStartDate = startDate.ToString("O"); var periodEndDate = endDate.ToString("O"); IPage <Invoice> invoices = null; if (ParameterSetName.Equals(Constants.ParameterSetNames.ListParameterSet) || ParameterSetName.Equals(Constants.ParameterSetNames.LatestItemParameterSet)) { // modern flow if (!string.IsNullOrWhiteSpace(BillingAccountName)) { if (!string.IsNullOrWhiteSpace(BillingProfileName)) { //fetch by /{ba}/{bp} invoices = BillingManagementClient.Invoices.ListByBillingProfile( billingAccountName: BillingAccountName, billingProfileName: BillingProfileName, periodStartDate: periodStartDate, periodEndDate: periodEndDate); } else // fetch by /{ba} { invoices = BillingManagementClient.Invoices.ListByBillingAccount( billingAccountName: BillingAccountName, periodStartDate: periodStartDate, periodEndDate: periodEndDate); } } else // ba/billingSub/{subId}/invoices { invoices = BillingManagementClient.Invoices.ListByBillingSubscription( periodStartDate: periodStartDate, periodEndDate: periodEndDate); } if (invoices != null && invoices.Any()) { var recentInvoices = (from invoice in invoices where invoice.InvoiceDate.HasValue orderby invoice.InvoiceDate descending select invoice).Take(MaxCount ?? 100); if (ParameterSetName.Equals(Constants.ParameterSetNames.LatestItemParameterSet)) { var psInvoice = new PSInvoice(recentInvoices.FirstOrDefault()); if (GenerateDownloadUrl) { this.GetDownloadUrl( recentInvoices.FirstOrDefault(), psInvoice, BillingAccountName ?? null); } WriteObject(psInvoice); } else { foreach (var invoice in recentInvoices) { var psInvoice = new PSInvoice(invoice); if (GenerateDownloadUrl) { this.GetDownloadUrl( invoice, psInvoice, BillingAccountName ?? null); } WriteObject(psInvoice); } } } return; } if (ParameterSetName.Equals(Constants.ParameterSetNames.SingleItemParameterSet)) { foreach (var invoiceName in Name) { try { var downloadBySubscription = false; Invoice invoice = null; if (!string.IsNullOrWhiteSpace(BillingAccountName)) // modern { invoice = BillingManagementClient.Invoices.Get( billingAccountName: BillingAccountName, invoiceName: invoiceName); } else // legacy { // getbyId retrieves legacy and modern invoices invoice = BillingManagementClient.Invoices.GetById(invoiceName); downloadBySubscription = true; } var psInvoice = new PSInvoice(invoice); if (GenerateDownloadUrl) { this.GetDownloadUrl( invoice, psInvoice, BillingAccountName ?? null, downloadBySubscription); } WriteObject(psInvoice); } catch (ErrorResponseException error) { WriteWarning(invoiceName + ": " + error.Body.Error.Message); // continue with the next } } } } catch (ErrorResponseException e) { WriteWarning(e.Body.Error.Message); } }
public void TopicCreateGetUpdateDelete() { using (MockContext context = MockContext.Start(this.GetType())) { this.InitializeClients(context); var location = this.ResourceManagementClient.GetLocationFromProvider(); var resourceGroup = this.ResourceManagementClient.TryGetResourceGroup(location); if (string.IsNullOrWhiteSpace(resourceGroup)) { resourceGroup = TestUtilities.GenerateName(EventGridManagementHelper.ResourceGroupPrefix); this.ResourceManagementClient.TryRegisterResourceGroup(location, resourceGroup); } var topicName = TestUtilities.GenerateName(EventGridManagementHelper.TopicPrefix); // Temporarily commenting this out as this is not yet enabled for the new API version // var operationsResponse = this.EventGridManagementClient.Operations.List(); var originalTagsDictionary = new Dictionary <string, string>() { { "originalTag1", "originalValue1" }, { "originalTag2", "originalValue2" } }; Topic topic = new Topic() { Location = location, Tags = originalTagsDictionary, InputSchema = InputSchema.CustomEventSchema, InputSchemaMapping = new JsonInputSchemaMapping() { Subject = new JsonFieldWithDefault("mySubjectField"), Topic = new JsonField("myTopicField"), DataVersion = new JsonFieldWithDefault(sourceField: null, defaultValue: "2"), EventType = new JsonFieldWithDefault("MyEventTypeField"), EventTime = new JsonField("MyEventTimeField"), Id = new JsonField("MyIDFIELD") } }; var createTopicResponse = this.EventGridManagementClient.Topics.CreateOrUpdateAsync(resourceGroup, topicName, topic).Result; Assert.NotNull(createTopicResponse); Assert.Equal(createTopicResponse.Name, topicName); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // Get the created topic var getTopicResponse = this.EventGridManagementClient.Topics.Get(resourceGroup, topicName); if (string.Compare(getTopicResponse.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getTopicResponse = this.EventGridManagementClient.Topics.Get(resourceGroup, topicName); Assert.NotNull(getTopicResponse); Assert.Equal("Succeeded", getTopicResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(location, getTopicResponse.Location, StringComparer.CurrentCultureIgnoreCase); Assert.Contains(getTopicResponse.Tags, tag => tag.Key == "originalTag1"); // Get all topics created within a resourceGroup IPage <Topic> topicsInResourceGroupPage = this.EventGridManagementClient.Topics.ListByResourceGroupAsync(resourceGroup).Result; var topicsInResourceGroupList = new List <Topic>(); if (topicsInResourceGroupPage.Any()) { topicsInResourceGroupList.AddRange(topicsInResourceGroupPage); var nextLink = topicsInResourceGroupPage.NextPageLink; while (nextLink != null) { topicsInResourceGroupPage = this.EventGridManagementClient.Topics.ListByResourceGroupNextAsync(nextLink).Result; topicsInResourceGroupList.AddRange(topicsInResourceGroupPage); nextLink = topicsInResourceGroupPage.NextPageLink; } } Assert.NotNull(topicsInResourceGroupList); Assert.True(topicsInResourceGroupList.Count() >= 1); Assert.Contains(topicsInResourceGroupList, t => t.Name == topicName); Assert.True(topicsInResourceGroupList.All(ns => ns.Id.Contains(resourceGroup))); IPage <Topic> topicsInResourceGroupPageWithTop = this.EventGridManagementClient.Topics.ListByResourceGroupAsync(resourceGroup, null, 5).Result; var topicsInResourceGroupListWithTop = new List <Topic>(); if (topicsInResourceGroupPageWithTop.Any()) { topicsInResourceGroupListWithTop.AddRange(topicsInResourceGroupPageWithTop); var nextLink = topicsInResourceGroupPageWithTop.NextPageLink; while (nextLink != null) { topicsInResourceGroupPageWithTop = this.EventGridManagementClient.Topics.ListByResourceGroupNextAsync(nextLink).Result; topicsInResourceGroupListWithTop.AddRange(topicsInResourceGroupPageWithTop); nextLink = topicsInResourceGroupPageWithTop.NextPageLink; } } Assert.NotNull(topicsInResourceGroupListWithTop); Assert.True(topicsInResourceGroupListWithTop.Count() >= 1); Assert.Contains(topicsInResourceGroupListWithTop, t => t.Name == topicName); Assert.True(topicsInResourceGroupListWithTop.All(ns => ns.Id.Contains(resourceGroup))); // Get all topics created within the subscription irrespective of the resourceGroup IPage <Topic> topicsInAzureSubscription = this.EventGridManagementClient.Topics.ListBySubscriptionAsync(null, 100).Result; var topicsInAzureSubscriptionList = new List <Topic>(); if (topicsInAzureSubscription.Any()) { topicsInAzureSubscriptionList.AddRange(topicsInAzureSubscription); var nextLink = topicsInAzureSubscription.NextPageLink; while (nextLink != null) { try { topicsInAzureSubscription = this.EventGridManagementClient.Topics.ListBySubscriptionNextAsync(nextLink).Result; topicsInAzureSubscriptionList.AddRange(topicsInAzureSubscription); nextLink = topicsInAzureSubscription.NextPageLink; } catch (Exception ex) { Console.WriteLine(ex); break; } } } Assert.NotNull(topicsInAzureSubscriptionList); Assert.True(topicsInAzureSubscriptionList.Count() >= 1); Assert.Contains(topicsInAzureSubscriptionList, t => t.Name == topicName); var replaceTopicTagsDictionary = new Dictionary <string, string>() { { "replacedTag1", "replacedValue1" }, { "replacedTag2", "replacedValue2" } }; // Replace the topic topic.Tags = replaceTopicTagsDictionary; var replaceTopicResponse = this.EventGridManagementClient.Topics.CreateOrUpdateAsync(resourceGroup, topicName, topic).Result; Assert.Contains(replaceTopicResponse.Tags, tag => tag.Key == "replacedTag1"); Assert.DoesNotContain(replaceTopicResponse.Tags, tag => tag.Key == "originalTag1"); // Update the topic with tags & allow traffic from all ips TopicUpdateParameters topicUpdateParameters = new TopicUpdateParameters(); topicUpdateParameters.Tags = new Dictionary <string, string>() { { "updatedTag1", "updatedValue1" }, { "updatedTag2", "updatedValue2" } }; topic.AllowTrafficFromAllIPs = true; var updateTopicResponse = this.EventGridManagementClient.Topics.UpdateAsync(resourceGroup, topicName, topicUpdateParameters).Result; Assert.Contains(updateTopicResponse.Tags, tag => tag.Key == "updatedTag1"); Assert.DoesNotContain(updateTopicResponse.Tags, tag => tag.Key == "replacedTag1"); Assert.True(updateTopicResponse.AllowTrafficFromAllIPs); Assert.Null(updateTopicResponse.InboundIpRules); // Update the Topic with IP filtering feature topic.AllowTrafficFromAllIPs = false; topic.InboundIpRules = new List <InboundIpRule>(); topic.InboundIpRules.Add(new InboundIpRule() { Action = IpActionType.Allow, IpMask = "12.35.67.98" }); topic.InboundIpRules.Add(new InboundIpRule() { Action = IpActionType.Allow, IpMask = "12.35.90.100" }); var updateTopicResponseWithIpFilteringFeature = this.EventGridManagementClient.Topics.CreateOrUpdateAsync(resourceGroup, topicName, topic).Result; Assert.False(updateTopicResponseWithIpFilteringFeature.AllowTrafficFromAllIPs); Assert.True(updateTopicResponseWithIpFilteringFeature.InboundIpRules.Count() == 2); // Delete topic this.EventGridManagementClient.Topics.DeleteAsync(resourceGroup, topicName).Wait(); } }
public void DomainCreateGetUpdateDelete() { using (MockContext context = MockContext.Start(this.GetType())) { this.InitializeClients(context); var location = this.ResourceManagementClient.GetLocationFromProvider(); var resourceGroup = this.ResourceManagementClient.TryGetResourceGroup(location); if (string.IsNullOrWhiteSpace(resourceGroup)) { resourceGroup = TestUtilities.GenerateName(EventGridManagementHelper.ResourceGroupPrefix); this.ResourceManagementClient.TryRegisterResourceGroup(location, resourceGroup); } var domainName = TestUtilities.GenerateName(EventGridManagementHelper.DomainPrefix); var domainTopicName1 = TestUtilities.GenerateName(EventGridManagementHelper.DomainTopicPrefix); var domainTopicName2 = TestUtilities.GenerateName(EventGridManagementHelper.DomainTopicPrefix); // Temporarily commenting this out as this is not yet enabled for the new API version // var operationsResponse = this.EventGridManagementClient.Operations.List(); var originalTagsDictionary = new Dictionary <string, string>() { { "originalTag1", "originalValue1" }, { "originalTag2", "originalValue2" } }; Domain domain = new Domain() { Location = location, Tags = originalTagsDictionary, InputSchema = InputSchema.CloudEventSchemaV10, InputSchemaMapping = new JsonInputSchemaMapping() { Topic = new JsonField("myTopicField") } }; var createDomainResponse = this.EventGridManagementClient.Domains.CreateOrUpdateAsync(resourceGroup, domainName, domain).Result; Assert.NotNull(createDomainResponse); Assert.Equal(createDomainResponse.Name, domainName); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // Get the created domain var getDomainResponse = this.EventGridManagementClient.Domains.Get(resourceGroup, domainName); if (string.Compare(getDomainResponse.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getDomainResponse = this.EventGridManagementClient.Domains.Get(resourceGroup, domainName); Assert.NotNull(getDomainResponse); Assert.Equal("Succeeded", getDomainResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(location, getDomainResponse.Location, StringComparer.CurrentCultureIgnoreCase); Assert.Contains(getDomainResponse.Tags, tag => tag.Key == "originalTag1"); //// Diable test as identity is not part of GA Version yet. //// Assert.Null(getDomainResponse.Identity); Assert.Null(getDomainResponse.InboundIpRules); // Get all domains created within a resourceGroup IPage <Domain> domainsInResourceGroupPage = this.EventGridManagementClient.Domains.ListByResourceGroupAsync(resourceGroup).Result; var domainsInResourceGroupList = new List <Domain>(); if (domainsInResourceGroupPage.Any()) { domainsInResourceGroupList.AddRange(domainsInResourceGroupPage); var nextLink = domainsInResourceGroupPage.NextPageLink; while (nextLink != null) { domainsInResourceGroupPage = this.EventGridManagementClient.Domains.ListByResourceGroupNextAsync(nextLink).Result; domainsInResourceGroupList.AddRange(domainsInResourceGroupPage); nextLink = domainsInResourceGroupPage.NextPageLink; } } Assert.NotNull(domainsInResourceGroupList); Assert.True(domainsInResourceGroupList.Count() >= 1); Assert.Contains(domainsInResourceGroupList, t => t.Name == domainName); Assert.True(domainsInResourceGroupList.All(ns => ns.Id.Contains(resourceGroup))); IPage <Domain> domainsInResourceGroupPageWithTop = this.EventGridManagementClient.Domains.ListByResourceGroupAsync(resourceGroup, null, 5).Result; var domainsInResourceGroupListWithTop = new List <Domain>(); if (domainsInResourceGroupPageWithTop.Any()) { domainsInResourceGroupListWithTop.AddRange(domainsInResourceGroupPageWithTop); var nextLink = domainsInResourceGroupPageWithTop.NextPageLink; while (nextLink != null) { domainsInResourceGroupPageWithTop = this.EventGridManagementClient.Domains.ListByResourceGroupNextAsync(nextLink).Result; domainsInResourceGroupListWithTop.AddRange(domainsInResourceGroupPageWithTop); nextLink = domainsInResourceGroupPageWithTop.NextPageLink; } } Assert.NotNull(domainsInResourceGroupListWithTop); Assert.True(domainsInResourceGroupListWithTop.Count() >= 1); Assert.Contains(domainsInResourceGroupListWithTop, t => t.Name == domainName); Assert.True(domainsInResourceGroupListWithTop.All(ns => ns.Id.Contains(resourceGroup))); // Get all domains created within the subscription irrespective of the resourceGroup IPage <Domain> domainsInAzureSubscription = this.EventGridManagementClient.Domains.ListBySubscriptionAsync(null, 100).Result; var domainsInAzureSubscriptionList = new List <Domain>(); if (domainsInAzureSubscription.Any()) { domainsInAzureSubscriptionList.AddRange(domainsInAzureSubscription); var nextLink = domainsInAzureSubscription.NextPageLink; while (nextLink != null) { try { domainsInAzureSubscription = this.EventGridManagementClient.Domains.ListBySubscriptionNextAsync(nextLink).Result; domainsInAzureSubscriptionList.AddRange(domainsInAzureSubscription); nextLink = domainsInAzureSubscription.NextPageLink; } catch (Exception ex) { Console.WriteLine(ex); break; } } } Assert.NotNull(domainsInAzureSubscriptionList); Assert.True(domainsInAzureSubscriptionList.Count() >= 1); Assert.Contains(domainsInAzureSubscriptionList, t => t.Name == domainName); var replaceDomainTagsDictionary = new Dictionary <string, string>() { { "replacedTag1", "replacedValue1" }, { "replacedTag2", "replacedValue2" } }; // Replace the domain domain.Tags = replaceDomainTagsDictionary; var replaceDomainResponse = this.EventGridManagementClient.Domains.CreateOrUpdateAsync(resourceGroup, domainName, domain).Result; Assert.Contains(replaceDomainResponse.Tags, tag => tag.Key == "replacedTag1"); Assert.DoesNotContain(replaceDomainResponse.Tags, tag => tag.Key == "originalTag1"); // Update the domain with tags & allow traffic from all ips var domainUpdateParameters = new DomainUpdateParameters() { Tags = new Dictionary <string, string>() { { "updatedTag1", "updatedValue1" }, { "updatedTag2", "updatedValue2" } }, PublicNetworkAccess = PublicNetworkAccess.Enabled, }; var updateDomainResponse = this.EventGridManagementClient.Domains.UpdateAsync(resourceGroup, domainName, domainUpdateParameters).Result; Assert.Contains(updateDomainResponse.Tags, tag => tag.Key == "updatedTag1"); Assert.DoesNotContain(updateDomainResponse.Tags, tag => tag.Key == "replacedTag1"); Assert.True(updateDomainResponse.PublicNetworkAccess == PublicNetworkAccess.Enabled); Assert.Null(updateDomainResponse.InboundIpRules); // Update the Topic with IP filtering feature domain.PublicNetworkAccess = PublicNetworkAccess.Disabled; domain.InboundIpRules = new List <InboundIpRule>(); domain.InboundIpRules.Add(new InboundIpRule() { Action = IpActionType.Allow, IpMask = "12.35.67.98" }); domain.InboundIpRules.Add(new InboundIpRule() { Action = IpActionType.Allow, IpMask = "12.35.90.100" }); var updateDomainResponseWithIpFilteringFeature = this.EventGridManagementClient.Domains.CreateOrUpdateAsync(resourceGroup, domainName, domain).Result; Assert.False(updateDomainResponseWithIpFilteringFeature.PublicNetworkAccess == PublicNetworkAccess.Enabled); Assert.True(updateDomainResponseWithIpFilteringFeature.InboundIpRules.Count() == 2); // Create domain topic manually. DomainTopic createDomainTopicResponse = this.EventGridManagementClient.DomainTopics.CreateOrUpdateAsync(resourceGroup, domainName, domainTopicName1).Result; Assert.NotNull(createDomainTopicResponse); Assert.Equal(createDomainTopicResponse.Name, domainTopicName1); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // Get the created domain Topic var getDomainTopicResponse = this.EventGridManagementClient.DomainTopics.Get(resourceGroup, domainName, domainTopicName1); if (string.Compare(getDomainTopicResponse.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getDomainTopicResponse = this.EventGridManagementClient.DomainTopics.Get(resourceGroup, domainName, domainTopicName1); Assert.NotNull(getDomainTopicResponse); Assert.Equal("Succeeded", getDomainTopicResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); createDomainTopicResponse = this.EventGridManagementClient.DomainTopics.CreateOrUpdateAsync(resourceGroup, domainName, domainTopicName2).Result; Assert.NotNull(createDomainTopicResponse); Assert.Equal(createDomainTopicResponse.Name, domainTopicName2); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // Get the created domain Topic getDomainTopicResponse = this.EventGridManagementClient.DomainTopics.Get(resourceGroup, domainName, domainTopicName2); if (string.Compare(getDomainTopicResponse.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getDomainTopicResponse = this.EventGridManagementClient.DomainTopics.Get(resourceGroup, domainName, domainTopicName2); Assert.NotNull(getDomainTopicResponse); Assert.Equal("Succeeded", getDomainTopicResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); // Get all domainTopics created within a resourceGroup IPage <DomainTopic> domainTopicsInDomainPage = this.EventGridManagementClient.DomainTopics.ListByDomainAsync(resourceGroup, domainName).Result; var domainTopicsInResourceGroupList = new List <DomainTopic>(); if (domainTopicsInDomainPage.Any()) { domainTopicsInResourceGroupList.AddRange(domainTopicsInDomainPage); var nextLink = domainTopicsInDomainPage.NextPageLink; while (nextLink != null) { domainTopicsInDomainPage = this.EventGridManagementClient.DomainTopics.ListByDomainNextAsync(nextLink).Result; domainTopicsInResourceGroupList.AddRange(domainTopicsInDomainPage); nextLink = domainTopicsInDomainPage.NextPageLink; } } Assert.NotNull(domainTopicsInResourceGroupList); Assert.True(domainTopicsInResourceGroupList.Count() == 2); Assert.Contains(domainTopicsInResourceGroupList, t => t.Name == domainTopicName1); Assert.Contains(domainTopicsInResourceGroupList, t => t.Name == domainTopicName2); Assert.True(domainTopicsInResourceGroupList.All(ns => ns.Id.Contains(resourceGroup))); Assert.True(domainTopicsInResourceGroupList.All(ns => ns.Id.Contains(domainName))); // Delete domainTopics this.EventGridManagementClient.DomainTopics.DeleteAsync(resourceGroup, domainName, domainTopicName1).Wait(); this.EventGridManagementClient.DomainTopics.DeleteAsync(resourceGroup, domainName, domainTopicName2).Wait(); // Delete domain this.EventGridManagementClient.Domains.DeleteAsync(resourceGroup, domainName).Wait(); } }
public void DomainCreateGetUpdateDelete() { using (MockContext context = MockContext.Start(this.GetType().FullName)) { this.InitializeClients(context); var location = this.ResourceManagementClient.GetLocationFromProvider(); var resourceGroup = this.ResourceManagementClient.TryGetResourceGroup(location); if (string.IsNullOrWhiteSpace(resourceGroup)) { resourceGroup = TestUtilities.GenerateName(EventGridManagementHelper.ResourceGroupPrefix); this.ResourceManagementClient.TryRegisterResourceGroup(location, resourceGroup); } var domainName = TestUtilities.GenerateName(EventGridManagementHelper.DomainPrefix); var domainTopicName1 = TestUtilities.GenerateName(EventGridManagementHelper.DomainTopicPrefix); var domainTopicName2 = TestUtilities.GenerateName(EventGridManagementHelper.DomainTopicPrefix); // Temporarily commenting this out as this is not yet enabled for the new API version // var operationsResponse = this.EventGridManagementClient.Operations.List(); var originalTagsDictionary = new Dictionary <string, string>() { { "originalTag1", "originalValue1" }, { "originalTag2", "originalValue2" } }; Domain domain = new Domain() { Location = location, Tags = originalTagsDictionary }; var createDomainResponse = this.EventGridManagementClient.Domains.CreateOrUpdateAsync(resourceGroup, domainName, domain).Result; Assert.NotNull(createDomainResponse); Assert.Equal(createDomainResponse.Name, domainName); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // Get the created domain var getDomainResponse = this.EventGridManagementClient.Domains.Get(resourceGroup, domainName); if (string.Compare(getDomainResponse.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getDomainResponse = this.EventGridManagementClient.Domains.Get(resourceGroup, domainName); Assert.NotNull(getDomainResponse); Assert.Equal("Succeeded", getDomainResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal(location, getDomainResponse.Location, StringComparer.CurrentCultureIgnoreCase); Assert.Contains(getDomainResponse.Tags, tag => tag.Key == "originalTag1"); // Get all domains created within a resourceGroup IPage <Domain> domainsInResourceGroupPage = this.EventGridManagementClient.Domains.ListByResourceGroupAsync(resourceGroup).Result; var domainsInResourceGroupList = new List <Domain>(); if (domainsInResourceGroupPage.Any()) { domainsInResourceGroupList.AddRange(domainsInResourceGroupPage); var nextLink = domainsInResourceGroupPage.NextPageLink; while (nextLink != null) { domainsInResourceGroupPage = this.EventGridManagementClient.Domains.ListByResourceGroupNextAsync(nextLink).Result; domainsInResourceGroupList.AddRange(domainsInResourceGroupPage); nextLink = domainsInResourceGroupPage.NextPageLink; } } Assert.NotNull(domainsInResourceGroupList); Assert.True(domainsInResourceGroupList.Count() >= 1); Assert.Contains(domainsInResourceGroupList, t => t.Name == domainName); Assert.True(domainsInResourceGroupList.All(ns => ns.Id.Contains(resourceGroup))); IPage <Domain> domainsInResourceGroupPageWithTop = this.EventGridManagementClient.Domains.ListByResourceGroupAsync(resourceGroup, null, 5).Result; var domainsInResourceGroupListWithTop = new List <Domain>(); if (domainsInResourceGroupPageWithTop.Any()) { domainsInResourceGroupListWithTop.AddRange(domainsInResourceGroupPageWithTop); var nextLink = domainsInResourceGroupPageWithTop.NextPageLink; while (nextLink != null) { domainsInResourceGroupPageWithTop = this.EventGridManagementClient.Domains.ListByResourceGroupNextAsync(nextLink).Result; domainsInResourceGroupListWithTop.AddRange(domainsInResourceGroupPageWithTop); nextLink = domainsInResourceGroupPageWithTop.NextPageLink; } } Assert.NotNull(domainsInResourceGroupListWithTop); Assert.True(domainsInResourceGroupListWithTop.Count() >= 1); Assert.Contains(domainsInResourceGroupListWithTop, t => t.Name == domainName); Assert.True(domainsInResourceGroupListWithTop.All(ns => ns.Id.Contains(resourceGroup))); // Get all domains created within the subscription irrespective of the resourceGroup IPage <Domain> domainsInAzureSubscription = this.EventGridManagementClient.Domains.ListBySubscriptionAsync(null, 100).Result; var domainsInAzureSubscriptionList = new List <Domain>(); if (domainsInAzureSubscription.Any()) { domainsInAzureSubscriptionList.AddRange(domainsInAzureSubscription); var nextLink = domainsInAzureSubscription.NextPageLink; while (nextLink != null) { try { domainsInAzureSubscription = this.EventGridManagementClient.Domains.ListBySubscriptionNextAsync(nextLink).Result; domainsInAzureSubscriptionList.AddRange(domainsInAzureSubscription); nextLink = domainsInAzureSubscription.NextPageLink; } catch (Exception ex) { Console.WriteLine(ex); } } } Assert.NotNull(domainsInAzureSubscriptionList); Assert.True(domainsInAzureSubscriptionList.Count() >= 1); Assert.Contains(domainsInAzureSubscriptionList, t => t.Name == domainName); var replaceDomainTagsDictionary = new Dictionary <string, string>() { { "replacedTag1", "replacedValue1" }, { "replacedTag2", "replacedValue2" } }; // Replace the domain domain.Tags = replaceDomainTagsDictionary; var replaceDomainResponse = this.EventGridManagementClient.Domains.CreateOrUpdateAsync(resourceGroup, domainName, domain).Result; Assert.Contains(replaceDomainResponse.Tags, tag => tag.Key == "replacedTag1"); Assert.DoesNotContain(replaceDomainResponse.Tags, tag => tag.Key == "originalTag1"); // Update the domain var updateDomainTagsDictionary = new Dictionary <string, string>() { { "updatedTag1", "updatedValue1" }, { "updatedTag2", "updatedValue2" } }; var updateDomainResponse = this.EventGridManagementClient.Domains.UpdateAsync(resourceGroup, domainName, updateDomainTagsDictionary).Result; Assert.Contains(updateDomainResponse.Tags, tag => tag.Key == "updatedTag1"); Assert.DoesNotContain(updateDomainResponse.Tags, tag => tag.Key == "replacedTag1"); // Create domain topic manually. DomainTopic createDomainTopicResponse = this.EventGridManagementClient.DomainTopics.CreateOrUpdateAsync(resourceGroup, domainName, domainTopicName1).Result; Assert.NotNull(createDomainTopicResponse); Assert.Equal(createDomainTopicResponse.Name, domainTopicName1); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // Get the created domain Topic var getDomainTopicResponse = this.EventGridManagementClient.DomainTopics.Get(resourceGroup, domainName, domainTopicName1); if (string.Compare(getDomainTopicResponse.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getDomainTopicResponse = this.EventGridManagementClient.DomainTopics.Get(resourceGroup, domainName, domainTopicName1); Assert.NotNull(getDomainTopicResponse); Assert.Equal("Succeeded", getDomainTopicResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); createDomainTopicResponse = this.EventGridManagementClient.DomainTopics.CreateOrUpdateAsync(resourceGroup, domainName, domainTopicName2).Result; Assert.NotNull(createDomainTopicResponse); Assert.Equal(createDomainTopicResponse.Name, domainTopicName2); TestUtilities.Wait(TimeSpan.FromSeconds(5)); // Get the created domain Topic getDomainTopicResponse = this.EventGridManagementClient.DomainTopics.Get(resourceGroup, domainName, domainTopicName2); if (string.Compare(getDomainTopicResponse.ProvisioningState, "Succeeded", true) != 0) { TestUtilities.Wait(TimeSpan.FromSeconds(5)); } getDomainTopicResponse = this.EventGridManagementClient.DomainTopics.Get(resourceGroup, domainName, domainTopicName2); Assert.NotNull(getDomainTopicResponse); Assert.Equal("Succeeded", getDomainTopicResponse.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); // Get all domainTopics created within a resourceGroup IPage <DomainTopic> domainTopicsInDomainPage = this.EventGridManagementClient.DomainTopics.ListByDomainAsync(resourceGroup, domainName).Result; var domainTopicsInResourceGroupList = new List <DomainTopic>(); if (domainTopicsInDomainPage.Any()) { domainTopicsInResourceGroupList.AddRange(domainTopicsInDomainPage); var nextLink = domainTopicsInDomainPage.NextPageLink; while (nextLink != null) { domainTopicsInDomainPage = this.EventGridManagementClient.DomainTopics.ListByDomainNextAsync(nextLink).Result; domainTopicsInResourceGroupList.AddRange(domainTopicsInDomainPage); nextLink = domainTopicsInDomainPage.NextPageLink; } } Assert.NotNull(domainTopicsInResourceGroupList); Assert.True(domainTopicsInResourceGroupList.Count() == 2); Assert.Contains(domainTopicsInResourceGroupList, t => t.Name == domainTopicName1); Assert.Contains(domainTopicsInResourceGroupList, t => t.Name == domainTopicName2); Assert.True(domainTopicsInResourceGroupList.All(ns => ns.Id.Contains(resourceGroup))); Assert.True(domainTopicsInResourceGroupList.All(ns => ns.Id.Contains(domainName))); // Delete domainTopics this.EventGridManagementClient.DomainTopics.DeleteAsync(resourceGroup, domainName, domainTopicName1).Wait(); this.EventGridManagementClient.DomainTopics.DeleteAsync(resourceGroup, domainName, domainTopicName2).Wait(); // Delete domain this.EventGridManagementClient.Domains.DeleteAsync(resourceGroup, domainName).Wait(); } }
protected void Snapshot_List_Execute(string diskCreateOption, string methodName, int?diskSizeGB = null) { using (MockContext context = MockContext.Start(this.GetType().FullName, methodName)) { EnsureClientsInitialized(context); // Data var rgName1 = TestUtilities.GenerateName(TestPrefix); var rgName2 = TestUtilities.GenerateName(TestPrefix); var diskName1 = TestUtilities.GenerateName(DiskNamePrefix); var diskName2 = TestUtilities.GenerateName(DiskNamePrefix); var snapshotName1 = TestUtilities.GenerateName(DiskNamePrefix); var snapshotName2 = TestUtilities.GenerateName(DiskNamePrefix); Disk disk1 = GenerateDefaultDisk(diskCreateOption, rgName1, diskSizeGB); Disk disk2 = GenerateDefaultDisk(diskCreateOption, rgName2, diskSizeGB); try { // ********** // SETUP // ********** // Create resource groups m_ResourcesClient.ResourceGroups.CreateOrUpdate(rgName1, new ResourceGroup { Location = DiskRPLocation }); m_ResourcesClient.ResourceGroups.CreateOrUpdate(rgName2, new ResourceGroup { Location = DiskRPLocation }); // Put 4 disks, 2 in each resource group Disk diskOut11 = m_CrpClient.Disks.CreateOrUpdate(rgName1, diskName1, disk1); Disk diskOut12 = m_CrpClient.Disks.CreateOrUpdate(rgName1, diskName2, disk2); Disk diskOut21 = m_CrpClient.Disks.CreateOrUpdate(rgName2, diskName1, disk1); Disk diskOut22 = m_CrpClient.Disks.CreateOrUpdate(rgName2, diskName2, disk2); // Generate 4 snapshots using disks info Snapshot snapshot11 = GenerateDefaultSnapshot(diskOut11.Id); Snapshot snapshot12 = GenerateDefaultSnapshot(diskOut12.Id, SnapshotStorageAccountTypes.StandardZRS); Snapshot snapshot21 = GenerateDefaultSnapshot(diskOut21.Id); Snapshot snapshot22 = GenerateDefaultSnapshot(diskOut22.Id); // Put 4 snapshots, 2 in each resource group m_CrpClient.Snapshots.CreateOrUpdate(rgName1, snapshotName1, snapshot11); m_CrpClient.Snapshots.CreateOrUpdate(rgName1, snapshotName2, snapshot12); m_CrpClient.Snapshots.CreateOrUpdate(rgName2, snapshotName1, snapshot21); m_CrpClient.Snapshots.CreateOrUpdate(rgName2, snapshotName2, snapshot22); // ********** // TEST // ********** // List snapshots under resource group IPage <Snapshot> snapshotsOut = m_CrpClient.Snapshots.ListByResourceGroup(rgName1); Assert.Equal(2, snapshotsOut.Count()); Assert.Null(snapshotsOut.NextPageLink); snapshotsOut = m_CrpClient.Snapshots.ListByResourceGroup(rgName2); Assert.Equal(2, snapshotsOut.Count()); Assert.Null(snapshotsOut.NextPageLink); // List snapshots under subscription snapshotsOut = m_CrpClient.Snapshots.List(); Assert.True(snapshotsOut.Count() >= 4); if (snapshotsOut.NextPageLink != null) { snapshotsOut = m_CrpClient.Snapshots.ListNext(snapshotsOut.NextPageLink); Assert.True(snapshotsOut.Any()); } } finally { // Delete resource group m_ResourcesClient.ResourceGroups.Delete(rgName1); m_ResourcesClient.ResourceGroups.Delete(rgName2); } } }
protected void Disk_List_Execute(string diskCreateOption, string methodName, int?diskSizeGB = null) { using (MockContext context = MockContext.Start(this.GetType().FullName, methodName)) { EnsureClientsInitialized(context); // Data var rgName1 = TestUtilities.GenerateName(TestPrefix); var rgName2 = TestUtilities.GenerateName(TestPrefix); var diskName1 = TestUtilities.GenerateName(DiskNamePrefix); var diskName2 = TestUtilities.GenerateName(DiskNamePrefix); Disk disk1 = GenerateDefaultDisk(diskCreateOption, rgName1, diskSizeGB); Disk disk2 = GenerateDefaultDisk(diskCreateOption, rgName2, diskSizeGB); try { // ********** // SETUP // ********** // Create resource groups, unless create option is import in which case resource group will be created with vm if (diskCreateOption != DiskCreateOption.Import) { m_ResourcesClient.ResourceGroups.CreateOrUpdate(rgName1, new ResourceGroup { Location = DiskRPLocation }); m_ResourcesClient.ResourceGroups.CreateOrUpdate(rgName2, new ResourceGroup { Location = DiskRPLocation }); } // Put 4 disks, 2 in each resource group m_CrpClient.Disks.CreateOrUpdate(rgName1, diskName1, disk1); m_CrpClient.Disks.CreateOrUpdate(rgName1, diskName2, disk2); m_CrpClient.Disks.CreateOrUpdate(rgName2, diskName1, disk1); m_CrpClient.Disks.CreateOrUpdate(rgName2, diskName2, disk2); // ********** // TEST // ********** // List disks under resource group IPage <Disk> disksOut = m_CrpClient.Disks.ListByResourceGroup(rgName1); Assert.Equal(2, disksOut.Count()); Assert.Null(disksOut.NextPageLink); disksOut = m_CrpClient.Disks.ListByResourceGroup(rgName2); Assert.Equal(2, disksOut.Count()); Assert.Null(disksOut.NextPageLink); // List disks under subscription disksOut = m_CrpClient.Disks.List(); Assert.True(disksOut.Count() >= 4); if (disksOut.NextPageLink != null) { disksOut = m_CrpClient.Disks.ListNext(disksOut.NextPageLink); Assert.True(disksOut.Any()); } } finally { // Delete resource group m_ResourcesClient.ResourceGroups.Delete(rgName1); m_ResourcesClient.ResourceGroups.Delete(rgName2); } } }
protected void DiskEncryptionSet_List_Execute(string methodName, string location = null) { using (MockContext context = MockContext.Start(this.GetType(), methodName)) { EnsureClientsInitialized(context); DiskRPLocation = location ?? DiskRPLocation; // Data var rgName1 = TestUtilities.GenerateName(TestPrefix); var rgName2 = TestUtilities.GenerateName(TestPrefix); var desName1 = TestUtilities.GenerateName(DiskNamePrefix); var desName2 = TestUtilities.GenerateName(DiskNamePrefix); DiskEncryptionSet des1 = GenerateDefaultDiskEncryptionSet(DiskRPLocation); DiskEncryptionSet des2 = GenerateDefaultDiskEncryptionSet(DiskRPLocation); try { // ********** // SETUP // ********** // Create resource groups m_ResourcesClient.ResourceGroups.CreateOrUpdate(rgName1, new ResourceGroup { Location = DiskRPLocation }); m_ResourcesClient.ResourceGroups.CreateOrUpdate(rgName2, new ResourceGroup { Location = DiskRPLocation }); // Put 4 diskEncryptionSets, 2 in each resource group m_CrpClient.DiskEncryptionSets.CreateOrUpdate(rgName1, desName1, des1); m_CrpClient.DiskEncryptionSets.CreateOrUpdate(rgName1, desName2, des2); m_CrpClient.DiskEncryptionSets.CreateOrUpdate(rgName2, desName1, des1); m_CrpClient.DiskEncryptionSets.CreateOrUpdate(rgName2, desName2, des2); // ********** // TEST // ********** // List diskEncryptionSets under resource group IPage <DiskEncryptionSet> dessOut = m_CrpClient.DiskEncryptionSets.ListByResourceGroup(rgName1); Assert.Equal(2, dessOut.Count()); Assert.Null(dessOut.NextPageLink); dessOut = m_CrpClient.DiskEncryptionSets.ListByResourceGroup(rgName2); Assert.Equal(2, dessOut.Count()); Assert.Null(dessOut.NextPageLink); // List diskEncryptionSets under subscription dessOut = m_CrpClient.DiskEncryptionSets.List(); Assert.True(dessOut.Count() >= 4); if (dessOut.NextPageLink != null) { dessOut = m_CrpClient.DiskEncryptionSets.ListNext(dessOut.NextPageLink); Assert.True(dessOut.Any()); } // Delete diskEncryptionSets m_CrpClient.DiskEncryptionSets.Delete(rgName1, desName1); m_CrpClient.DiskEncryptionSets.Delete(rgName1, desName2); m_CrpClient.DiskEncryptionSets.Delete(rgName2, desName1); m_CrpClient.DiskEncryptionSets.Delete(rgName2, desName2); } finally { // Delete resource group m_ResourcesClient.ResourceGroups.Delete(rgName1); m_ResourcesClient.ResourceGroups.Delete(rgName2); } } }