public async Task TryGetTest()
        {
            ResourceGroup result = await _collection.GetIfExistsAsync(_rgName);

            Assert.NotNull(result);
            Assert.IsTrue(result.Data.Name == _rgName);
            result = await _collection.GetIfExistsAsync("FakeName");

            Assert.IsNull(result);
        }
Пример #2
0
        public async Task TryGetResourceGroup()
        {
            #region Snippet:Readme_TryGetRG
            ArmClient client = new ArmClient(new DefaultAzureCredential());
            Subscription subscription = await client.GetDefaultSubscriptionAsync();
            ResourceGroupCollection resourceGroups = subscription.GetResourceGroups();
            string resourceGroupName = "myRgName";

            ResourceGroup resourceGroup = await resourceGroups.GetIfExistsAsync(resourceGroupName);

            if (resourceGroup == null)
            {
                Console.WriteLine($"Resource Group {resourceGroupName} does not exist.");
            }
            else
            {
                // At this point, we are sure that myRG is a not null Resource Group, so we can use this object to perform any operations we want.
            }
            #endregion Snippet:Readme_TryGetRG
        }