Skip to content

Commit

Permalink
Merge pull request Azure#1 from Azure/main
Browse files Browse the repository at this point in the history
pr
  • Loading branch information
seilorjunior authored Aug 15, 2022
2 parents 80fdf68 + e3fa5cd commit 183f33a
Show file tree
Hide file tree
Showing 34 changed files with 6,666 additions and 18 deletions.
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Azure.ResourceManager.Hci.Tests
{
public class AzureStackHciManagementTestEnvironment : TestEnvironment
public class HciManagementTestEnvironment : TestEnvironment
{
}
}
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);
}
}
}
}
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);
}
}
}
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);
}
}
}
}
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);
}
}
}
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));
}
}
}
}
Loading

0 comments on commit 183f33a

Please sign in to comment.