Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: 🛠️ Build
run: dotnet build -c Release src/Refitter.sln -p:UseSourceLink=true -p:PackageVersion="${{ env.VERSION }}" -p:Version="${{ env.VERSION }}"
- name: 🧪 Test
run: dotnet test src/Refitter.sln -c Release
run: dotnet test --solution src/Refitter.sln -c Release
Comment thread
christianhelle marked this conversation as resolved.
- name: 🗳️ Upload
uses: actions/upload-artifact@v5
with:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ jobs:
build:
name: 👌 Verify build
runs-on: windows-latest

steps:

- name: 🛒 Checkout repository
uses: actions/checkout@v6
uses: actions/checkout@v6

- uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x

- name: 🧪 Test
run: dotnet test src/Refitter.Tests/Refitter.Tests.csproj -c Release --collect:"XPlat Code Coverage" -p:UseSourceLink=true -p:PackageVersion="${{ env.VERSION }}"
run: dotnet test --project src/Refitter.Tests/Refitter.Tests.csproj -c Release --coverage --coverage-output coverage.cobertura.xml --coverage-output-format xml

- name: 🗳️ Upload
uses: actions/upload-artifact@v5
with:
Expand Down
13 changes: 10 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,38 @@ Feature requests are welcome! Please follow the feature request template in `.gi
- Verify that the generated code builds successfully
- Test coverage should be comprehensive, covering both normal operation and edge cases.
- All tests must pass before submitting a pull request.
- **Testing Framework**: The project uses [TUnit](https://github.com/thomhurst/TUnit) instead of xUnit for unit testing, which provides 3x faster test execution.

Example test pattern:

```csharp
using FluentAssertions;
using Refitter.Core;
using Refitter.Tests.Build;
using Refitter.Tests.TestUtilities;
using TUnit.Core;

public class MyFeatureTests
{
private const string OpenApiSpec = @"
// Your OpenAPI specification here
";

[Fact]
[Test]
public async Task Can_Generate_Code()
{
string generatedCode = await GenerateCode();
generatedCode.Should().NotBeNullOrWhiteSpace();
}

[Fact]
[Test]
public async Task Generated_Code_Contains_Expected_Pattern()
{
string generatedCode = await GenerateCode();
generatedCode.Should().Contain("ExpectedPattern");
}

[Fact]
[Test]
public async Task Can_Build_Generated_Code()
{
string generatedCode = await GenerateCode();
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,16 @@ Please head to the [Apizr documentation](https://www.apizr.net) to get more.

.NET 8.0 or .NET 9.0

## Testing

Refitter uses [TUnit](https://github.com/thomhurst/TUnit) as its testing framework instead of xUnit. TUnit was chosen for its superior performance, providing 3x faster test execution compared to xUnit. This significantly improves the developer experience when running the test suite locally and in CI/CD pipelines.

To run the tests:

```bash
dotnet test --solution src/Refitter.sln -c Release
```

## Contributing

Please read our [contribution guidelines](CONTRIBUTING.md) if you'd like to contribute to the project.
Expand Down
6 changes: 5 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ When contributing to the documentation:
2. Include code examples where appropriate
3. Test your changes locally before submitting
4. Ensure all links are valid and working
5. Update the table of contents if adding new articles
5. Update the table of contents if adding new articles

## Testing Framework

Refitter uses [TUnit](https://github.com/thomhurst/TUnit) for unit testing instead of xUnit. TUnit provides significantly faster test execution (3x faster), which improves both local development and CI/CD pipeline performance. When writing tests for new features or bug fixes, use TUnit's `[Test]` attribute instead of xUnit's `[Fact]` or `[Theory]`.
10 changes: 10 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"sdk": {
"version": "10.0.0",
"rollForward": "latestFeature",
"testingPlatform": true
},
"test": {
"runner": "Microsoft.Testing.Platform"
}
}
4 changes: 3 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseTestingPlatform>true</UseTestingPlatform>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
</PropertyGroup>

<PropertyGroup Label="Nuget">
Expand Down Expand Up @@ -37,4 +39,4 @@
<EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using FluentAssertions;
using Refit;
using Refitter.Tests.CustomGenerated;
using Xunit;
using TUnit.Core;

namespace Refitter.SourceGenerators.Tests;

public class CustomOutputFolderGeneratorTests
{
[Fact]
[Test]
public void Can_Create_File_In_Custom_Path() =>
File.Exists("../../../CustomGenerated/CustomGenerated.cs").Should().BeTrue();

[Fact]
[Test]
public void Can_Resolve_Refit_Interface() =>
RestService.For<IApiInCustomGeneratedFolder>("https://petstore3.swagger.io/api/v3")
.Should()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
using FluentAssertions;
using Refit;
using Refitter.Tests.AdditionalFiles.ByTag;
using Xunit;
using TUnit.Core;

namespace Refitter.SourceGenerators.Tests;

public class MultipleInterfaceByTagGeneratorTests
{
[Theory]
[InlineData(typeof(IPetApi))]
[InlineData(typeof(IUserApi))]
[InlineData(typeof(IStoreApi))]
[Test]
[Arguments(typeof(IPetApi))]
[Arguments(typeof(IUserApi))]
[Arguments(typeof(IStoreApi))]
public void Should_Generate_Interface(Type type) =>
type
.Namespace
.Should()
.Be("Refitter.Tests.AdditionalFiles.ByTag");

[Theory]
[InlineData(typeof(IPetApi))]
[InlineData(typeof(IUserApi))]
[InlineData(typeof(IStoreApi))]
[Test]
[Arguments(typeof(IPetApi))]
[Arguments(typeof(IUserApi))]
[Arguments(typeof(IStoreApi))]
public void Can_Resolve_Refit_Interface(Type type) =>
RestService.For(type, "https://petstore3.swagger.io/api/v3")
.Should()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
using FluentAssertions;
using Refit;
using Refitter.Tests.AdditionalFiles.ByEndpoint;
using Xunit;
using TUnit.Core;

namespace Refitter.SourceGenerators.Tests;

public class MultipleInterfaceGeneratorTests
{
[Theory]
[InlineData(typeof(IAddPetEndpoint))]
[InlineData(typeof(IUpdatePetEndpoint))]
[InlineData(typeof(IDeletePetEndpoint))]
[InlineData(typeof(ICreateUserEndpoint))]
[InlineData(typeof(IUpdateUserEndpoint))]
[InlineData(typeof(IDeleteUserEndpoint))]
[InlineData(typeof(ILoginUserEndpoint))]
[InlineData(typeof(ILogoutUserEndpoint))]
[InlineData(typeof(IPlaceOrderEndpoint))]
[InlineData(typeof(IGetOrderByIdEndpoint))]
[InlineData(typeof(IDeleteOrderEndpoint))]
[InlineData(typeof(IGetInventoryEndpoint))]
[InlineData(typeof(IGetPetByIdEndpoint))]
[InlineData(typeof(IUploadFileEndpoint))]
[InlineData(typeof(IFindPetsByStatusEndpoint))]
[InlineData(typeof(IFindPetsByTagsEndpoint))]
[InlineData(typeof(IGetUserByNameEndpoint))]
[InlineData(typeof(IUpdatePetWithFormEndpoint))]
[InlineData(typeof(ICreateUsersWithListInputEndpoint))]
[Test]
[Arguments(typeof(IAddPetEndpoint))]
[Arguments(typeof(IUpdatePetEndpoint))]
[Arguments(typeof(IDeletePetEndpoint))]
[Arguments(typeof(ICreateUserEndpoint))]
[Arguments(typeof(IUpdateUserEndpoint))]
[Arguments(typeof(IDeleteUserEndpoint))]
[Arguments(typeof(ILoginUserEndpoint))]
[Arguments(typeof(ILogoutUserEndpoint))]
[Arguments(typeof(IPlaceOrderEndpoint))]
[Arguments(typeof(IGetOrderByIdEndpoint))]
[Arguments(typeof(IDeleteOrderEndpoint))]
[Arguments(typeof(IGetInventoryEndpoint))]
[Arguments(typeof(IGetPetByIdEndpoint))]
[Arguments(typeof(IUploadFileEndpoint))]
[Arguments(typeof(IFindPetsByStatusEndpoint))]
[Arguments(typeof(IFindPetsByTagsEndpoint))]
[Arguments(typeof(IGetUserByNameEndpoint))]
[Arguments(typeof(IUpdatePetWithFormEndpoint))]
[Arguments(typeof(ICreateUsersWithListInputEndpoint))]
public void Should_Generate_Interface(Type type) =>
type
.Namespace
.Should()
.Be("Refitter.Tests.AdditionalFiles.ByEndpoint");

[Theory]
[InlineData(typeof(IAddPetEndpoint))]
[InlineData(typeof(IUpdatePetEndpoint))]
[InlineData(typeof(IDeletePetEndpoint))]
[InlineData(typeof(ICreateUserEndpoint))]
[InlineData(typeof(IUpdateUserEndpoint))]
[InlineData(typeof(IDeleteUserEndpoint))]
[InlineData(typeof(ILoginUserEndpoint))]
[InlineData(typeof(ILogoutUserEndpoint))]
[InlineData(typeof(IPlaceOrderEndpoint))]
[InlineData(typeof(IGetOrderByIdEndpoint))]
[InlineData(typeof(IDeleteOrderEndpoint))]
[InlineData(typeof(IGetInventoryEndpoint))]
[InlineData(typeof(IGetPetByIdEndpoint))]
[InlineData(typeof(IUploadFileEndpoint))]
[InlineData(typeof(IFindPetsByStatusEndpoint))]
[InlineData(typeof(IFindPetsByTagsEndpoint))]
[InlineData(typeof(IGetUserByNameEndpoint))]
[InlineData(typeof(IUpdatePetWithFormEndpoint))]
[InlineData(typeof(ICreateUsersWithListInputEndpoint))]
[Test]
[Arguments(typeof(IAddPetEndpoint))]
[Arguments(typeof(IUpdatePetEndpoint))]
[Arguments(typeof(IDeletePetEndpoint))]
[Arguments(typeof(ICreateUserEndpoint))]
[Arguments(typeof(IUpdateUserEndpoint))]
[Arguments(typeof(IDeleteUserEndpoint))]
[Arguments(typeof(ILoginUserEndpoint))]
[Arguments(typeof(ILogoutUserEndpoint))]
[Arguments(typeof(IPlaceOrderEndpoint))]
[Arguments(typeof(IGetOrderByIdEndpoint))]
[Arguments(typeof(IDeleteOrderEndpoint))]
[Arguments(typeof(IGetInventoryEndpoint))]
[Arguments(typeof(IGetPetByIdEndpoint))]
[Arguments(typeof(IUploadFileEndpoint))]
[Arguments(typeof(IFindPetsByStatusEndpoint))]
[Arguments(typeof(IFindPetsByTagsEndpoint))]
[Arguments(typeof(IGetUserByNameEndpoint))]
[Arguments(typeof(IUpdatePetWithFormEndpoint))]
[Arguments(typeof(ICreateUsersWithListInputEndpoint))]
public void Can_Resolve_Refit_Interface(Type type) =>
RestService.For(type, "https://petstore3.swagger.io/api/v3")
.Should()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using FluentAssertions;
using Refit;
using Refitter.Tests.AdditionalFiles.OptionalParameters;
using Xunit;
using TUnit.Core;

namespace Refitter.SourceGenerators.Tests;

public class OperationalParametersGeneratorTest
{
[Fact]
[Test]
public void Should_Type_Exist() =>
typeof(ISwaggerPetstoreWithOptionalParameters)
.Namespace
.Should()
.Be("Refitter.Tests.AdditionalFiles.OptionalParameters");

[Fact]
[Test]
public void Can_Resolve_Refit_Interface() =>
RestService.For<ISwaggerPetstoreWithOptionalParameters>("https://petstore3.swagger.io/api/v3")
.Should()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateProgramFile>false</GenerateProgramFile>
<RootNamespace>Refitter.SourceGenerators.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="10.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="FluentAssertions" Version="7.2.0" />
<PackageReference Include="System.Text.Json" Version="10.0.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="TUnit" Version="1.3.25" />
<PackageReference Include="coverlet.collector" Version="6.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand All @@ -42,9 +41,9 @@
</ItemGroup>

<ItemGroup>
<ProjectReference
Include="..\Refitter.SourceGenerator\Refitter.SourceGenerator.csproj"
OutputItemType="Analyzer"
<ProjectReference
Include="..\Refitter.SourceGenerator\Refitter.SourceGenerator.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using FluentAssertions;
using Refit;
using Refitter.Tests.AdditionalFiles.SingeInterface;
using Xunit;
using TUnit.Core;

namespace Refitter.SourceGenerators.Tests;

public class SingleInterfaceGeneratorTest
{
[Fact]
[Test]
public void Should_Type_Exist() =>
typeof(ISwaggerPetstoreInterface)
.Namespace
.Should()
.Be("Refitter.Tests.AdditionalFiles.SingeInterface");

[Fact]
[Test]
public void Can_Resolve_Refit_Interface() =>
RestService.For<ISwaggerPetstoreInterface>("https://petstore3.swagger.io/api/v3")
.Should()
Expand Down
Loading
Loading