Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests for resourcemanager version update #24872

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions sdk/compute/Azure.ResourceManager.Compute/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Before creating an availability set, we need to have a resource group.

```C# Snippet:Readme_GetResourceGroupContainer
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();
// With the container, we can create a new resource group with an specific name
string rgName = "myRgName";
Expand All @@ -79,7 +79,7 @@ AvailabilitySet availabilitySet = lro.Value;
// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup container for that subscription
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();

string rgName = "myRgName";
Expand All @@ -100,7 +100,7 @@ await foreach (AvailabilitySet availabilitySet in response)
// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup container for that subscription
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();

// With the container, we can create a new resource group with an specific name
Expand All @@ -123,7 +123,7 @@ AvailabilitySet updatedAvailabilitySet = await availabilitySet.UpdateAsync(updat
// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup container for that subscription
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();

// With the container, we can create a new resource group with an specific name
Expand All @@ -142,7 +142,7 @@ If you just want to verify if the availability set exists, you can use the funct

```C# Snippet:Managing_Availability_Set_CheckIfExistsForAvailabilitySet
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();

string rgName = "myRgName";
Expand All @@ -166,7 +166,7 @@ If you want to first check if the availability set exists, and if it does, you w
// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup container for that subscription
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();

string rgName = "myRgName";
Expand All @@ -190,7 +190,7 @@ if (availabilitySet == null)
// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup container for that subscription
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();

string rgName = "myRgName";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ using Azure.ResourceManager.Resources;
using NUnit.Framework;
```

When you first create your ARM client, choose the subscription you're going to work in. There's a convenient `DefaultSubscription` property that returns the default subscription configured for your user:
When you first create your ARM client, choose the subscription you're going to work in. You can use the `GetDefaultSubscription`/`GetDefaultSubscriptionAsync` methods to return the default subscription configured for your user:

```C# Snippet:Readme_DefaultSubscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = armClient.GetDefaultSubscription();
```

This is a scoped operations object, and any operations you perform will be done under that subscription. From this object, you have access to all children via container objects. Or you can access individual children by ID.

```C# Snippet:Readme_GetResourceGroupContainer
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();
// With the container, we can create a new resource group with an specific name
string rgName = "myRgName";
Expand All @@ -39,7 +39,7 @@ Now that we have the resource group created, we can manage the disks inside this

```C# Snippet:Managing_Disks_CreateADisk
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
Expand All @@ -64,7 +64,7 @@ Disk disk = lro.Value;

```C# Snippet:Managing_Disks_ListAllDisks
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
Expand All @@ -82,7 +82,7 @@ await foreach (Disk disk in response)

```C# Snippet:Managing_Disks_DeleteDisk
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ using Azure.ResourceManager.Resources;
using NUnit.Framework;
```

When you first create your ARM client, choose the subscription you're going to work in. There's a convenient `DefaultSubscription` property that returns the default subscription configured for your user:
When you first create your ARM client, choose the subscription you're going to work in. You can use the `GetDefaultSubscription`/`GetDefaultSubscriptionAsync` methods to return the default subscription configured for your user:

```C# Snippet:Readme_DefaultSubscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = armClient.GetDefaultSubscription();
```

This is a scoped operations object, and any operations you perform will be done under that subscription. From this object, you have access to all children via container objects. Or you can access individual children by ID.

```C# Snippet:Readme_GetResourceGroupContainer
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();
// With the container, we can create a new resource group with an specific name
string rgName = "myRgName";
Expand All @@ -40,7 +40,7 @@ Please notice that before we create a virtual machine, at lease we need to creat

```C# Snippet:Managing_VirtualMachines_CreateAVirtualMachine
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
Expand Down Expand Up @@ -112,7 +112,7 @@ VirtualMachine vm = lro.Value;

```C# Snippet:Managing_VirtualMachines_ListAllVirtualMachines
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
Expand All @@ -130,7 +130,7 @@ await foreach (VirtualMachine vm in response)

```C# Snippet:Managing_VirtualMachines_DeleteVirtualMachine
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public class ComputeTestBase : ManagementRecordedTestBase<ComputeTestEnvironment
{
protected Location DefaultLocation => Location.WestUS2;
protected ArmClient Client { get; private set; }
protected Subscription DefaultSubscription => Client.DefaultSubscription;

protected Subscription DefaultSubscription { get; private set; }
public ComputeTestBase(bool isAsync) : base(isAsync)
{
}
Expand All @@ -25,9 +24,10 @@ public ComputeTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync, mode
}

[SetUp]
public void CreateCommonClient()
public async Task CreateCommonClient()
{
Client = GetArmClient();
DefaultSubscription = await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false);
}

protected async Task<ResourceGroup> CreateResourceGroupAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void DefaultSubscription()
{
#region Snippet:Readme_DefaultSubscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = armClient.GetDefaultSubscription();
#endregion
}

Expand All @@ -42,7 +42,7 @@ public async Task CreateResourceGroup()
{
#region Snippet:Readme_GetResourceGroupContainer
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();
// With the container, we can create a new resource group with an specific name
string rgName = "myRgName";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task CreateAvailabilitySet()
// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup container for that subscription
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();

// With the container, we can create a new resource group with an specific name
Expand All @@ -45,7 +45,7 @@ public async Task UpdateAvailabilitySet()
// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup container for that subscription
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();

// With the container, we can create a new resource group with an specific name
Expand All @@ -71,7 +71,7 @@ public async Task DeleteAvailabilitySet()
// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup container for that subscription
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();

// With the container, we can create a new resource group with an specific name
Expand All @@ -91,7 +91,7 @@ public async Task CheckIfExists()
{
#region Snippet:Managing_Availability_Set_CheckIfExistsForAvailabilitySet
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();

string rgName = "myRgName";
Expand All @@ -118,7 +118,7 @@ public async Task GetAllAvailabilitySets()
// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup container for that subscription
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();

string rgName = "myRgName";
Expand All @@ -142,7 +142,7 @@ public async Task GetIfExistsAvailabilitySet()
// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup container for that subscription
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();

string rgName = "myRgName";
Expand Down Expand Up @@ -170,7 +170,7 @@ public async Task AddTagToAvailabilitySet()
// First, initialize the ArmClient and get the default subscription
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
// Now we get a ResourceGroup container for that subscription
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroupContainer rgContainer = subscription.GetResourceGroups();

string rgName = "myRgName";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task CreateDisk()
{
#region Snippet:Managing_Disks_CreateADisk
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
Expand Down Expand Up @@ -48,7 +48,7 @@ public async Task ListDisks()
{
#region Snippet:Managing_Disks_ListAllDisks
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
Expand All @@ -69,7 +69,7 @@ public async Task DeleteDisk()
{
#region Snippet:Managing_Disks_DeleteDisk
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task CreateVirtualMachine()
{
#region Snippet:Managing_VirtualMachines_CreateAVirtualMachine
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
Expand Down Expand Up @@ -95,7 +95,7 @@ public async Task ListAllVirtualMachines()
{
#region Snippet:Managing_VirtualMachines_ListAllVirtualMachines
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
Expand All @@ -116,7 +116,7 @@ public async Task DeleteVirtualMachine()
{
#region Snippet:Managing_VirtualMachines_DeleteVirtualMachine
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
Subscription subscription = armClient.DefaultSubscription;
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
// first we need to get the resource group
string rgName = "myRgName";
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);
Expand Down
Loading