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

Generate sample code for ResourceManager #37550

Merged
merged 3 commits into from
Jul 21, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.ResourceManager.Perf"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Test.Perf", "..\..\..\common\Perf\Azure.Test.Perf\Azure.Test.Perf.csproj", "{AD397048-D114-4A32-8F35-64E5C72A4697}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.ResourceManager.Samples", "samples\Azure.ResourceManager.Samples.csproj", "{0D3137B9-8FB5-46E3-9033-84EF6DBE8D1E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -61,6 +63,10 @@ Global
{AD397048-D114-4A32-8F35-64E5C72A4697}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD397048-D114-4A32-8F35-64E5C72A4697}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD397048-D114-4A32-8F35-64E5C72A4697}.Release|Any CPU.Build.0 = Release|Any CPU
{0D3137B9-8FB5-46E3-9033-84EF6DBE8D1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0D3137B9-8FB5-46E3-9033-84EF6DBE8D1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0D3137B9-8FB5-46E3-9033-84EF6DBE8D1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0D3137B9-8FB5-46E3-9033-84EF6DBE8D1E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk\">
<ItemGroup>
<PackageReference Include="Azure.Identity"/>
<PackageReference Include="NUnit"/>
<PackageReference Include="NUnit3TestAdapter"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\Azure.ResourceManager.csproj"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated code configuration

Run `dotnet build /t:GenerateTests` to generate code.

# Azure.ResourceManager.Tests

> see https://aka.ms/autorest
``` yaml
require: ../src/autorest.md
include-x-ms-examples-original-file: true
testgen:
sample: true
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// <auto-generated/>

#nullable disable

using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Resources;

namespace Azure.ResourceManager.Resources.Samples
{
public partial class Sample_DataPolicyManifestCollection
{
// Retrieve a data policy manifest by policy mode
[NUnit.Framework.Test]
[NUnit.Framework.Ignore("Only verifying that the sample builds")]
public async Task Get_RetrieveADataPolicyManifestByPolicyMode()
{
// Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/getDataPolicyManifest.json
// this example is just showing the usage of "DataPolicyManifests_GetByPolicyMode" operation, for the dependent resources, they will have to be created separately.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);

// this example assumes you already have this TenantResource created on azure
// for more information of creating TenantResource, please refer to the document of TenantResource
var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current;

// get the collection of this DataPolicyManifestResource
DataPolicyManifestCollection collection = tenant.GetDataPolicyManifests();

// invoke the operation
string policyMode = "Microsoft.KeyVault.Data";
DataPolicyManifestResource result = await collection.GetAsync(policyMode);

// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
DataPolicyManifestData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
}

// Retrieve a data policy manifest by policy mode
[NUnit.Framework.Test]
[NUnit.Framework.Ignore("Only verifying that the sample builds")]
public async Task Exists_RetrieveADataPolicyManifestByPolicyMode()
{
// Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/getDataPolicyManifest.json
// this example is just showing the usage of "DataPolicyManifests_GetByPolicyMode" operation, for the dependent resources, they will have to be created separately.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);

// this example assumes you already have this TenantResource created on azure
// for more information of creating TenantResource, please refer to the document of TenantResource
var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current;

// get the collection of this DataPolicyManifestResource
DataPolicyManifestCollection collection = tenant.GetDataPolicyManifests();

// invoke the operation
string policyMode = "Microsoft.KeyVault.Data";
bool result = await collection.ExistsAsync(policyMode);

Console.WriteLine($"Succeeded: {result}");
}

// List data policy manifests
[NUnit.Framework.Test]
[NUnit.Framework.Ignore("Only verifying that the sample builds")]
public async Task GetAll_ListDataPolicyManifests()
{
// Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/listDataPolicyManifests.json
// this example is just showing the usage of "DataPolicyManifests_List" operation, for the dependent resources, they will have to be created separately.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);

// this example assumes you already have this TenantResource created on azure
// for more information of creating TenantResource, please refer to the document of TenantResource
var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current;

// get the collection of this DataPolicyManifestResource
DataPolicyManifestCollection collection = tenant.GetDataPolicyManifests();

// invoke the operation and iterate over the result
await foreach (DataPolicyManifestResource item in collection.GetAllAsync())
{
// the variable item is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
DataPolicyManifestData resourceData = item.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
}

Console.WriteLine($"Succeeded");
}

// List data policy manifests with namespace filter
[NUnit.Framework.Test]
[NUnit.Framework.Ignore("Only verifying that the sample builds")]
public async Task GetAll_ListDataPolicyManifestsWithNamespaceFilter()
{
// Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/listDataPolicyManifestsNamespaceFilter.json
// this example is just showing the usage of "DataPolicyManifests_List" operation, for the dependent resources, they will have to be created separately.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);

// this example assumes you already have this TenantResource created on azure
// for more information of creating TenantResource, please refer to the document of TenantResource
var tenant = client.GetTenants().GetAllAsync().GetAsyncEnumerator().Current;

// get the collection of this DataPolicyManifestResource
DataPolicyManifestCollection collection = tenant.GetDataPolicyManifests();

// invoke the operation and iterate over the result
string filter = "namespace eq 'Microsoft.KeyVault'";
await foreach (DataPolicyManifestResource item in collection.GetAllAsync(filter: filter))
{
// the variable item is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
DataPolicyManifestData resourceData = item.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
}

Console.WriteLine($"Succeeded");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// <auto-generated/>

#nullable disable

using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Resources;

namespace Azure.ResourceManager.Resources.Samples
{
public partial class Sample_DataPolicyManifestResource
{
// Retrieve a data policy manifest by policy mode
[NUnit.Framework.Test]
[NUnit.Framework.Ignore("Only verifying that the sample builds")]
public async Task Get_RetrieveADataPolicyManifestByPolicyMode()
{
// Generated from example definition: specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/getDataPolicyManifest.json
// this example is just showing the usage of "DataPolicyManifests_GetByPolicyMode" operation, for the dependent resources, they will have to be created separately.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);

// this example assumes you already have this DataPolicyManifestResource created on azure
// for more information of creating DataPolicyManifestResource, please refer to the document of DataPolicyManifestResource
string policyMode = "Microsoft.KeyVault.Data";
ResourceIdentifier dataPolicyManifestResourceId = DataPolicyManifestResource.CreateResourceIdentifier(policyMode);
DataPolicyManifestResource dataPolicyManifest = client.GetDataPolicyManifestResource(dataPolicyManifestResourceId);

// invoke the operation
DataPolicyManifestResource result = await dataPolicyManifest.GetAsync();

// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
DataPolicyManifestData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// <auto-generated/>

#nullable disable

using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Resources;

namespace Azure.ResourceManager.Resources.Samples
{
public partial class Sample_FeatureCollection
{
// List provider Features
[NUnit.Framework.Test]
[NUnit.Framework.Ignore("Only verifying that the sample builds")]
public async Task GetAll_ListProviderFeatures()
{
// Generated from example definition: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/listProviderFeatures.json
// this example is just showing the usage of "Features_List" operation, for the dependent resources, they will have to be created separately.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);

// this example assumes you already have this ResourceProviderResource created on azure
// for more information of creating ResourceProviderResource, please refer to the document of ResourceProviderResource
string subscriptionId = "subid";
string resourceProviderNamespace = "Resource Provider Namespace";
ResourceIdentifier resourceProviderResourceId = ResourceProviderResource.CreateResourceIdentifier(subscriptionId, resourceProviderNamespace);
ResourceProviderResource resourceProvider = client.GetResourceProviderResource(resourceProviderResourceId);

// get the collection of this FeatureResource
FeatureCollection collection = resourceProvider.GetFeatures();

// invoke the operation and iterate over the result
await foreach (FeatureResource item in collection.GetAllAsync())
{
// the variable item is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
FeatureData resourceData = item.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
}

Console.WriteLine($"Succeeded");
}

// Get feature
[NUnit.Framework.Test]
[NUnit.Framework.Ignore("Only verifying that the sample builds")]
public async Task Get_GetFeature()
{
// Generated from example definition: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/getFeature.json
// this example is just showing the usage of "Features_Get" operation, for the dependent resources, they will have to be created separately.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);

// this example assumes you already have this ResourceProviderResource created on azure
// for more information of creating ResourceProviderResource, please refer to the document of ResourceProviderResource
string subscriptionId = "subid";
string resourceProviderNamespace = "Resource Provider Namespace";
ResourceIdentifier resourceProviderResourceId = ResourceProviderResource.CreateResourceIdentifier(subscriptionId, resourceProviderNamespace);
ResourceProviderResource resourceProvider = client.GetResourceProviderResource(resourceProviderResourceId);

// get the collection of this FeatureResource
FeatureCollection collection = resourceProvider.GetFeatures();

// invoke the operation
string featureName = "feature";
FeatureResource result = await collection.GetAsync(featureName);

// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
FeatureData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
}

// Get feature
[NUnit.Framework.Test]
[NUnit.Framework.Ignore("Only verifying that the sample builds")]
public async Task Exists_GetFeature()
{
// Generated from example definition: specification/resources/resource-manager/Microsoft.Features/stable/2021-07-01/examples/getFeature.json
// this example is just showing the usage of "Features_Get" operation, for the dependent resources, they will have to be created separately.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);

// this example assumes you already have this ResourceProviderResource created on azure
// for more information of creating ResourceProviderResource, please refer to the document of ResourceProviderResource
string subscriptionId = "subid";
string resourceProviderNamespace = "Resource Provider Namespace";
ResourceIdentifier resourceProviderResourceId = ResourceProviderResource.CreateResourceIdentifier(subscriptionId, resourceProviderNamespace);
ResourceProviderResource resourceProvider = client.GetResourceProviderResource(resourceProviderResourceId);

// get the collection of this FeatureResource
FeatureCollection collection = resourceProvider.GetFeatures();

// invoke the operation
string featureName = "feature";
bool result = await collection.ExistsAsync(featureName);

Console.WriteLine($"Succeeded: {result}");
}
}
}
Loading