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

Adding more test cases for Azure Quantum Mgmt SDK #18247

Merged
merged 2 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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

Large diffs are not rendered by default.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System.Collections.Generic;
using Xunit;
using System.Threading;
using System.Linq;

namespace Microsoft.Azure.Management.Quantum.Tests
{
public class OfferingOperationTests : QuantumManagementTestBase
{
[Fact]
public void TestListOfferings()
{
TestInitialize();

var firstPage = QuantumClient.Offerings.List(CommonData.Location);
var offerings = QuantumManagementTestUtilities.ListResources(firstPage, QuantumClient.Offerings.ListNext);
Assert.True(offerings.Count >= 1);
var microsoftQIO = offerings.FirstOrDefault((offering) => "Microsoft".Equals(offering.Id));
Assert.NotNull(microsoftQIO);
var microsoftQIOBasicSKU = microsoftQIO.Properties.Skus.FirstOrDefault((sku) => "Basic".Equals(sku.Id));
Assert.NotNull(microsoftQIOBasicSKU);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System.Collections.Generic;
using Xunit;
using System.Threading;
using System.Linq;

namespace Microsoft.Azure.Management.Quantum.Tests
{
public class OperationsTests : QuantumManagementTestBase
{
[Fact]
public void TestListOperations()
{
TestInitialize();

var firstPage = QuantumClient.Operations.List();
var operations = QuantumManagementTestUtilities.ListResources(firstPage, QuantumClient.Operations.ListNext);
Assert.True(operations.Count >= 1);
var workspaceRead = operations.FirstOrDefault((operation) => "Microsoft.Quantum/Workspaces/Read".Equals(operation.Name));
Assert.NotNull(workspaceRead);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Runtime.InteropServices;

namespace Microsoft.Azure.Management.Quantum.Tests
{
Expand All @@ -23,7 +24,7 @@ internal virtual void TestInitialize([System.Runtime.CompilerServices.CallerMemb
{
Context = QuantumMockContext.Start(this.GetType(), methodName);

UseAccessTokenIfNeeded();
UseAzLoginCredentialsIfNeeded();

CommonData = new CommonTestFixture();
QuantumClient = Context.GetServiceClient<QuantumManagementClient>();
Expand All @@ -45,29 +46,64 @@ internal virtual void TestInitialize([System.Runtime.CompilerServices.CallerMemb
}
}

private static void UseAccessTokenIfNeeded()
private static void UseAzLoginCredentialsIfNeeded()
{
var testConnectionString = Environment.GetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION");
if (!string.IsNullOrEmpty(testConnectionString) && !testConnectionString.Contains("ServicePrincipal=") && IsRecordMode)
if (IsRecordMode)
{
var azProcess = new Process()
var testConnectionString = Environment.GetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION");
AzLoginAccessTokenInfo accessTokenInfo = null;
if (string.IsNullOrEmpty(testConnectionString))
{
StartInfo = new ProcessStartInfo("cmd.exe", "/c az account get-access-token")
{
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true
}
};
azProcess.Start();
azProcess.WaitForExit();
var output = azProcess.StandardOutput.ReadToEnd();
var accessToken = JObject.Parse(output)["accessToken"].Value<string>();
Environment.SetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION", $"{testConnectionString}RawToken={accessToken};");
accessTokenInfo = GetAzLoginAccessTokenInfo();
if (accessTokenInfo == null) return;
testConnectionString = $"SubscriptionId={accessTokenInfo.SubscriptionId};AADTenant={accessTokenInfo.TenantId};Environment=Prod;HttpRecorderMode=Record;";
Environment.SetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION", testConnectionString);
}
if (!testConnectionString.Contains("ServicePrincipal="))
accessTokenInfo = accessTokenInfo ?? GetAzLoginAccessTokenInfo(); {
if (accessTokenInfo == null) return;
Environment.SetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION", $"{testConnectionString};RawToken={accessTokenInfo.AccessToken};");
}
}
}

private class AzLoginAccessTokenInfo
{
[JsonProperty("subscription")]
public string SubscriptionId { get; set; }

[JsonProperty("tenant")]
public string TenantId { get; set; }

[JsonProperty("accessToken")]
public string AccessToken { get; set; }
}

private static AzLoginAccessTokenInfo GetAzLoginAccessTokenInfo()
{
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
if (!isWindows)
{
return null;
}

var azProcess = new Process()
{
StartInfo = new ProcessStartInfo("cmd.exe", "/c az account get-access-token")
{
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true
}
};
azProcess.Start();
azProcess.WaitForExit();
var azProcessOutput = azProcess.StandardOutput.ReadToEnd();
var accessTokenInfo = JsonConvert.DeserializeObject<AzLoginAccessTokenInfo>(azProcessOutput);
return accessTokenInfo;
}

protected virtual void CreateResources()
{
//create resource group
Expand Down