Skip to content

Commit

Permalink
test: Added Unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed May 10, 2024
1 parent 4172b12 commit c0093cf
Show file tree
Hide file tree
Showing 8 changed files with 24,131 additions and 0 deletions.
7 changes: 7 additions & 0 deletions OpenApiGenerator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenApiGenerator.Helpers",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenApiGenerator.Core", "src\libs\OpenApiGenerator.Core\OpenApiGenerator.Core.csproj", "{3A3F5EE3-0076-4822-B3BA-2955EC802E25}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenApiGenerator.UnitTests", "src\tests\OpenApiGenerator.UnitTests\OpenApiGenerator.UnitTests.csproj", "{88BE4AC5-6E7B-46FA-B656-5CCE8BF9F18E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -56,6 +58,10 @@ Global
{3A3F5EE3-0076-4822-B3BA-2955EC802E25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A3F5EE3-0076-4822-B3BA-2955EC802E25}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A3F5EE3-0076-4822-B3BA-2955EC802E25}.Release|Any CPU.Build.0 = Release|Any CPU
{88BE4AC5-6E7B-46FA-B656-5CCE8BF9F18E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88BE4AC5-6E7B-46FA-B656-5CCE8BF9F18E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88BE4AC5-6E7B-46FA-B656-5CCE8BF9F18E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88BE4AC5-6E7B-46FA-B656-5CCE8BF9F18E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -66,6 +72,7 @@ Global
{0EC09367-E7C5-4847-A9F3-DBC18A1C8395} = {9CAA231D-7BE1-46C9-ACD6-EB2E569CEBEA}
{CF6126AF-6934-46EC-A0F2-B75C673EA8D8} = {6E5BF389-3D3F-4D74-9DD0-3B199CB529C5}
{3A3F5EE3-0076-4822-B3BA-2955EC802E25} = {6E5BF389-3D3F-4D74-9DD0-3B199CB529C5}
{88BE4AC5-6E7B-46FA-B656-5CCE8BF9F18E} = {9CAA231D-7BE1-46C9-ACD6-EB2E569CEBEA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1493AEE4-9211-46E9-BFE6-8F629EAC5693}
Expand Down
60 changes: 60 additions & 0 deletions src/tests/OpenApiGenerator.UnitTests/ModelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
using OpenApiGenerator.Core.Generators;
using OpenApiGenerator.Core.Models;

namespace OpenApiGenerator.UnitTests;

[TestClass]
public class ModelTests :
VerifyBase
{
private Settings DefaultSettings => new(
TargetFramework: "netstandard2.0",
Namespace: "G",
ClassName: "Api",
NamingConvention: default,
IncludeOperationIds: [],
GenerateModels: true,
ModelStyle: default,
IncludeModels: []
);

private Task VerifyAsync(
ImmutableArray<ModelData> models,
[CallerMemberName] string? callerName = null)
{
return Verify(models
.Select(x => x with { Parents = [] })
.ToArray())
.UseDirectory($"Snapshots/{callerName}")
.UseFileName("_")
//.AutoVerify()
;
}

[TestMethod]
public Task OpenAi()
{
var yaml = H.Resources.openai_yaml.AsString();
var settings = DefaultSettings with
{
//IncludeModels = ["CreateCompletionResponse"],
};

var models = ModelGeneratorMethods.PrepareData((yaml, settings));

return VerifyAsync(models);
}

[TestMethod]
public Task Ollama()
{
var yaml = H.Resources.ollamacurated_yaml.AsString();
var settings = DefaultSettings;

var models = ModelGeneratorMethods.PrepareData((yaml, settings));

return VerifyAsync(models);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup Label="Base packages">
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Verify.MSTest" Version="23.1.0" />
</ItemGroup>

<ItemGroup Label="GlobalUsings">
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
<Using Include="FluentAssertions" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="H.Resources.Generator" Version="1.6.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\libs\OpenApiGenerator.Core\OpenApiGenerator.Core.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Snapshots\Models\" />
<Folder Include="Snapshots\Ollama\" />
<Folder Include="Snapshots\OpenAi\" />
</ItemGroup>

</Project>
Loading

0 comments on commit c0093cf

Please sign in to comment.