forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Subscription] Add tests (Azure#31128)
- Loading branch information
Showing
37 changed files
with
1,390,342 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
.../Azure.ResourceManager.Subscription/tests/Scenario/BillingAccountPoliciesResponseTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Azure.Core; | ||
using Azure.Core.TestFramework; | ||
using Azure.ResourceManager.Resources; | ||
using Azure.ResourceManager.Subscription.Models; | ||
using Azure.ResourceManager.Subscription.Tests; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.ResourceManager.Subscription.Tests | ||
{ | ||
internal class BillingAccountPoliciesResponseTests : SubscriptionManagementTestBase | ||
{ | ||
private BillingAccountPoliciesResponseCollection _billingAccountPolicesCollection => GetBillingAccountPoliciesResponseCollection().Result; | ||
|
||
public BillingAccountPoliciesResponseTests(bool isAsync) : base(isAsync) | ||
{ | ||
} | ||
|
||
private async Task<BillingAccountPoliciesResponseCollection> GetBillingAccountPoliciesResponseCollection() | ||
{ | ||
var tenants = await Client.GetTenants().GetAllAsync().ToEnumerableAsync(); | ||
return tenants.FirstOrDefault().GetBillingAccountPoliciesResponses(); | ||
} | ||
|
||
[RecordedTest] | ||
public void Exist() | ||
{ | ||
// Unable to get a valid account name | ||
// Azure.RequestFailedException : Invalid billing account name. | ||
Assert.ThrowsAsync<RequestFailedException>(() => _billingAccountPolicesCollection.ExistsAsync("testBillingAccountId")); | ||
} | ||
|
||
[RecordedTest] | ||
public void Get() | ||
{ | ||
// Unable to get a valid account name | ||
// Azure.RequestFailedException : Invalid billing account name. | ||
Assert.ThrowsAsync<RequestFailedException>(() => _billingAccountPolicesCollection.GetAsync("testBillingAccountId")); | ||
} | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
...ption/Azure.ResourceManager.Subscription/tests/Scenario/SubscriptionAliasResponseTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Security; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Core.TestFramework; | ||
using Azure.ResourceManager.Subscription.Models; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.ResourceManager.Subscription.Tests | ||
{ | ||
internal class SubscriptionAliasResponseTests : SubscriptionManagementTestBase | ||
{ | ||
private SubscriptionAliasResponseCollection _aliasCollection => GetAliasCollection().Result; | ||
|
||
public SubscriptionAliasResponseTests(bool isAsync) : base(isAsync) | ||
{ | ||
} | ||
|
||
[TearDown] | ||
public async Task TestTearDown() | ||
{ | ||
var list = await _aliasCollection.GetAllAsync().ToEnumerableAsync(); | ||
foreach (var item in list) | ||
{ | ||
await item.DeleteAsync(WaitUntil.Completed); | ||
} | ||
} | ||
|
||
private async Task<SubscriptionAliasResponseCollection> GetAliasCollection() | ||
{ | ||
var tenants = await Client.GetTenants().GetAllAsync().ToEnumerableAsync(); | ||
return tenants.FirstOrDefault().GetSubscriptionAliasResponses(); | ||
} | ||
|
||
private async Task<SubscriptionAliasResponseResource> CreateAliasResponse(string aliasName) | ||
{ | ||
var data = new SubscriptionAliasResponseCreateOrUpdateContent() | ||
{ | ||
Properties = new PutAliasRequestProperties() | ||
{ | ||
Workload = "Production", | ||
SubscriptionId = Environment.GetEnvironmentVariable("SUBSCRIPTION_ID"), | ||
} | ||
}; | ||
data.Properties.AdditionalProperties = new PutAliasRequestAdditionalProperties(); | ||
data.Properties.AdditionalProperties.Tags.Add(new KeyValuePair<string, string>("tag1", "test1")); | ||
data.Properties.AdditionalProperties.Tags.Add(new KeyValuePair<string, string>("tag2", "test2")); | ||
var alias = await _aliasCollection.CreateOrUpdateAsync(WaitUntil.Completed, aliasName, data); | ||
return alias.Value; | ||
} | ||
|
||
[RecordedTest] | ||
[Ignore("pipeline playback error")] | ||
public async Task CreateOrUpdate() | ||
{ | ||
string aliasName = Recording.GenerateAssetName("test-alias-"); | ||
var alias = await CreateAliasResponse(aliasName); | ||
ValidateAliasResponse(alias); | ||
Assert.AreEqual(aliasName, alias.Data.Name); | ||
} | ||
|
||
[RecordedTest] | ||
[Ignore("pipeline playback error")] | ||
public async Task Exist() | ||
{ | ||
string aliasName = Recording.GenerateAssetName("test-alias-"); | ||
var alias = await CreateAliasResponse(aliasName); | ||
bool flag = await _aliasCollection.ExistsAsync(aliasName); | ||
Assert.IsTrue(flag); | ||
} | ||
|
||
[RecordedTest] | ||
[Ignore("pipeline playback error")] | ||
public async Task Get() | ||
{ | ||
string aliasName = Recording.GenerateAssetName("test-alias-"); | ||
await CreateAliasResponse(aliasName); | ||
var alias = await _aliasCollection.GetAsync(aliasName); | ||
ValidateAliasResponse(alias); | ||
Assert.AreEqual(aliasName, alias.Value.Data.Name); | ||
} | ||
|
||
[RecordedTest] | ||
[Ignore("pipeline playback error")] | ||
public async Task GetAll() | ||
{ | ||
string aliasName = Recording.GenerateAssetName("test-alias-"); | ||
await CreateAliasResponse(aliasName); | ||
var list = await _aliasCollection.GetAllAsync().ToEnumerableAsync(); | ||
Assert.IsNotEmpty(list); | ||
ValidateAliasResponse(list.FirstOrDefault()); | ||
} | ||
|
||
[RecordedTest] | ||
[Ignore("pipeline playback error")] | ||
public async Task Delete() | ||
{ | ||
string aliasName = Recording.GenerateAssetName("test-alias-"); | ||
var alias = await CreateAliasResponse(aliasName); | ||
bool flag = await _aliasCollection.ExistsAsync(aliasName); | ||
Assert.IsTrue(flag); | ||
|
||
await alias.DeleteAsync(WaitUntil.Completed); | ||
flag = await _aliasCollection.ExistsAsync(aliasName); | ||
Assert.IsFalse(flag); | ||
} | ||
|
||
private void ValidateAliasResponse(SubscriptionAliasResponseResource alias) | ||
{ | ||
Assert.IsNotNull(alias); | ||
Assert.AreEqual("Microsoft.Subscription", alias.Data.ResourceType.Namespace); | ||
} | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...scription/Azure.ResourceManager.Subscription/tests/Scenario/SubscriptionExtensionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Core.TestFramework; | ||
using Azure.ResourceManager.Resources; | ||
using Azure.ResourceManager.Subscription.Models; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.ResourceManager.Subscription.Tests | ||
{ | ||
internal class SubscriptionExtensionTests : SubscriptionManagementTestBase | ||
{ | ||
private SubscriptionResource _subscription; | ||
|
||
public SubscriptionExtensionTests(bool isAsync) : base(isAsync) | ||
{ | ||
} | ||
|
||
[SetUp] | ||
public async Task TestSetUp() | ||
{ | ||
_subscription = await Client.GetDefaultSubscriptionAsync(); | ||
} | ||
|
||
[RecordedTest] | ||
public async Task GetLocationsSubscriptions() | ||
{ | ||
var list = await _subscription.GetLocationsAsync().ToEnumerableAsync(); | ||
Assert.IsNotEmpty(list); | ||
Assert.IsNotNull(list.First(item => item.Name == "eastus")); | ||
} | ||
|
||
[RecordedTest] | ||
public async Task PredefinedTagOperations() | ||
{ | ||
// CreateOrUpdate | ||
string tagName = "testEmptyTag"; | ||
var predefinedTag = await _subscription.CreateOrUpdatePredefinedTagAsync(tagName); | ||
Assert.IsNotNull(predefinedTag); | ||
Assert.AreEqual(tagName, predefinedTag.Value.TagName); | ||
|
||
// GetAll | ||
var list = await _subscription.GetAllPredefinedTagsAsync().ToEnumerableAsync(); | ||
Assert.IsNotEmpty(list); | ||
Assert.IsNotNull(list.First(item => item.TagName == tagName)); | ||
|
||
// Delete | ||
var deleteResponse = await _subscription.DeletePredefinedTagAsync(tagName); | ||
Assert.AreEqual(200, deleteResponse.Status); | ||
} | ||
|
||
[RecordedTest] | ||
public async Task PredefinedTagValueOperations() | ||
{ | ||
string tagName = "testTag"; | ||
await _subscription.CreateOrUpdatePredefinedTagAsync(tagName); | ||
|
||
// Add a TagValue | ||
string tagValue = "preTestValue"; | ||
var predefinedTagValue = await _subscription.CreateOrUpdatePredefinedTagValueAsync(tagName, tagValue); | ||
Assert.IsNotNull(predefinedTagValue); | ||
Assert.AreEqual(tagValue, predefinedTagValue.Value.TagValue); | ||
|
||
// Delete a TagValue | ||
var deleteResponse1 = await _subscription.CreateOrUpdatePredefinedTagValueAsync(tagName, tagValue); | ||
Assert.AreEqual(200, deleteResponse1.GetRawResponse().Status); | ||
|
||
// Delete--409 Please delete all the associated tag values before deleting the tag name. | ||
//var deleteResponse = await _subscription.DeletePredefinedTagAsync(tagName); | ||
//Assert.AreEqual(200, deleteResponse.Status); | ||
} | ||
|
||
[RecordedTest] | ||
public async Task GetFeatures() | ||
{ | ||
var list = await _subscription.GetFeaturesAsync().ToEnumerableAsync(); | ||
Assert.IsNotEmpty(list); | ||
} | ||
|
||
[RecordedTest] | ||
[PlaybackOnly("Dangerous operations")] | ||
public async Task CancelSubscription() | ||
{ | ||
var response = await _subscription.CancelSubscriptionAsync(); | ||
Assert.AreEqual(200,response.GetRawResponse().Status); | ||
} | ||
|
||
[RecordedTest] | ||
[PlaybackOnly("Dangerous operations")] | ||
public async Task RenameSubscription() | ||
{ | ||
SubscriptionName data = new SubscriptionName() | ||
{ | ||
SubscriptionNameValue = "azSubscriptionTestName" | ||
}; | ||
var response = await _subscription.RenameSubscriptionAsync(data); | ||
Assert.AreEqual(200,response.GetRawResponse().Status); | ||
} | ||
|
||
[RecordedTest] | ||
[Ignore("400. NotAllowed. Reactivation is not supported for subscription")] | ||
public async Task EnableSubscription() | ||
{ | ||
var response = await _subscription.EnableSubscriptionAsync(); | ||
Assert.AreEqual(200,response.GetRawResponse().Status); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...cription/Azure.ResourceManager.Subscription/tests/Scenario/TenantPolicyDefinitionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Core.TestFramework; | ||
using Azure.ResourceManager.Resources; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.ResourceManager.Subscription.Tests | ||
{ | ||
internal class TenantPolicyDefinitionTests : SubscriptionManagementTestBase | ||
{ | ||
private TenantPolicyDefinitionCollection _tenantPolicyDefinitionCollection => GetTenantPolicyDefinition().Result; | ||
|
||
public TenantPolicyDefinitionTests(bool isAsync) : base(isAsync) | ||
{ | ||
} | ||
|
||
private async Task<TenantPolicyDefinitionCollection> GetTenantPolicyDefinition() | ||
{ | ||
var tenants = await Client.GetTenants().GetAllAsync().ToEnumerableAsync(); | ||
return tenants.FirstOrDefault().GetTenantPolicyDefinitions(); | ||
} | ||
|
||
[RecordedTest] | ||
public async Task GetAll() | ||
{ | ||
var list = await _tenantPolicyDefinitionCollection.GetAllAsync().ToEnumerableAsync(); | ||
Assert.IsNotEmpty(list); | ||
} | ||
|
||
[RecordedTest] | ||
public async Task Exist() | ||
{ | ||
var list = await _tenantPolicyDefinitionCollection.GetAllAsync().ToEnumerableAsync(); | ||
string policyName = list.FirstOrDefault().Data.Name; | ||
bool flag = await _tenantPolicyDefinitionCollection.ExistsAsync(policyName); | ||
Assert.IsTrue(flag); | ||
} | ||
|
||
[RecordedTest] | ||
public async Task Get() | ||
{ | ||
var list = await _tenantPolicyDefinitionCollection.GetAllAsync().ToEnumerableAsync(); | ||
string policyName = list.FirstOrDefault().Data.Name; | ||
var policy = await _tenantPolicyDefinitionCollection.GetAsync(policyName); | ||
Assert.IsNotNull(policy); | ||
Assert.AreEqual(policyName, policy.Value.Data.Name); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...bscription/Azure.ResourceManager.Subscription/tests/Scenario/TenantPolicyResponseTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Core.TestFramework; | ||
using Azure.ResourceManager.Resources; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.ResourceManager.Subscription.Tests | ||
{ | ||
internal class TenantPolicyResponseTests : SubscriptionManagementTestBase | ||
{ | ||
public TenantPolicyResponseTests(bool isAsync) : base(isAsync) | ||
{ | ||
} | ||
|
||
[RecordedTest] | ||
[Ignore("https://github.com/Azure/azure-sdk-for-net/issues/31127")] | ||
public async Task GetAll() | ||
{ | ||
var tenants = await Client.GetTenants().GetAllAsync().ToEnumerableAsync(); | ||
var response = tenants.FirstOrDefault().GetGetTenantPolicyResponse(); | ||
Assert.NotNull(response); | ||
} | ||
} | ||
} |
Oops, something went wrong.