Skip to content

Commit 09ad980

Browse files
authored
Add more test projects (#29)
1 parent 8628c0e commit 09ad980

File tree

13 files changed

+204
-29
lines changed

13 files changed

+204
-29
lines changed

.github/workflows/azure-dev-build-only.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ jobs:
2525
- name: Install local certs
2626
shell: pwsh
2727
run: |
28-
dotnet dev-certs https --clean
29-
dotnet dev-certs https --trust
28+
dotnet tool update -g linux-dev-certs
29+
dotnet linux-dev-certs install
3030
3131
- name: Install Aspire workload
3232
shell: pwsh

.github/workflows/azure-dev.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ jobs:
3434
- name: Install local certs
3535
shell: pwsh
3636
run: |
37-
dotnet dev-certs https --clean
38-
dotnet dev-certs https --trust
37+
dotnet tool update -g linux-dev-certs
38+
dotnet linux-dev-certs install
3939
4040
- name: Install Aspire workload
4141
shell: pwsh

AzureOpenAIProxy.sln

+14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{A69C5782-F
1717
EndProject
1818
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureOpenAIProxy.AppHost.Tests", "test\AzureOpenAIProxy.AppHost.Tests\AzureOpenAIProxy.AppHost.Tests.csproj", "{E8994388-24FA-4221-8E46-4CD1DA96C585}"
1919
EndProject
20+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureOpenAIProxy.PlaygroundApp.Tests", "test\AzureOpenAIProxy.PlaygroundApp.Tests\AzureOpenAIProxy.PlaygroundApp.Tests.csproj", "{0AE9860A-0F8D-49EF-B375-BF95374A1EDA}"
21+
EndProject
22+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureOpenAIProxy.ApiApp.Tests", "test\AzureOpenAIProxy.ApiApp.Tests\AzureOpenAIProxy.ApiApp.Tests.csproj", "{0E772300-9263-49CA-8E26-D0B9CC584202}"
23+
EndProject
2024
Global
2125
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2226
Debug|Any CPU = Debug|Any CPU
@@ -43,6 +47,14 @@ Global
4347
{E8994388-24FA-4221-8E46-4CD1DA96C585}.Debug|Any CPU.Build.0 = Debug|Any CPU
4448
{E8994388-24FA-4221-8E46-4CD1DA96C585}.Release|Any CPU.ActiveCfg = Release|Any CPU
4549
{E8994388-24FA-4221-8E46-4CD1DA96C585}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{0AE9860A-0F8D-49EF-B375-BF95374A1EDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{0AE9860A-0F8D-49EF-B375-BF95374A1EDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{0AE9860A-0F8D-49EF-B375-BF95374A1EDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{0AE9860A-0F8D-49EF-B375-BF95374A1EDA}.Release|Any CPU.Build.0 = Release|Any CPU
54+
{0E772300-9263-49CA-8E26-D0B9CC584202}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
55+
{0E772300-9263-49CA-8E26-D0B9CC584202}.Debug|Any CPU.Build.0 = Debug|Any CPU
56+
{0E772300-9263-49CA-8E26-D0B9CC584202}.Release|Any CPU.ActiveCfg = Release|Any CPU
57+
{0E772300-9263-49CA-8E26-D0B9CC584202}.Release|Any CPU.Build.0 = Release|Any CPU
4658
EndGlobalSection
4759
GlobalSection(SolutionProperties) = preSolution
4860
HideSolutionNode = FALSE
@@ -53,6 +65,8 @@ Global
5365
{A8BBA7EA-5615-470C-8D2E-77CCCAE3F51E} = {004CE987-A209-4933-884A-2F59506CDC9E}
5466
{1E3B6609-56EC-4FEC-A689-34F9E5DCCF22} = {004CE987-A209-4933-884A-2F59506CDC9E}
5567
{E8994388-24FA-4221-8E46-4CD1DA96C585} = {A69C5782-F0B3-46B9-8089-3E7216AAAB25}
68+
{0AE9860A-0F8D-49EF-B375-BF95374A1EDA} = {A69C5782-F0B3-46B9-8089-3E7216AAAB25}
69+
{0E772300-9263-49CA-8E26-D0B9CC584202} = {A69C5782-F0B3-46B9-8089-3E7216AAAB25}
5670
EndGlobalSection
5771
GlobalSection(ExtensibilityGlobals) = postSolution
5872
SolutionGuid = {1D2D444D-0384-4C78-B968-156C7C848DE8}

Directory.Build.props

+3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
<SwashbuckleVersion>6.*</SwashbuckleVersion>
1818

1919
<CoverletVersion>6.*</CoverletVersion>
20+
<FluentAssertionsVersion>6.*</FluentAssertionsVersion>
2021
<MicrosoftTestSdkVersion>17.*</MicrosoftTestSdkVersion>
22+
<NSubstituteVersion>5.*</NSubstituteVersion>
23+
<SystemTextJsonVersion>8.*</SystemTextJsonVersion>
2124
<XunitVersion>2.*</XunitVersion>
2225
</PropertyGroup>
2326
</Project>

src/AzureOpenAIProxy.ApiApp/Builders/OpenAIServiceRequestBuilder.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ public IOpenAIServiceRequestBuilder SetOpenAIInstance(OpenAISettings openaiSetti
6464
var instances = (openaiSettings ?? throw new ArgumentNullException(nameof(openaiSettings)))
6565
.Instances
6666
.Where(p => p.DeploymentNames!.Contains(deploymentName) == true);
67-
var openai = instances.Skip(openaiSettings.Random.Next(instances.Count())).First();
67+
var openai = instances.Skip(openaiSettings.Random.Next(instances.Count())).FirstOrDefault();
6868

69-
this._endpoint = openai.Endpoint;
70-
this._apiKey = openai.ApiKey;
69+
this._endpoint = openai?.Endpoint;
70+
this._apiKey = openai?.ApiKey;
7171

7272
return this;
7373
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<IsPackable>false</IsPackable>
5+
<IsTestProject>true</IsTestProject>
6+
7+
<AssemblyName>AzureOpenAIProxy.ApiApp.Tests</AssemblyName>
8+
<RootNamespace>AzureOpenAIProxy.ApiApp.Tests</RootNamespace>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)">
13+
<PrivateAssets>all</PrivateAssets>
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
</PackageReference>
16+
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftTestSdkVersion)" />
18+
<PackageReference Include="NSubstitute" Version="$(NSubstituteVersion)" />
19+
<PackageReference Include="xunit" Version="$(XunitVersion)" />
20+
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)">
21+
<PrivateAssets>all</PrivateAssets>
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
</PackageReference>
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<ProjectReference Include="..\..\src\AzureOpenAIProxy.ApiApp\AzureOpenAIProxy.ApiApp.csproj" />
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<Using Include="Xunit" />
32+
</ItemGroup>
33+
34+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System.Reflection;
2+
3+
using AzureOpenAIProxy.ApiApp.Builders;
4+
using AzureOpenAIProxy.ApiApp.Configurations;
5+
6+
using FluentAssertions;
7+
8+
namespace AzureOpenAIProxy.ApiApp.Tests.Builders;
9+
10+
public class OpenAIServiceRequestBuilderTests
11+
{
12+
[Theory]
13+
[InlineData("https://localhost", "my-api-key", "deployment-name-1")]
14+
public void Given_OpenAISettings_When_Invoked_SetOpenAIInstance_Then_It_Should_Store_Value(string endpoint, string apiKey, string deploymentName)
15+
{
16+
// Arrange
17+
var instance = new OpenAIInstanceSettings
18+
{
19+
Endpoint = endpoint,
20+
ApiKey = apiKey,
21+
DeploymentNames = new List<string>() { deploymentName },
22+
};
23+
var settings = new OpenAISettings()
24+
{
25+
Instances = { instance }
26+
};
27+
28+
// Act
29+
var builder = new OpenAIServiceRequestBuilder();
30+
builder.SetOpenAIInstance(settings, deploymentName);
31+
32+
// Assert
33+
var _endpoint = builder.GetType().GetField("_endpoint", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(builder) as string;
34+
var _apiKey = builder.GetType().GetField("_apiKey", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(builder) as string;
35+
36+
_endpoint.Should().Be(endpoint);
37+
_apiKey.Should().Be(apiKey);
38+
}
39+
40+
[Theory]
41+
[InlineData("https://localhost", "my-api-key", "deployment-name-1", "deployment-name-2")]
42+
public void Given_OpenAISettings_When_Invoked_SetOpenAIInstance_Then_It_Should_Return_Null(string endpoint, string apiKey, string deploymentName, string nonDeploymentName)
43+
{
44+
// Arrange
45+
var instance = new OpenAIInstanceSettings
46+
{
47+
Endpoint = endpoint,
48+
ApiKey = apiKey,
49+
DeploymentNames = new List<string>() { deploymentName },
50+
};
51+
var settings = new OpenAISettings()
52+
{
53+
Instances = { instance }
54+
};
55+
56+
// Act
57+
var builder = new OpenAIServiceRequestBuilder();
58+
builder.SetOpenAIInstance(settings, nonDeploymentName);
59+
60+
// Assert
61+
var _endpoint = builder.GetType().GetField("_endpoint", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(builder) as string;
62+
var _apiKey = builder.GetType().GetField("_apiKey", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(builder) as string;
63+
64+
_endpoint.Should().BeNull();
65+
_apiKey.Should().BeNull();
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace AzureOpenAIProxy.ApiApp.Tests;
2+
3+
public class UnitTest1
4+
{
5+
[Fact]
6+
public void Test1()
7+
{
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Net;
2+
3+
using FluentAssertions;
4+
5+
namespace AzureOpenAIProxy.Tests;
6+
7+
public class AppHostProgramTests
8+
{
9+
[Theory]
10+
[InlineData("apiapp", "/health", HttpStatusCode.OK)]
11+
[InlineData("playgroundapp", "/health", HttpStatusCode.OK)]
12+
public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Healthy(string resourceName, string endpoint, HttpStatusCode statusCode)
13+
{
14+
// Arrange
15+
var appHost = await DistributedApplicationTestingBuilder.CreateAsync<Projects.AzureOpenAIProxy_AppHost>();
16+
await using var app = await appHost.BuildAsync();
17+
await app.StartAsync();
18+
19+
// Act
20+
var httpClient = app.CreateHttpClient(resourceName);
21+
var response = await httpClient.GetAsync(endpoint);
22+
23+
// Assert
24+
response.StatusCode.Should().Be(statusCode);
25+
}
26+
}

test/AzureOpenAIProxy.AppHost.Tests/AzureOpenAIProxy.AppHost.Tests.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>
17+
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
1718
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftTestSdkVersion)" />
19+
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" />
1820
<PackageReference Include="xunit" Version="$(XunitVersion)" />
1921
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)">
2022
<PrivateAssets>all</PrivateAssets>

test/AzureOpenAIProxy.AppHost.Tests/WebTests.cs

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<IsPackable>false</IsPackable>
5+
<IsTestProject>true</IsTestProject>
6+
7+
<AssemblyName>AzureOpenAIProxy.PlaygroundApp.Tests</AssemblyName>
8+
<RootNamespace>AzureOpenAIProxy.PlaygroundApp.Tests</RootNamespace>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="coverlet.collector" Version="$(CoverletVersion)">
13+
<PrivateAssets>all</PrivateAssets>
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
</PackageReference>
16+
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftTestSdkVersion)" />
18+
<PackageReference Include="xunit" Version="$(XunitVersion)" />
19+
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)">
20+
<PrivateAssets>all</PrivateAssets>
21+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22+
</PackageReference>
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<ProjectReference Include="..\..\src\AzureOpenAIProxy.PlaygroundApp\AzureOpenAIProxy.PlaygroundApp.csproj" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<Using Include="Xunit" />
31+
</ItemGroup>
32+
33+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace AzureOpenAIProxy.PlaygroundApp.Tests;
2+
3+
public class UnitTest1
4+
{
5+
[Fact]
6+
public void Test1()
7+
{
8+
}
9+
}

0 commit comments

Comments
 (0)