Skip to content

Commit

Permalink
Merge branch 'refs/heads/generatortests'
Browse files Browse the repository at this point in the history
  • Loading branch information
cecilphillip committed Jun 4, 2024
2 parents 562465b + 5950d49 commit aa4f12d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

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

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit" Version="1.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="xunit" Version="2.5.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
</ItemGroup>

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

<ItemGroup>
<ProjectReference Include="..\..\src\Stripe.Extensions.AspNetCore.SourceGenerators\Stripe.Extensions.AspNetCore.SourceGenerators.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis;

namespace Stripe.Extensions.AspNetCore.SourceGenerators.Tests;

public class StripeWebhookHandlerGeneratorTests
{
[Fact]
public void GeneratorOutputsAspNetCore()
{
// Run generator using a driver with an empty compilation
var generator = new StripeWebhookHandlerGenerator();
var driver = CSharpGeneratorDriver.Create(generator);

var compilation = CSharpCompilation.Create(nameof(StripeWebhookHandlerGeneratorTests));
driver.RunGeneratorsAndUpdateCompilation(compilation, out var newCompilation, out var diagnostics);


// Retrieve all files in the compilation.
var generatedFiles = newCompilation.SyntaxTrees
.Select(t => Path.GetFileName(t.FilePath))
.ToArray();

Assert.Equivalent(new[] { "Stripe.Extensions.AspNetCore.g.cs" }, generatedFiles);

Assert.Empty(diagnostics.Where(d => d.Severity == DiagnosticSeverity.Error));
}
}

0 comments on commit aa4f12d

Please sign in to comment.