forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Azure#1 from Azure/main
pr
- Loading branch information
Showing
34 changed files
with
6,666 additions
and
18 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
sdk/azurestackhci/Azure.ResourceManager.Hci/tests/HciManagementTestBase.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,78 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using Azure.Core; | ||
using Azure.Core.TestFramework; | ||
using Azure.ResourceManager.Hci.Models; | ||
using Azure.ResourceManager.Resources; | ||
using Azure.ResourceManager.TestFramework; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Azure.ResourceManager.Hci.Tests | ||
{ | ||
public class HciManagementTestBase : ManagementRecordedTestBase<HciManagementTestEnvironment> | ||
{ | ||
protected ArmClient Client { get; private set; } | ||
|
||
protected SubscriptionResource Subscription { get; private set; } | ||
|
||
protected HciManagementTestBase(bool isAsync, RecordedTestMode mode) | ||
: base(isAsync, mode) | ||
{ | ||
} | ||
|
||
protected HciManagementTestBase(bool isAsync) | ||
: base(isAsync) | ||
{ | ||
} | ||
|
||
[SetUp] | ||
public async Task CreateCommonClient() | ||
{ | ||
Client = GetArmClient(); | ||
Subscription = await Client.GetDefaultSubscriptionAsync(); | ||
} | ||
|
||
protected async Task<ResourceGroupResource> CreateResourceGroupAsync(SubscriptionResource subscription, string rgNamePrefix, AzureLocation location) | ||
{ | ||
string rgName = Recording.GenerateAssetName(rgNamePrefix); | ||
ResourceGroupData input = new ResourceGroupData(location); | ||
var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, input); | ||
return lro.Value; | ||
} | ||
|
||
protected async Task<HciClusterResource> CreateHciClusterAsync(ResourceGroupResource resourceGroup, string clusterName, AzureLocation? location = null) | ||
{ | ||
var clusterData = new HciClusterData(location == null ? resourceGroup.Data.Location : location.Value) | ||
{ | ||
AadClientId = new Guid(TestEnvironment.ClientId), | ||
AadTenantId = new Guid(TestEnvironment.TenantId) | ||
}; | ||
var lro = await resourceGroup.GetHciClusters().CreateOrUpdateAsync(WaitUntil.Completed, clusterName, clusterData); | ||
return lro.Value; | ||
} | ||
|
||
protected async Task<ArcSettingResource> CreateArcSettingAsync(HciClusterResource cluster, string arcSettingName) | ||
{ | ||
var arcSettingData = new ArcSettingData(); | ||
var lro = await cluster.GetArcSettings().CreateOrUpdateAsync(WaitUntil.Completed, arcSettingName, arcSettingData); | ||
return lro.Value; | ||
} | ||
|
||
protected async Task<ArcExtensionResource> CreateArcExtensionAsync(ArcSettingResource arcSetting, string arcExtensionName) | ||
{ | ||
var arcExtensionData = new ArcExtensionData() | ||
{ | ||
Settings = BinaryData.FromObjectAsJson(new Dictionary<string, object>() | ||
{ | ||
{ "workspaceId", "5dcf9bc1-c220-4ed6-84f3-6919c3a393b6" } | ||
}) | ||
}; | ||
var lro = await arcSetting.GetArcExtensions().CreateOrUpdateAsync(WaitUntil.Completed, arcExtensionName, arcExtensionData); | ||
return lro.Value; | ||
} | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
sdk/azurestackhci/Azure.ResourceManager.Hci/tests/Scenario/ArcExtensionCollectionTests.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,48 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Core; | ||
using Azure.Core.TestFramework; | ||
using Azure.ResourceManager.Hci.Models; | ||
using Azure.ResourceManager.Models; | ||
using Azure.ResourceManager.Resources; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.ResourceManager.Hci.Tests | ||
{ | ||
public class ArcExtensionCollectionTests: HciManagementTestBase | ||
{ | ||
public ArcExtensionCollectionTests(bool isAsync) | ||
: base(isAsync) | ||
{ | ||
} | ||
|
||
[TestCase] | ||
[RecordedTest] | ||
public async Task CreateGetList() | ||
{ | ||
var location = AzureLocation.EastUS; | ||
var resourceGroup = await CreateResourceGroupAsync(Subscription, "hci-cluster-rg", location); | ||
var clusterName = Recording.GenerateAssetName("hci-cluster"); | ||
var cluster = await CreateHciClusterAsync(resourceGroup, clusterName); | ||
var arcSetting = await CreateArcSettingAsync(cluster, "default"); | ||
|
||
var arcExtensionCollection = arcSetting.GetArcExtensions(); | ||
var arcExtensionName = "MicrosoftMonitoringAgent"; | ||
var arcExtension = await CreateArcExtensionAsync(arcSetting, arcExtensionName); | ||
Assert.AreEqual(arcExtension.Data.Name, arcExtensionName); | ||
|
||
ArcExtensionResource arcExtensionFromGet = await arcExtensionCollection.GetAsync(arcExtensionName); | ||
Assert.AreEqual(arcExtensionFromGet.Data.Name, arcExtensionName); | ||
|
||
await foreach (ArcExtensionResource arcExtensionFromList in arcExtensionCollection) | ||
{ | ||
Assert.AreEqual(arcExtensionFromList.Data.Name, arcExtensionName); | ||
} | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
sdk/azurestackhci/Azure.ResourceManager.Hci/tests/Scenario/ArcExtensionOperationTests.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,62 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Core; | ||
using Azure.Core.TestFramework; | ||
using Azure.ResourceManager.Hci.Models; | ||
using Azure.ResourceManager.Models; | ||
using Azure.ResourceManager.Resources; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.ResourceManager.Hci.Tests | ||
{ | ||
public class ArcExtensionOperationTests: HciManagementTestBase | ||
{ | ||
private ResourceGroupResource _resourceGroup; | ||
private ArcExtensionResource _arcExtension; | ||
private ArcExtensionCollection _arcExtensionCollection; | ||
|
||
public ArcExtensionOperationTests(bool isAsync) | ||
: base(isAsync) | ||
{ | ||
} | ||
|
||
private async Task<ArcExtensionResource> CreateArcExtensionAsync(string arcExtensionName) | ||
{ | ||
var location = AzureLocation.EastUS; | ||
_resourceGroup = await CreateResourceGroupAsync(Subscription, "hci-cluster-rg", location); | ||
var clusterName = Recording.GenerateAssetName("hci-cluster"); | ||
var cluster = await CreateHciClusterAsync(_resourceGroup, clusterName); | ||
var arcSetting = await CreateArcSettingAsync(cluster, "default"); | ||
|
||
_arcExtension = await CreateArcExtensionAsync(arcSetting, arcExtensionName); | ||
_arcExtensionCollection = arcSetting.GetArcExtensions(); | ||
return _arcExtension; | ||
} | ||
|
||
[TestCase] | ||
[RecordedTest] | ||
public async Task GetUpdateDelete() | ||
{ | ||
var arcExtensionName = "MicrosoftMonitoringAgent"; | ||
var arcExtension = await CreateArcExtensionAsync(arcExtensionName); | ||
|
||
var data = new ArcExtensionData() | ||
{ | ||
ShouldAutoUpgradeMinorVersion = true, | ||
}; | ||
var lro = await arcExtension.UpdateAsync(WaitUntil.Completed, data); | ||
var arcExtensionFromUpdate = lro.Value; | ||
Assert.True(arcExtensionFromUpdate.Data.ShouldAutoUpgradeMinorVersion); | ||
|
||
ArcExtensionResource arcExtensionFromGet = await arcExtensionFromUpdate.GetAsync(); | ||
Assert.AreEqual(arcExtensionFromGet.Data.Name, arcExtensionName); | ||
|
||
await arcExtensionFromGet.DeleteAsync(WaitUntil.Completed); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
sdk/azurestackhci/Azure.ResourceManager.Hci/tests/Scenario/ArcSettingCollectionTests.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,46 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Core; | ||
using Azure.Core.TestFramework; | ||
using Azure.ResourceManager.Hci.Models; | ||
using Azure.ResourceManager.Models; | ||
using Azure.ResourceManager.Resources; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.ResourceManager.Hci.Tests | ||
{ | ||
public class ArcSettingCollectionTests: HciManagementTestBase | ||
{ | ||
public ArcSettingCollectionTests(bool isAsync) | ||
: base(isAsync) | ||
{ | ||
} | ||
|
||
[TestCase] | ||
[RecordedTest] | ||
public async Task CreateGetList() | ||
{ | ||
var location = AzureLocation.EastUS; | ||
var resourceGroup = await CreateResourceGroupAsync(Subscription, "hci-cluster-rg", location); | ||
var clusterName = Recording.GenerateAssetName("hci-cluster"); | ||
var cluster = await CreateHciClusterAsync(resourceGroup, clusterName); | ||
var arcSettingCollection = cluster.GetArcSettings(); | ||
var arcSettingName = "default";//Recording.GenerateAssetName("hci-arc-setting"); | ||
var arcSetting = await CreateArcSettingAsync(cluster, arcSettingName); | ||
Assert.AreEqual(arcSetting.Data.Name, arcSettingName); | ||
|
||
ArcSettingResource arcSettingFromGet = await arcSettingCollection.GetAsync(arcSettingName); | ||
Assert.AreEqual(arcSettingFromGet.Data.Name, arcSettingName); | ||
|
||
await foreach (ArcSettingResource arcSettingFromList in arcSettingCollection) | ||
{ | ||
Assert.AreEqual(arcSettingFromList.Data.Name, arcSettingName); | ||
} | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
sdk/azurestackhci/Azure.ResourceManager.Hci/tests/Scenario/ArcSettingOperationTests.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,63 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Core; | ||
using Azure.Core.TestFramework; | ||
using Azure.ResourceManager.Hci.Models; | ||
using Azure.ResourceManager.Models; | ||
using Azure.ResourceManager.Resources; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.ResourceManager.Hci.Tests | ||
{ | ||
public class ArcSettingOperationTests: HciManagementTestBase | ||
{ | ||
private ResourceGroupResource _resourceGroup; | ||
private ArcSettingResource _arcSetting; | ||
private ArcSettingCollection _arcSettingCollection; | ||
|
||
public ArcSettingOperationTests(bool isAsync) | ||
: base(isAsync) | ||
{ | ||
} | ||
|
||
private async Task<ArcSettingResource> CreateArcSettingAsync(string arcSettingName) | ||
{ | ||
var location = AzureLocation.EastUS; | ||
_resourceGroup = await CreateResourceGroupAsync(Subscription, "hci-cluster-rg", location); | ||
var clusterName = Recording.GenerateAssetName("hci-cluster"); | ||
HciClusterResource cluster = await CreateHciClusterAsync(_resourceGroup, clusterName); | ||
_arcSettingCollection = cluster.GetArcSettings(); | ||
_arcSetting = await CreateArcSettingAsync(cluster, arcSettingName); | ||
return _arcSetting; | ||
} | ||
|
||
[TestCase] | ||
[RecordedTest] | ||
public async Task GetUpdateDelete() | ||
{ | ||
var arcSettingName = "default"; | ||
var arcSetting = await CreateArcSettingAsync(arcSettingName); | ||
|
||
var patch = new ArcSettingPatch() | ||
{ | ||
ConnectivityProperties = BinaryData.FromObjectAsJson(new Dictionary<string, object>() | ||
{ | ||
{ "enabled", true } | ||
}) | ||
}; | ||
ArcSettingResource arcSettingFromUpdate = await arcSetting.UpdateAsync(patch); | ||
var properties = arcSettingFromUpdate.Data.ConnectivityProperties.ToObjectFromJson() as Dictionary<string, object>; | ||
Assert.True((bool)properties["enabled"]); | ||
|
||
ArcSettingResource arcSettingFromGet = await arcSettingFromUpdate.GetAsync(); | ||
Assert.AreEqual(arcSettingFromGet.Data.Name, arcSettingName); | ||
|
||
await arcSettingFromGet.DeleteAsync(WaitUntil.Completed); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
sdk/azurestackhci/Azure.ResourceManager.Hci/tests/Scenario/HciClusterCollectionTests.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,54 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Core; | ||
using Azure.Core.TestFramework; | ||
using Azure.ResourceManager.Hci.Models; | ||
using Azure.ResourceManager.Models; | ||
using Azure.ResourceManager.Resources; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.ResourceManager.Hci.Tests | ||
{ | ||
public class HciClusterCollectionTests: HciManagementTestBase | ||
{ | ||
public HciClusterCollectionTests(bool isAsync) | ||
: base(isAsync) | ||
{ | ||
} | ||
|
||
[TestCase] | ||
[RecordedTest] | ||
public async Task CreateGetList() | ||
{ | ||
var location = AzureLocation.EastUS; | ||
var resourceGroup = await CreateResourceGroupAsync(Subscription, "hci-cluster-rg", location); | ||
var clusterCollection = resourceGroup.GetHciClusters(); | ||
var clusterName = Recording.GenerateAssetName("hci-cluster"); | ||
var cluster = await CreateHciClusterAsync(resourceGroup, clusterName); | ||
var clusterData = cluster.Data; | ||
Assert.AreEqual(clusterData.Name, clusterName); | ||
Assert.AreEqual(clusterData.Location, location); | ||
Assert.AreEqual(clusterData.AadClientId, new Guid(TestEnvironment.ClientId)); | ||
Assert.AreEqual(clusterData.AadTenantId, new Guid(TestEnvironment.TenantId)); | ||
|
||
HciClusterResource clusterFromGet = await clusterCollection.GetAsync(clusterName); | ||
Assert.AreEqual(clusterFromGet.Data.Name, clusterName); | ||
Assert.AreEqual(clusterFromGet.Data.Location, location); | ||
Assert.AreEqual(clusterFromGet.Data.AadClientId, new Guid(TestEnvironment.ClientId)); | ||
Assert.AreEqual(clusterFromGet.Data.AadTenantId, new Guid(TestEnvironment.TenantId)); | ||
|
||
await foreach (HciClusterResource clusterFromList in clusterCollection) | ||
{ | ||
Assert.AreEqual(clusterFromList.Data.Name, clusterName); | ||
Assert.AreEqual(clusterFromList.Data.Location, location); | ||
Assert.AreEqual(clusterFromList.Data.AadClientId, new Guid(TestEnvironment.ClientId)); | ||
Assert.AreEqual(clusterFromList.Data.AadTenantId, new Guid(TestEnvironment.TenantId)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.