Skip to content

Commit

Permalink
Merge pull request #92 from christianhelle/source-generator-tests
Browse files Browse the repository at this point in the history
Add production tests for source generators
  • Loading branch information
christianhelle authored Jul 31, 2023
2 parents a79a0e9 + 909621e commit 3a6fac0
Show file tree
Hide file tree
Showing 15 changed files with 271 additions and 2 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/production-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ on:
- cron: '0 8 * * *'

jobs:
template:

cli:
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -40,4 +41,13 @@ jobs:
format: ${{ matrix.format }}
version: ${{ matrix.version }}
openapi: ${{ matrix.openapi }}
command: 'dotnet tool install --global --prerelease refitter; refitter'
command: 'dotnet tool install --global --prerelease refitter; refitter'

sourcegenerator:
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
uses: ./.github/workflows/template-source-generator.yml
with:
os: ${{ matrix.os }}
24 changes: 24 additions & 0 deletions .github/workflows/template-source-generator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Run Tests

on:
workflow_call:
inputs:
os:
type: string
default: ubuntu-latest

jobs:

test:

name: ${{ inputs.os }}
runs-on: ${{ inputs.os }}
timeout-minutes: 10

steps:
- name: 🛒 Checkout repository
uses: actions/checkout@v3

- name: 🛠️ Build SourceGenerator.sln
run: dotnet build
working-directory: test/SourceGenerator
18 changes: 18 additions & 0 deletions test/SourceGenerator/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project>
<PropertyGroup>
<OutputType>Exe</OutputType>
<LangVersion>latest</LangVersion>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Program.cs">
<Link>Program.cs</Link>
</Compile>
<AdditionalFiles Include="..\*.refitter" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Refitter.SourceGenerator" Version="0.7.0.28-preview" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions test/SourceGenerator/Net462/Net462.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions test/SourceGenerator/Net472/Net472.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions test/SourceGenerator/Net48/Net48.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions test/SourceGenerator/Net481/Net481.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net481</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions test/SourceGenerator/Net6/Net6.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>
5 changes: 5 additions & 0 deletions test/SourceGenerator/Net7/Net7.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
</Project>
5 changes: 5 additions & 0 deletions test/SourceGenerator/NetStandard20/NetStandard20.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
5 changes: 5 additions & 0 deletions test/SourceGenerator/NetStandard21/NetStandard21.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
</Project>
48 changes: 48 additions & 0 deletions test/SourceGenerator/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Refit;
using System;
using System.Threading.Tasks;

namespace MyNamespace;

internal class Program
{
private static async Task Main(string[] args)
{
await TestPetstoreUsingDirectTypes();
await TestPetstoreUsingApiResponse();
}

private static async Task TestPetstoreUsingApiResponse()
{
var responseClient = RestService.For<Petstore.UsingApiResponse.ISwaggerPetstoreApiResponse>("https://petstore3.swagger.io/api/v3");
var response = await responseClient.GetPetById(1);

Console.WriteLine("## Using IApiResponse<T> as return type ##");
Console.WriteLine($"HTTP Status Code: {response.StatusCode}");
Console.WriteLine($"Name: {response.Content.Name}");
Console.WriteLine($"Status: {response.Content.Status}");

var pets = await responseClient.FindPetsByStatus(Petstore.UsingApiResponse.Status.Available);
Console.WriteLine("Found " + pets.Content.Count + " available pet(s)");

var taggedPets = await responseClient.FindPetsByTags(new[] { "tag1Updated", "new" });
Console.WriteLine("Found " + taggedPets.Content.Count + " tagged pet(s)");
}

private static async Task TestPetstoreUsingDirectTypes()
{
var client = RestService.For<Petstore.ISwaggerPetstoreDirect>("https://petstore3.swagger.io/api/v3");
var pet = await client.GetPetById(1);

Console.WriteLine($"Name: {pet.Name}");
Console.WriteLine($"Status: {pet.Status}");

var pets = await client.FindPetsByStatus(Petstore.Status.Available);
Console.WriteLine("Found " + pets.Count + " available pet(s)");

var taggedPets = await client.FindPetsByTags(new[] { "tag1Updated", "new" });
Console.WriteLine("Found " + taggedPets.Count + " tagged pet(s)");

Console.WriteLine();
}
}
64 changes: 64 additions & 0 deletions test/SourceGenerator/SourceGenerator.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Net462", "Net462\Net462.csproj", "{DDF75403-9EF8-4B7E-89E7-392071720D18}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Net472", "Net472\Net472.csproj", "{946FFF5A-19F3-4DCC-91E7-0F8D8E22FC39}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Net48", "Net48\Net48.csproj", "{5651B984-6110-4A6A-B6EC-6A8466F97FF9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Net481", "Net481\Net481.csproj", "{CC6110B0-4DC4-4C9A-98F5-6327979815F2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Net6", "Net6\Net6.csproj", "{EC36C592-66FD-4F0F-A50D-01791EE37BAC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Net7", "Net7\Net7.csproj", "{E5E1F363-0A7C-4EA5-B36E-D5B8A1D73B8A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetStandard20", "NetStandard20\NetStandard20.csproj", "{457977B3-A993-4284-853A-ADB3DFFFBCC1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetStandard21", "NetStandard21\NetStandard21.csproj", "{0A8BAE94-81E2-43FE-8DD2-EE9E576DDB47}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DDF75403-9EF8-4B7E-89E7-392071720D18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DDF75403-9EF8-4B7E-89E7-392071720D18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDF75403-9EF8-4B7E-89E7-392071720D18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DDF75403-9EF8-4B7E-89E7-392071720D18}.Release|Any CPU.Build.0 = Release|Any CPU
{946FFF5A-19F3-4DCC-91E7-0F8D8E22FC39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{946FFF5A-19F3-4DCC-91E7-0F8D8E22FC39}.Debug|Any CPU.Build.0 = Debug|Any CPU
{946FFF5A-19F3-4DCC-91E7-0F8D8E22FC39}.Release|Any CPU.ActiveCfg = Release|Any CPU
{946FFF5A-19F3-4DCC-91E7-0F8D8E22FC39}.Release|Any CPU.Build.0 = Release|Any CPU
{5651B984-6110-4A6A-B6EC-6A8466F97FF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5651B984-6110-4A6A-B6EC-6A8466F97FF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5651B984-6110-4A6A-B6EC-6A8466F97FF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5651B984-6110-4A6A-B6EC-6A8466F97FF9}.Release|Any CPU.Build.0 = Release|Any CPU
{CC6110B0-4DC4-4C9A-98F5-6327979815F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CC6110B0-4DC4-4C9A-98F5-6327979815F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CC6110B0-4DC4-4C9A-98F5-6327979815F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CC6110B0-4DC4-4C9A-98F5-6327979815F2}.Release|Any CPU.Build.0 = Release|Any CPU
{EC36C592-66FD-4F0F-A50D-01791EE37BAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC36C592-66FD-4F0F-A50D-01791EE37BAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC36C592-66FD-4F0F-A50D-01791EE37BAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC36C592-66FD-4F0F-A50D-01791EE37BAC}.Release|Any CPU.Build.0 = Release|Any CPU
{E5E1F363-0A7C-4EA5-B36E-D5B8A1D73B8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5E1F363-0A7C-4EA5-B36E-D5B8A1D73B8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5E1F363-0A7C-4EA5-B36E-D5B8A1D73B8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5E1F363-0A7C-4EA5-B36E-D5B8A1D73B8A}.Release|Any CPU.Build.0 = Release|Any CPU
{457977B3-A993-4284-853A-ADB3DFFFBCC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{457977B3-A993-4284-853A-ADB3DFFFBCC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{457977B3-A993-4284-853A-ADB3DFFFBCC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{457977B3-A993-4284-853A-ADB3DFFFBCC1}.Release|Any CPU.Build.0 = Release|Any CPU
{0A8BAE94-81E2-43FE-8DD2-EE9E576DDB47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A8BAE94-81E2-43FE-8DD2-EE9E576DDB47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A8BAE94-81E2-43FE-8DD2-EE9E576DDB47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A8BAE94-81E2-43FE-8DD2-EE9E576DDB47}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
9 changes: 9 additions & 0 deletions test/SourceGenerator/swagger-petstore-apiresponse.refitter
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"openApiPath": "../OpenAPI/v3.0/petstore.json",
"namespace": "Petstore.UsingApiResponse",
"returnIApiResponse": true,
"naming": {
"useOpenApiTitle": false,
"interfaceName": "SwaggerPetstoreApiResponse"
}
}
8 changes: 8 additions & 0 deletions test/SourceGenerator/swagger-petstore-direct.refitter
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"openApiPath": "../OpenAPI/v3.0/petstore.json",
"namespace": "Petstore",
"naming": {
"useOpenApiTitle": false,
"interfaceName": "SwaggerPetstoreDirect"
}
}

0 comments on commit 3a6fac0

Please sign in to comment.