Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
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
1 change: 1 addition & 0 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.snk
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"msbuild-sdks": {
"Microsoft.Quantum.Sdk": "0.16.2105140327-beta"
"Microsoft.Quantum.Sdk": "0.17.2106147878-beta"
}
}
76 changes: 76 additions & 0 deletions src/Azure/Azure.Quantum.Client.Test/CredentialFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#nullable enable

using System;

using Azure.Identity;

using Microsoft.Azure.Quantum.Authentication;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.Azure.Quantum.Test
{
[TestClass]
public class CredentialFactoryTests
{
private const string SUBSCRIPTION = "916dfd6d-030c-4bd9-b579-7bb6d1926e97";

[DataTestMethod]
[DataRow(CredentialType.Default, typeof(DefaultAzureCredential))]
[DataRow(CredentialType.Environment, typeof(EnvironmentCredential))]
[DataRow(CredentialType.ManagedIdentity, typeof(ManagedIdentityCredential))]
[DataRow(CredentialType.CLI, typeof(AzureCliCredential))]
[DataRow(CredentialType.SharedToken, typeof(SharedTokenCacheCredential))]
[DataRow(CredentialType.VisualStudio, typeof(VisualStudioCredential))]
[DataRow(CredentialType.VisualStudioCode, typeof(VisualStudioCodeCredential))]
[DataRow(CredentialType.Interactive, typeof(InteractiveBrowserCredential))]
[DataRow(CredentialType.DeviceCode, typeof(DeviceCodeCredential))]
public void TestCreateCredential(CredentialType credentialType, Type expectedType)
{
var actual = CredentialFactory.CreateCredential(credentialType);
Assert.IsNotNull(actual);
Assert.AreEqual(expectedType, actual.GetType());

// Now test with a specific subscription id:
actual = CredentialFactory.CreateCredential(credentialType, SUBSCRIPTION);
Assert.IsNotNull(actual);
Assert.AreEqual(expectedType, actual.GetType());
}

[TestMethod]
public void TestInvalidCredentialType()
{
Assert.ThrowsException<ArgumentException>(() => CredentialFactory.CreateCredential((CredentialType)9999));
}

[TestMethod]
public void TestGetTenantId()
{
var actual = CredentialFactory.GetTenantId(SUBSCRIPTION);
Assert.IsNotNull(actual);
Assert.IsFalse(string.IsNullOrWhiteSpace(actual));

var actual2 = CredentialFactory.GetTenantId(SUBSCRIPTION);
Assert.AreEqual(actual, actual2);
}

[DataTestMethod]
[DataRow(null, null)]
[DataRow("", null)]
[DataRow("some random string", null)]
[DataRow("string,with,random,values", null)]
[DataRow("string=with,random=,key=values", null)]
[DataRow("string=with,random=,authorization_uri=", null)]
[DataRow("string=with,invalid=authorization_uri,authorization_uri=some-random-value", null)]
[DataRow("string=with,invalid=authorization_uri,authorization_uri=http://foo.bar.com/some-random-value", null)]
[DataRow("string=missing,tenant_id=authorization_uri,authorization_uri=\"http://foo.bar.com/", null)]
[DataRow("authorization_uri=\"https://login.microsoftonline.com/tenantId\",key1=value1s,etc...", "tenantId")]
public void TestExtractTenantIdFromBearer(string? bearer, string? expected)
{
var actual = CredentialFactory.ExtractTenantIdFromBearer(bearer);
Assert.AreEqual(expected, actual);
}
}
}
52 changes: 0 additions & 52 deletions src/Azure/Azure.Quantum.Client.Test/Helpers/MockHelper.cs

This file was deleted.

118 changes: 118 additions & 0 deletions src/Azure/Azure.Quantum.Client.Test/Helpers/Problem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace Microsoft.Azure.Quantum.Test
{
public enum ProblemType : int
{
PUBO = 0,
Ising = 1,
}

/// <summary>
/// This is the data structure that represents a QIO problem payload on the service.
/// It's currently not exposed in C#, so we have it here so we can test job submission of
/// the client libraries without having to serialize Q# programs.
/// </summary>
public class Problem
{
private readonly HashSet<Term> terms = new HashSet<Term>();

public Problem(ProblemType type = ProblemType.PUBO)
{
ProblemType = type;
}

public Problem(IEnumerable<Term> collection)
: this()
{
AddRange(collection);
}

[JsonPropertyName("version")]
public string Version => "1.1";

[JsonPropertyName("type")]
[JsonConverter(typeof(JsonStringEnumConverter))]
public ProblemType ProblemType { get; }

[JsonPropertyName("terms")]
public IEnumerable<Term> Terms => terms;

public void Add(Term term)
{
terms.Add(term);
}

public void Add(int i, float c)
{
terms.Add(new Term(new int[] { i }, c));
}

public void Add(int i, int j, float c)
{
terms.Add(new Term(new int[] { i, j }, c));
}

public void Add(int i, int j, int k, float c)
{
terms.Add(new Term(new int[] { i, j, k }, c));
}

public void AddRange(IEnumerable<Term> collection)
{
foreach (var term in collection)
{
terms.Add(term);
}
}

public Task SerializeAsync(Stream stream)
{
var root = new SerializationWrapper
{
CostFunction = this,
};

// Save to the writer
return JsonSerializer.SerializeAsync(stream, root);
}

public override string ToString()
{
var root = new SerializationWrapper
{
CostFunction = this,
};

return JsonSerializer.Serialize(root);
}

private struct SerializationWrapper
{
[JsonPropertyName("cost_function")]
public Problem CostFunction { get; set; }
}

public class Term
{
public Term(int[] ids, float c)
{
this.IDs = ids;
this.Weight = c;
}

[JsonPropertyName("c")]
public float Weight { get; }

[JsonPropertyName("ids")]
public int[] IDs { get; }
}
}
}
14 changes: 0 additions & 14 deletions src/Azure/Azure.Quantum.Client.Test/Helpers/TestConstants.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading