Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
10f6ad0
Change the accessbility to virtual for Resource.Id
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-…
Apr 23, 2021
832483a
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
Apr 28, 2021
3066cd2
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
May 6, 2021
9597dc7
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
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
6f858c5
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
m-nash May 17, 2021
fb80156
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
m-nash May 25, 2021
4f1408d
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
Jun 4, 2021
0bcb9e4
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
Jun 7, 2021
03d54f9
Add GenericResourceOperations tests
Jun 11, 2021
766d4f6
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
Jun 11, 2021
e6cb898
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
Jun 11, 2021
d3ae815
Merge branch 'mgmt-track2' into yall-4568-GenericResourceOperations
Jun 11, 2021
0d972d2
Merge GenericResourceOperationsTests and GenericResourceTests
Jun 14, 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
Expand Up @@ -7,33 +7,20 @@
namespace Azure.ResourceManager.Core.Tests
{
[Parallelizable]
public class GenericResourceTests : ResourceManagerTestBase
public class GenericResourceOperationsTests : ResourceManagerTestBase
{
private string _rgName;

private readonly string _location = "southcentralus";

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

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

[TestCase]
[RecordedTest]
public async Task GetGenericsConfirmException()
{
var asetid = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{_rgName}/providers/Microsoft.Compute/availabilitySets/testavset";
ArmClientOptions options = new ArmClientOptions();
_ = GetArmClient(options); // setup providers client
var rgName = Recording.GenerateAssetName("testrg");
_ = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).CreateOrUpdateAsync(rgName);
var asetid = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{rgName}/providers/Microsoft.Compute/availabilitySets/testavset";
var subOp = await Client.GetSubscriptions().TryGetAsync(TestEnvironment.SubscriptionId);
var genericResourceOperations = new GenericResourceOperations(subOp, asetid);
RequestFailedException exception = Assert.ThrowsAsync<RequestFailedException>(async () => await genericResourceOperations.GetAsync());
Expand All @@ -45,9 +32,9 @@ public async Task GetGenericsConfirmException()
[RecordedTest]
public async Task GetGenericsBadNameSpace()
{
var asetid = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{_rgName}/providers/Microsoft.NotAValidNameSpace123/availabilitySets/testavset";
ArmClientOptions options = new ArmClientOptions();
_ = GetArmClient(options); // setup providers client
var rgName = Recording.GenerateAssetName("testrg");
_ = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).CreateOrUpdateAsync(rgName);
var asetid = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{rgName}/providers/Microsoft.NotAValidNameSpace123/availabilitySets/testavset";
var subOp = await Client.GetSubscriptions().TryGetAsync(TestEnvironment.SubscriptionId);
var genericResourceOperations = new GenericResourceOperations(subOp, asetid);
InvalidOperationException exception = Assert.ThrowsAsync<InvalidOperationException>(async () => await genericResourceOperations.GetAsync());
Expand All @@ -58,7 +45,9 @@ public async Task GetGenericsBadNameSpace()
[RecordedTest]
public async Task GetGenericsBadApiVersion()
{
ResourceGroupResourceIdentifier rgid = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{_rgName}";
var rgName = Recording.GenerateAssetName("testrg");
_ = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).CreateOrUpdateAsync(rgName);
ResourceGroupResourceIdentifier rgid = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{rgName}";
ArmClientOptions options = new ArmClientOptions();
options.ApiVersions.SetApiVersion(rgid.ResourceType, "1500-10-10");
var client = GetArmClient(options);
Expand All @@ -72,14 +61,13 @@ public async Task GetGenericsBadApiVersion()
[RecordedTest]
public async Task GetGenericsGoodApiVersion()
{
ResourceGroupResourceIdentifier rgid = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/{_rgName}";
ArmClientOptions options = new ArmClientOptions();
var client = GetArmClient(options);
var subOp = await client.GetSubscriptions().TryGetAsync(TestEnvironment.SubscriptionId);
var genericResourceOperations = new GenericResourceOperations(subOp, rgid);
var rg = await genericResourceOperations.GetAsync();
Assert.IsNotNull(rg.Value);
Assert.IsTrue(rg.Value.Data.Name.Equals(_rgName));
var rgName = Recording.GenerateAssetName("testrg");
ResourceGroup rg = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).CreateOrUpdateAsync(rgName);
var subOp = await Client.GetSubscriptions().TryGetAsync(TestEnvironment.SubscriptionId);
var genericResourceOperations = new GenericResourceOperations(subOp, rg.Id);
var genericResource = await genericResourceOperations.GetAsync();
Assert.IsNotNull(genericResource.Value);
Assert.IsTrue(genericResource.Value.Data.Name.Equals(rgName));
}

[TestCase]
Expand All @@ -90,6 +78,9 @@ public async Task Delete()
var aset = await CreateGenericAvailabilitySetAsync(rg.Id);

Assert.DoesNotThrowAsync(async () => await aset.DeleteAsync());

var fakeId = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/foo-1";
Assert.ThrowsAsync<RequestFailedException>(async () => _ = await CreateGenericAvailabilitySetAsync(fakeId));
}

[TestCase]
Expand All @@ -98,13 +89,21 @@ public async Task StartDelete()
{
var rgOp = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).StartCreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
ResourceGroup rg = await rgOp.WaitForCompletionAsync();
var asetOp = await StartCreateGenericAvailabilitySetAsync(rg.Id);
GenericResource aset = await asetOp.WaitForCompletionAsync();
var createOp = await StartCreateGenericAvailabilitySetAsync(rg.Id);
GenericResource aset = await createOp.WaitForCompletionAsync();

Assert.DoesNotThrowAsync(async () => {
Assert.DoesNotThrowAsync(async () =>
{
var deleteOp = await aset.StartDeleteAsync();
_ = await deleteOp.WaitForCompletionResponseAsync();
});

var fakeId = $"/subscriptions/{TestEnvironment.SubscriptionId}/resourceGroups/foo-1";
Assert.ThrowsAsync<RequestFailedException>(async () =>
{
var createOp = await StartCreateGenericAvailabilitySetAsync(fakeId);
_ = await createOp.WaitForCompletionAsync();
});
}

[TestCase]
Expand All @@ -114,6 +113,8 @@ public async Task AddTag()
ResourceGroup rg = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
var aset = await CreateGenericAvailabilitySetAsync(rg.Id);

Assert.AreEqual(0, aset.Data.Tags.Count);

aset = await aset.AddTagAsync("key", "value");

Assert.IsTrue(aset.Data.Tags.ContainsKey("key"));
Expand All @@ -126,8 +127,10 @@ public async Task StartAddTag()
{
var rgOp = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).StartCreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
ResourceGroup rg = await rgOp.WaitForCompletionAsync();
var asetOp = await StartCreateGenericAvailabilitySetAsync(rg.Id);
GenericResource aset = await asetOp.WaitForCompletionAsync();
var createOp = await StartCreateGenericAvailabilitySetAsync(rg.Id);
GenericResource aset = await createOp.WaitForCompletionAsync();

Assert.AreEqual(0, aset.Data.Tags.Count);

var addTagOp = await aset.StartAddTagAsync("key", "value");
aset = await addTagOp.WaitForCompletionAsync();
Expand Down Expand Up @@ -155,6 +158,8 @@ public async Task SetTags()
ResourceGroup rg = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
var aset = await CreateGenericAvailabilitySetAsync(rg.Id);

Assert.AreEqual(0, aset.Data.Tags.Count);

Dictionary<string, string> tags = new Dictionary<string, string>();
tags.Add("key", "value");
aset = await aset.SetTagsAsync(tags);
Expand All @@ -169,8 +174,8 @@ public async Task StartSetTags()
{
var rgOp = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).StartCreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
ResourceGroup rg = await rgOp.WaitForCompletionAsync();
var asetOp = await StartCreateGenericAvailabilitySetAsync(rg.Id);
GenericResource aset = await asetOp.WaitForCompletionAsync();
var createOp = await StartCreateGenericAvailabilitySetAsync(rg.Id);
GenericResource aset = await createOp.WaitForCompletionAsync();

Dictionary<string, string> tags = new Dictionary<string, string>();
tags.Add("key", "value");
Expand All @@ -195,6 +200,7 @@ public async Task RemoveTag()
aset = await aset.RemoveTagAsync("key");

Assert.IsFalse(aset.Data.Tags.ContainsKey("key"));
Assert.AreEqual(0, aset.Data.Tags.Count);
}

[TestCase]
Expand All @@ -203,8 +209,8 @@ public async Task StartRemoveTag()
{
var rgOp = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).StartCreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
ResourceGroup rg = await rgOp.WaitForCompletionAsync();
var asetOp = await StartCreateGenericAvailabilitySetAsync(rg.Id);
GenericResource aset = await asetOp.WaitForCompletionAsync();
var crateOp = await StartCreateGenericAvailabilitySetAsync(rg.Id);
GenericResource aset = await crateOp.WaitForCompletionAsync();

Dictionary<string, string> tags = new Dictionary<string, string>();
tags.Add("key", "value");
Expand All @@ -215,6 +221,7 @@ public async Task StartRemoveTag()
aset = await removeTagOp.WaitForCompletionAsync();

Assert.IsFalse(aset.Data.Tags.ContainsKey("key"));
Assert.AreEqual(0, aset.Data.Tags.Count);
}

[TestCase]
Expand All @@ -230,6 +237,8 @@ public async Task Update()

Assert.IsTrue(aset.Data.Tags.ContainsKey("key"));
Assert.AreEqual("value", aset.Data.Tags["key"]);

Assert.ThrowsAsync<ArgumentNullException>(async () => _ = await aset.UpdateAsync(null));
}

[TestCase]
Expand All @@ -238,8 +247,8 @@ public async Task StartUpdate()
{
var rgOp = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).StartCreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
ResourceGroup rg = await rgOp.WaitForCompletionAsync();
var asetOp = await StartCreateGenericAvailabilitySetAsync(rg.Id);
GenericResource aset = await asetOp.WaitForCompletionAsync();
var createOp = await StartCreateGenericAvailabilitySetAsync(rg.Id);
GenericResource aset = await createOp.WaitForCompletionAsync();

var data = ConstructGenericAvailabilitySet();
data.Tags.Add("key", "value");
Expand All @@ -248,6 +257,12 @@ public async Task StartUpdate()

Assert.IsTrue(aset.Data.Tags.ContainsKey("key"));
Assert.AreEqual("value", aset.Data.Tags["key"]);

Assert.ThrowsAsync<ArgumentNullException>(async () =>
{
var updateOp = await aset.StartUpdateAsync(null);
_ = await updateOp.WaitForCompletionAsync();
});
}
}
}
Loading