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

5771 - GetGenericResourceOperations in ArmClient #21066

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
10f6ad0
Change the accessbility to virtual for Resource.Id
YalinLi0312 Mar 24, 2021
ccc17c7
merge from usptream
Apr 5, 2021
5060f5c
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
m-nash Apr 12, 2021
9a9a651
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
m-nash Apr 21, 2021
7764cb5
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
YalinLi0312 Apr 23, 2021
832483a
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
YalinLi0312 Apr 28, 2021
32767e0
GetGenericResourceOperations extension method implementation
JonathanCrd May 1, 2021
b10aee2
Create ArmClientTests.cs
JonathanCrd May 1, 2021
3066cd2
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
YalinLi0312 May 6, 2021
9597dc7
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
YalinLi0312 May 6, 2021
86547b0
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
m-nash May 10, 2021
4fa650c
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
m-nash May 10, 2021
47bbbfe
Scenario Tests
JonathanCrd May 12, 2021
7c2ff13
Merge branch 'mgmt-track2' into JonathanCrd-5771-GetGenericResourceOp…
JonathanCrd May 12, 2021
15c7b15
GetGenericResourceOperations for single ID
JonathanCrd May 13, 2021
4a97da9
Single ID tests
JonathanCrd May 13, 2021
da1f08a
Merge remote-tracking branch 'upstream/feature/mgmt-track2' into Jona…
JonathanCrd May 13, 2021
9d145f2
Addressing comments
JonathanCrd May 13, 2021
46b4402
Tests recordings
JonathanCrd May 13, 2021
cd31d06
Tests recordings
JonathanCrd May 13, 2021
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
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;

namespace Azure.ResourceManager.Core
{
/// <summary>
/// A class of extensions for the ARM Client.
/// </summary>
public static class ArmClientExtensions
{
/// <summary>
/// Get the operations for a list of specific resources.
/// </summary>
/// <param name="client"></param>
/// <param name="ids">A list of the IDs of the resources to retrieve.</param>
/// <returns></returns>
public static IList<GenericResourceOperations> GetGenericResourceOperations(this ArmClient client, IEnumerable<string> ids)
{
if (ids == null)
{
throw new ArgumentNullException(nameof(ids));
}

IList<GenericResourceOperations> genericRespirceOperations = new List<GenericResourceOperations>();
foreach (string id in ids)
{
genericRespirceOperations.Add(new GenericResourceOperations(client.DefaultSubscription, id));
}
return genericRespirceOperations;
}

/// <summary>
/// Get the operations for an specific resource.
/// </summary>
/// <param name="client"></param>
/// <param name="id">The ID of the resource to retrieve.</param>
/// <returns></returns>
public static GenericResourceOperations GetGenericResourceOperations(this ArmClient client, string id)
{
if (id == null)
{
throw new ArgumentNullException(nameof(id));
}

return new GenericResourceOperations(client.DefaultSubscription, id);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Threading.Tasks;
using Azure.Core.TestFramework;

namespace Azure.ResourceManager.Core.Tests.Scenario
{
class ArmClientTests : ResourceManagerTestBase
{
private string _rgName;
private readonly string _location = "southcentralus";

public ArmClientTests(bool isAsync)
: base(isAsync)//, RecordedTestMode.Record)
{
}

[OneTimeSetUp]
public async Task LocalOneTimeSetup()
{
_rgName = SessionRecording.GenerateAssetName("testRg-");
var subscription = await GlobalClient.GetSubscriptions().TryGetAsync(SessionEnvironment.SubscriptionId);
_ = subscription.GetResourceGroups().Construct(_location).StartCreateOrUpdateAsync(_rgName).ConfigureAwait(false).GetAwaiter().GetResult().Value;
StopSessionRecording();
}

[TestCase]
public void GetGenericOperationsTests()
{
var ids = new List<string>()
{
$"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/foo-1/",
$"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/foo-2/",
$"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/foo-3/",
$"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/foo-4/"
};

var genericResourceOperationsList = Client.GetGenericResourceOperations(ids);

foreach(GenericResourceOperations operations in genericResourceOperationsList)
{
Assert.AreEqual(operations.Id, ids[0]);
ids.RemoveAt(0);
}
}

[TestCase]
public void GetGenericResourceOperationsSingleIDTests()
{
string id = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/foo-1/";
Assert.AreEqual(Client.GetGenericResourceOperations(id).Id, id);
}

[TestCase]
[RecordedTest]
public async Task GetGenericResourceOperationsWithSingleValidResource()
{
string id = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{_rgName}/";
var genericResourceOperations = Client.GetGenericResourceOperations(id);
var genericResource = await genericResourceOperations.GetAsync();
Assert.AreEqual(200, genericResource.GetRawResponse().Status);
}

[TestCase]
[RecordedTest]
public void GetGenericResourceOperationsWithSingleInvalidResource()
{
string id = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/foo-1/";
var genericResourceOperations = Client.GetGenericResourceOperations(id);
RequestFailedException exception = Assert.ThrowsAsync<RequestFailedException>(async () => await genericResourceOperations.GetAsync());
Assert.AreEqual(404, exception.Status);
}

[TestCase]
[RecordedTest]
public async Task GetGenericOperationsWithListOfValidResource()
{
var ids = new List<string>()
{
$"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{_rgName}/"
};

var genericResourceOperationsList = Client.GetGenericResourceOperations(ids);

foreach (GenericResourceOperations operations in genericResourceOperationsList)
{
var genericResource = await operations.GetAsync();
Assert.AreEqual(200, genericResource.GetRawResponse().Status);
}
}

[TestCase]
[RecordedTest]
public void GetGenericOperationsWithListOfInvalidResource()
{
var ids = new List<string>()
{
$"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/non-existent/"
};

var genericResourceOperationsList = Client.GetGenericResourceOperations(ids);

foreach (GenericResourceOperations operations in genericResourceOperationsList)
{
RequestFailedException exception = Assert.ThrowsAsync<RequestFailedException>(async () => await operations.GetAsync());
Assert.AreEqual(404, exception.Status);
}
}

[TestCase]
public void GetGenericResourceOperationWithNullSetOfIds()
{
string[] x = null;
Assert.Throws<ArgumentNullException>(() => { Client.GetGenericResourceOperations(x); });
}

[TestCase]
public void GetGenericResourceOperationWithNullId()
{
string x = null;
Assert.Throws<ArgumentNullException>(() => { Client.GetGenericResourceOperations(x); });
}

[TestCase]
public void GetGenericResourceOperationEmptyTest()
{
var ids = new List<string>();
Assert.AreEqual(new List<string>(), Client.GetGenericResourceOperations(ids));
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading