Skip to content

Commit

Permalink
Add more test projects (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinyoo authored Jul 11, 2024
1 parent 8628c0e commit 09ad980
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/azure-dev-build-only.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
- name: Install local certs
shell: pwsh
run: |
dotnet dev-certs https --clean
dotnet dev-certs https --trust
dotnet tool update -g linux-dev-certs
dotnet linux-dev-certs install
- name: Install Aspire workload
shell: pwsh
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/azure-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
- name: Install local certs
shell: pwsh
run: |
dotnet dev-certs https --clean
dotnet dev-certs https --trust
dotnet tool update -g linux-dev-certs
dotnet linux-dev-certs install
- name: Install Aspire workload
shell: pwsh
Expand Down
14 changes: 14 additions & 0 deletions AzureOpenAIProxy.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{A69C5782-F
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureOpenAIProxy.AppHost.Tests", "test\AzureOpenAIProxy.AppHost.Tests\AzureOpenAIProxy.AppHost.Tests.csproj", "{E8994388-24FA-4221-8E46-4CD1DA96C585}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureOpenAIProxy.PlaygroundApp.Tests", "test\AzureOpenAIProxy.PlaygroundApp.Tests\AzureOpenAIProxy.PlaygroundApp.Tests.csproj", "{0AE9860A-0F8D-49EF-B375-BF95374A1EDA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureOpenAIProxy.ApiApp.Tests", "test\AzureOpenAIProxy.ApiApp.Tests\AzureOpenAIProxy.ApiApp.Tests.csproj", "{0E772300-9263-49CA-8E26-D0B9CC584202}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -43,6 +47,14 @@ Global
{E8994388-24FA-4221-8E46-4CD1DA96C585}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8994388-24FA-4221-8E46-4CD1DA96C585}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E8994388-24FA-4221-8E46-4CD1DA96C585}.Release|Any CPU.Build.0 = Release|Any CPU
{0AE9860A-0F8D-49EF-B375-BF95374A1EDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0AE9860A-0F8D-49EF-B375-BF95374A1EDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0AE9860A-0F8D-49EF-B375-BF95374A1EDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0AE9860A-0F8D-49EF-B375-BF95374A1EDA}.Release|Any CPU.Build.0 = Release|Any CPU
{0E772300-9263-49CA-8E26-D0B9CC584202}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E772300-9263-49CA-8E26-D0B9CC584202}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E772300-9263-49CA-8E26-D0B9CC584202}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E772300-9263-49CA-8E26-D0B9CC584202}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -53,6 +65,8 @@ Global
{A8BBA7EA-5615-470C-8D2E-77CCCAE3F51E} = {004CE987-A209-4933-884A-2F59506CDC9E}
{1E3B6609-56EC-4FEC-A689-34F9E5DCCF22} = {004CE987-A209-4933-884A-2F59506CDC9E}
{E8994388-24FA-4221-8E46-4CD1DA96C585} = {A69C5782-F0B3-46B9-8089-3E7216AAAB25}
{0AE9860A-0F8D-49EF-B375-BF95374A1EDA} = {A69C5782-F0B3-46B9-8089-3E7216AAAB25}
{0E772300-9263-49CA-8E26-D0B9CC584202} = {A69C5782-F0B3-46B9-8089-3E7216AAAB25}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1D2D444D-0384-4C78-B968-156C7C848DE8}
Expand Down
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
<SwashbuckleVersion>6.*</SwashbuckleVersion>

<CoverletVersion>6.*</CoverletVersion>
<FluentAssertionsVersion>6.*</FluentAssertionsVersion>
<MicrosoftTestSdkVersion>17.*</MicrosoftTestSdkVersion>
<NSubstituteVersion>5.*</NSubstituteVersion>
<SystemTextJsonVersion>8.*</SystemTextJsonVersion>
<XunitVersion>2.*</XunitVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public IOpenAIServiceRequestBuilder SetOpenAIInstance(OpenAISettings openaiSetti
var instances = (openaiSettings ?? throw new ArgumentNullException(nameof(openaiSettings)))
.Instances
.Where(p => p.DeploymentNames!.Contains(deploymentName) == true);
var openai = instances.Skip(openaiSettings.Random.Next(instances.Count())).First();
var openai = instances.Skip(openaiSettings.Random.Next(instances.Count())).FirstOrDefault();

this._endpoint = openai.Endpoint;
this._apiKey = openai.ApiKey;
this._endpoint = openai?.Endpoint;
this._apiKey = openai?.ApiKey;

return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>

<AssemblyName>AzureOpenAIProxy.ApiApp.Tests</AssemblyName>
<RootNamespace>AzureOpenAIProxy.ApiApp.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftTestSdkVersion)" />
<PackageReference Include="NSubstitute" Version="$(NSubstituteVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\AzureOpenAIProxy.ApiApp\AzureOpenAIProxy.ApiApp.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System.Reflection;

using AzureOpenAIProxy.ApiApp.Builders;
using AzureOpenAIProxy.ApiApp.Configurations;

using FluentAssertions;

namespace AzureOpenAIProxy.ApiApp.Tests.Builders;

public class OpenAIServiceRequestBuilderTests
{
[Theory]
[InlineData("https://localhost", "my-api-key", "deployment-name-1")]
public void Given_OpenAISettings_When_Invoked_SetOpenAIInstance_Then_It_Should_Store_Value(string endpoint, string apiKey, string deploymentName)
{
// Arrange
var instance = new OpenAIInstanceSettings
{
Endpoint = endpoint,
ApiKey = apiKey,
DeploymentNames = new List<string>() { deploymentName },
};
var settings = new OpenAISettings()
{
Instances = { instance }
};

// Act
var builder = new OpenAIServiceRequestBuilder();
builder.SetOpenAIInstance(settings, deploymentName);

// Assert
var _endpoint = builder.GetType().GetField("_endpoint", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(builder) as string;
var _apiKey = builder.GetType().GetField("_apiKey", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(builder) as string;

_endpoint.Should().Be(endpoint);
_apiKey.Should().Be(apiKey);
}

[Theory]
[InlineData("https://localhost", "my-api-key", "deployment-name-1", "deployment-name-2")]
public void Given_OpenAISettings_When_Invoked_SetOpenAIInstance_Then_It_Should_Return_Null(string endpoint, string apiKey, string deploymentName, string nonDeploymentName)
{
// Arrange
var instance = new OpenAIInstanceSettings
{
Endpoint = endpoint,
ApiKey = apiKey,
DeploymentNames = new List<string>() { deploymentName },
};
var settings = new OpenAISettings()
{
Instances = { instance }
};

// Act
var builder = new OpenAIServiceRequestBuilder();
builder.SetOpenAIInstance(settings, nonDeploymentName);

// Assert
var _endpoint = builder.GetType().GetField("_endpoint", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(builder) as string;
var _apiKey = builder.GetType().GetField("_apiKey", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(builder) as string;

_endpoint.Should().BeNull();
_apiKey.Should().BeNull();
}
}
9 changes: 9 additions & 0 deletions test/AzureOpenAIProxy.ApiApp.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace AzureOpenAIProxy.ApiApp.Tests;

public class UnitTest1
{
[Fact]
public void Test1()
{
}
}
26 changes: 26 additions & 0 deletions test/AzureOpenAIProxy.AppHost.Tests/AppHostProgramTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Net;

using FluentAssertions;

namespace AzureOpenAIProxy.Tests;

public class AppHostProgramTests
{
[Theory]
[InlineData("apiapp", "/health", HttpStatusCode.OK)]
[InlineData("playgroundapp", "/health", HttpStatusCode.OK)]
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Healthy(string resourceName, string endpoint, HttpStatusCode statusCode)
{
// Arrange
var appHost = await DistributedApplicationTestingBuilder.CreateAsync<Projects.AzureOpenAIProxy_AppHost>();
await using var app = await appHost.BuildAsync();
await app.StartAsync();

// Act
var httpClient = app.CreateHttpClient(resourceName);
var response = await httpClient.GetAsync(endpoint);

// Assert
response.StatusCode.Should().Be(statusCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftTestSdkVersion)" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)">
<PrivateAssets>all</PrivateAssets>
Expand Down
22 changes: 0 additions & 22 deletions test/AzureOpenAIProxy.AppHost.Tests/WebTests.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>

<AssemblyName>AzureOpenAIProxy.PlaygroundApp.Tests</AssemblyName>
<RootNamespace>AzureOpenAIProxy.PlaygroundApp.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftTestSdkVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\AzureOpenAIProxy.PlaygroundApp\AzureOpenAIProxy.PlaygroundApp.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions test/AzureOpenAIProxy.PlaygroundApp.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace AzureOpenAIProxy.PlaygroundApp.Tests;

public class UnitTest1
{
[Fact]
public void Test1()
{
}
}

0 comments on commit 09ad980

Please sign in to comment.