Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
3 changes: 3 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.Diagnostics.NETCore.Client" Version="0.2.607501" />
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.10.0" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.10.0-preview.1.25513.3" />
<PackageVersion Include="Azure.AI.OpenAI" Version="2.1.0" />
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="$(MicrosoftTestingExtensionsCodeCoverageVersion)" />
<PackageVersion Include="Microsoft.TestPlatform.AdapterUtilities" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageVersion Include="Microsoft.TestPlatform.ObjectModel" Version="$(MicrosoftNETTestSdkVersion)" />
Expand Down
2 changes: 2 additions & 0 deletions Microsoft.Testing.Platform.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"projects": [
"samples\\Playground\\Playground.csproj",
"src\\Platform\\Microsoft.Testing.Extensions.AzureDevOpsReport\\Microsoft.Testing.Extensions.AzureDevOpsReport.csproj",
"src\\Platform\\Microsoft.Testing.Extensions.AzureFoundry\\Microsoft.Testing.Extensions.AzureFoundry.csproj",
"src\\Platform\\Microsoft.Testing.Extensions.CrashDump\\Microsoft.Testing.Extensions.CrashDump.csproj",
"src\\Platform\\Microsoft.Testing.Extensions.HangDump\\Microsoft.Testing.Extensions.HangDump.csproj",
"src\\Platform\\Microsoft.Testing.Extensions.HotReload\\Microsoft.Testing.Extensions.HotReload.csproj",
Expand All @@ -13,6 +14,7 @@
"src\\Platform\\Microsoft.Testing.Extensions.TrxReport.Abstractions\\Microsoft.Testing.Extensions.TrxReport.Abstractions.csproj",
"src\\Platform\\Microsoft.Testing.Extensions.TrxReport\\Microsoft.Testing.Extensions.TrxReport.csproj",
"src\\Platform\\Microsoft.Testing.Extensions.VSTestBridge\\Microsoft.Testing.Extensions.VSTestBridge.csproj",
"src\\Platform\\Microsoft.Testing.Platform.AI\\Microsoft.Testing.Platform.AI.csproj",
"src\\Platform\\Microsoft.Testing.Platform.MSBuild\\Microsoft.Testing.Platform.MSBuild.csproj",
"src\\Platform\\Microsoft.Testing.Platform\\Microsoft.Testing.Platform.csproj",
"test\\IntegrationTests\\Microsoft.Testing.Platform.Acceptance.IntegrationTests\\Microsoft.Testing.Platform.Acceptance.IntegrationTests.csproj",
Expand Down
26 changes: 14 additions & 12 deletions TestFx.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<File Path="global.json" />
<File Path="Nuget.config" />
</Folder>
<Folder Name="/Solution Items/eng/" Id="5450f9c7-f297-9839-c636-5c9c04a5ba28">
<Folder Name="/Solution Items/eng/">
<File Path="eng/AfterSolutionBuild.targets" />
<File Path="eng/Analyzers.props" />
<File Path="eng/Build.props" />
Expand All @@ -23,16 +23,17 @@
<File Path="eng/Versions.props" />
<File Path="eng/write-release-notes.ps1" />
</Folder>
<Folder Name="/Solution Items/eng/TestingPlatformRunner/" Id="a7b54d83-9a9c-527b-00f3-bda998e116c9">
<Folder Name="/Solution Items/eng/TestingPlatformRunner/">
<File Path="eng/TestingPlatformRunner/TestingPlatform.Runner.targets" />
<File Path="eng/TestingPlatformRunner/TestingPlatformRunner.targets" />
</Folder>
<Folder Name="/src/">
<File Path="src/.editorconfig" />
<File Path="src/Directory.Build.props" />
</Folder>
<Folder Name="/src/1 - Platform and Extensions/" Id="4272bbd9-efdb-ae85-3883-a1ab2fbd20bd">
<Folder Name="/src/1 - Platform and Extensions/">
<File Path="src/Platform/Directory.Build.props" />
<Project Path="src/Platform/Microsoft.Testing.Extensions.AzureFoundry/Microsoft.Testing.Extensions.AzureFoundry.csproj" Id="60c660b9-6d0c-4967-b21c-e1c34257cc75" />
<Project Path="src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/Microsoft.Testing.Extensions.AzureDevOpsReport.csproj" />
<Project Path="src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csproj" />
<Project Path="src/Platform/Microsoft.Testing.Extensions.HangDump/Microsoft.Testing.Extensions.HangDump.csproj" />
Expand All @@ -43,19 +44,20 @@
<Project Path="src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/Microsoft.Testing.Extensions.TrxReport.Abstractions.csproj" />
<Project Path="src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csproj" />
<Project Path="src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csproj" />
<Project Path="src/Platform/Microsoft.Testing.Platform.AI/Microsoft.Testing.Platform.AI.csproj" />
<Project Path="src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csproj" />
<Project Path="src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj" />
</Folder>
<Folder Name="/src/2 - Adapter/" Id="f7cf448e-306d-5d9b-7166-fa7205a8989c">
<Folder Name="/src/2 - Adapter/">
<Project Path="src/Adapter/MSTest.Engine/MSTest.Engine.csproj" />
<Project Path="src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj" />
<Project Path="src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj" />
</Folder>
<Folder Name="/src/3 - TestFramework/" Id="f28cc185-255f-b581-6ed3-c247f7096eb1">
<Folder Name="/src/3 - TestFramework/">
<Project Path="src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj" />
<Project Path="src/TestFramework/TestFramework/TestFramework.csproj" />
</Folder>
<Folder Name="/src/4 - Analyzers/" Id="9c73ee5c-ce16-2586-eb05-df3b4306d351">
<Folder Name="/src/4 - Analyzers/">
<Project Path="src/Analyzers/MSTest.Analyzers.CodeFixes/MSTest.Analyzers.CodeFixes.csproj" />
<Project Path="src/Analyzers/MSTest.Analyzers.Package/MSTest.Analyzers.Package.csproj">
<BuildDependency Project="src/Analyzers/MSTest.GlobalConfigsGenerator/MSTest.GlobalConfigsGenerator.csproj" />
Expand All @@ -64,7 +66,7 @@
<Project Path="src/Analyzers/MSTest.GlobalConfigsGenerator/MSTest.GlobalConfigsGenerator.csproj" />
<Project Path="src/Analyzers/MSTest.SourceGeneration/MSTest.SourceGeneration.csproj" />
</Folder>
<Folder Name="/src/5 - Package/" Id="87d92690-a0c0-3299-b302-eb18ebf7ffb3">
<Folder Name="/src/5 - Package/">
<Project Path="src/Package/MSTest.Sdk/MSTest.Sdk.csproj" />
<Project Path="src/Package/MSTest/MSTest.csproj" />
</Folder>
Expand All @@ -73,14 +75,14 @@
<File Path="test/Directory.Build.props" />
<File Path="test/Directory.Build.targets" />
</Folder>
<Folder Name="/test/IntegrationTests/" Id="334eb2cc-8f21-7cba-1333-4c64d82c9f9a">
<Folder Name="/test/IntegrationTests/">
<Project Path="test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csproj" />
<Project Path="test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csproj" />
<Project Path="test/IntegrationTests/MSTest.IntegrationTests/MSTest.IntegrationTests.csproj" />
<Project Path="test/IntegrationTests/MSTest.VstestConsoleWrapper.IntegrationTests/MSTest.VstestConsoleWrapper.IntegrationTests.csproj" />
<Project Path="test/IntegrationTests/PlatformServices.Desktop.IntegrationTests/PlatformServices.Desktop.IntegrationTests.csproj" />
</Folder>
<Folder Name="/test/IntegrationTests/TestAssets/" Id="05959510-e531-ecb6-7089-da3b202e43db">
<Folder Name="/test/IntegrationTests/TestAssets/">
<File Path="test/IntegrationTests/TestAssets/Directory.Build.targets" />
<Project Path="test/IntegrationTests/TestAssets/ClsTestProject/ClsTestProject.csproj" />
<Project Path="test/IntegrationTests/TestAssets/DataRowTestProject/DataRowTestProject.csproj" />
Expand Down Expand Up @@ -110,15 +112,15 @@
<Project Path="test/IntegrationTests/TestAssets/TestProject/TestProjectForDiscovery.csproj" />
<Project Path="test/IntegrationTests/TestAssets/TimeoutTestProject/TimeoutTestProject.csproj" />
</Folder>
<Folder Name="/test/Performance/" Id="5e428a24-a249-2472-0469-8a6e9a79c114">
<Folder Name="/test/Performance/">
<Project Path="test/Performance/MSTest.Performance.Runner/MSTest.Performance.Runner.csproj" />
</Folder>
<Folder Name="/test/TestUtilities/" Id="f47f7890-75b5-78d9-9d83-447eee1edf9f">
<Folder Name="/test/TestUtilities/">
<Project Path="test/Utilities/Automation.CLI/Automation.CLI.csproj" />
<Project Path="test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csproj" />
<Project Path="test/Utilities/TestFramework.ForTestingMSTest/TestFramework.ForTestingMSTest.csproj" />
</Folder>
<Folder Name="/test/UnitTests/" Id="afae3f01-5c40-22b5-606d-a848a5891b0a">
<Folder Name="/test/UnitTests/">
<Project Path="test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csproj" />
<Project Path="test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csproj" />
<Project Path="test/UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests/Microsoft.Testing.Platform.MSBuild.UnitTests.csproj" />
Expand Down
2 changes: 2 additions & 0 deletions samples/Playground/Playground.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

<ItemGroup>
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Platform\Microsoft.Testing.Platform.csproj" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Platform.AI\Microsoft.Testing.Platform.AI.csproj" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.AzureFoundry\Microsoft.Testing.Extensions.AzureFoundry.csproj" />
<ProjectReference Include="$(RepoRoot)src\Adapter\MSTest.TestAdapter\MSTest.TestAdapter.csproj" />
<ProjectReference Include="$(RepoRoot)src\Analyzers\MSTest.Analyzers.CodeFixes\MSTest.Analyzers.CodeFixes.csproj" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
<ProjectReference Include="$(RepoRoot)src\Analyzers\MSTest.Analyzers\MSTest.Analyzers.csproj" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
Expand Down
24 changes: 21 additions & 3 deletions samples/Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
using Microsoft.Testing.Platform.Messages;
#if NETCOREAPP
using Microsoft.Testing.Platform.ServerMode.IntegrationTests.Messages.V100;

using MSTest.Acceptance.IntegrationTests.Messages.V100;

#endif
using Microsoft.Extensions.AI;
using Microsoft.Testing.Extensions.AzureFoundry;
using Microsoft.Testing.Platform.AI;
using Microsoft.Testing.Platform.Capabilities.TestFramework;
using Microsoft.Testing.Platform.TestHost;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Playground;

Expand All @@ -32,10 +37,13 @@ public static async Task<int> Main(string[] args)
ITestApplicationBuilder testApplicationBuilder = await TestApplication.CreateBuilderAsync(args);

// Test MSTest
testApplicationBuilder.AddMSTest(() => [Assembly.GetEntryAssembly()!]);
// testApplicationBuilder.AddMSTest(() => [Assembly.GetEntryAssembly()!]);

// Add Chat client provider
testApplicationBuilder.AddChatClientProvider(sp => new AzureOpenAIChatClientProvider(sp));

// Test a custom local test framework
// testApplicationBuilder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_, _) => new DummyAdapter());
testApplicationBuilder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_, s) => new DummyAdapter(s));

// Custom test host controller extension
// testApplicationBuilder.TestHostControllers.AddProcessLifetimeHandler(s => new OutOfProc(s.GetMessageBus()));
Expand Down Expand Up @@ -78,6 +86,10 @@ public static async Task<int> Main(string[] args)

internal sealed class DummyAdapter : ITestFramework, IDataProducer
{
private readonly IServiceProvider _serviceProvider;

public DummyAdapter(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider;

public string Uid => nameof(DummyAdapter);

public string Version => string.Empty;
Expand All @@ -96,6 +108,12 @@ public async Task ExecuteRequestAsync(ExecuteRequestContext context)
{
try
{
IChatClient? chatClient = await _serviceProvider.GetChatClientAsync(context.CancellationToken);
if (chatClient != null)
{
ChatResponse response = await chatClient.GetResponseAsync(chatMessage: "Hello, world!", cancellationToken: context.CancellationToken);
}

MyService.DoSomething();
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;$(SupportedNetFrameworks)</TargetFrameworks>
<IsShipping>false</IsShipping>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.AI.OpenAI" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Platform.AI\Microsoft.Testing.Platform.AI.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.ClientModel;

using Azure.AI.OpenAI;

using Microsoft.Extensions.AI;
using Microsoft.Testing.Extensions.AzureFoundry.Resources;
using Microsoft.Testing.Platform.AI;
using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.Services;

namespace Microsoft.Testing.Extensions.AzureFoundry;

/// <summary>
/// Provider for creating Azure OpenAI chat clients.
/// </summary>
public sealed class AzureOpenAIChatClientProvider : IChatClientProvider
{
private readonly IServiceProvider _serviceProvider;

/// <summary>
/// Initializes a new instance of the <see cref="AzureOpenAIChatClientProvider"/> class.
/// </summary>
/// <param name="serviceProvider">The service provider.</param>
public AzureOpenAIChatClientProvider(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}

/// <inheritdoc />
public bool SupportsToolCalling => true;

/// <inheritdoc />
public string ModelName => _serviceProvider.GetRequiredService<IEnvironment>().GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "unknown";

/// <inheritdoc />
public Task<IChatClient> CreateChatClientAsync(CancellationToken cancellationToken)
{
IEnvironment environment = _serviceProvider.GetRequiredService<IEnvironment>();
string? endpoint = environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
string? deploymentName = environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME");
string? apiKey = environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY");

if (string.IsNullOrEmpty(endpoint))
{
throw new InvalidOperationException(ExtensionResources.AzureOpenAIEndpointNotSet);
}

if (string.IsNullOrEmpty(deploymentName))
{
throw new InvalidOperationException(ExtensionResources.AzureOpenAIDeploymentNameNotSet);
}

if (string.IsNullOrEmpty(apiKey))
{
throw new InvalidOperationException(ExtensionResources.AzureOpenAIApiKeyNotSet);
}

var client = new AzureOpenAIClient(
new Uri(endpoint!),
new ApiKeyCredential(apiKey!));

return Task.FromResult(client.GetChatClient(deploymentName).AsIChatClient());
}
}
Loading
Loading