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
72 changes: 36 additions & 36 deletions ServiceScan.SourceGenerator.Tests/AddServicesTests.cs

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions ServiceScan.SourceGenerator.Tests/CustomHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static partial void ProcessServices()
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -102,7 +102,7 @@ public static partial void ProcessServices( string value, decimal number)
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -147,7 +147,7 @@ public static partial void ProcessServices()
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -201,7 +201,7 @@ public static partial class ServicesExtensions
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -259,7 +259,7 @@ public static partial IServiceCollection ProcessServices(this IServiceCollection
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -310,7 +310,7 @@ public static partial void ProcessServices()
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -360,7 +360,7 @@ public static partial void ProcessServices()
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -439,7 +439,7 @@ public static partial class ModelBuilderExtensions
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -487,7 +487,7 @@ public partial void ProcessServices()
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -538,7 +538,7 @@ public partial void ProcessServices()
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -592,7 +592,7 @@ public partial void ProcessServices()
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -645,7 +645,7 @@ public partial void ProcessServices( global::Microsoft.Extensions.DependencyInje
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -705,7 +705,7 @@ public static partial class ServiceCollectionExtensions
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -758,7 +758,7 @@ public static partial void ProcessServices()
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -803,7 +803,7 @@ public static partial void ProcessServices()
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -858,7 +858,7 @@ public static partial void AddHandlers()
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -914,7 +914,7 @@ public static partial void AddHandlers()
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -967,7 +967,7 @@ public static partial void AddProcessors()
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -1028,7 +1028,7 @@ public static partial void AddHandlers()
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -1079,7 +1079,7 @@ public static partial void ProcessServices()
}
}
""";
Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

private static Compilation CreateCompilation(params string[] source)
Expand Down
4 changes: 2 additions & 2 deletions ServiceScan.SourceGenerator.Tests/DiagnosticTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static partial class ServicesExtensions
}
}
""";
Assert.Equal(expectedFile, results.GeneratedTrees[1].ToString());
Assert.Equal(expectedFile, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -211,7 +211,7 @@ public static partial void AddServices(this global::Microsoft.Extensions.Depende
}
}
""";
Assert.Equal(expectedFile, results.GeneratedTrees[1].ToString());
Assert.Equal(expectedFile, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down
12 changes: 6 additions & 6 deletions ServiceScan.SourceGenerator.Tests/GeneratedMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace GeneratorTests;
}
""";

Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -97,7 +97,7 @@ public static partial void AddServices(this IServiceCollection services)
}
""";

Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -137,7 +137,7 @@ public static partial IServiceCollection AddServices( IServiceCollection service
}
""";

Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -177,7 +177,7 @@ private partial void AddServices( IServiceCollection services)
}
""";

Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -216,7 +216,7 @@ public static partial IServiceCollection AddServices(this IServiceCollection ser
}
""";

Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

[Fact]
Expand Down Expand Up @@ -256,7 +256,7 @@ public static partial IServiceCollection AddServices(this IServiceCollection str
}
""";

Assert.Equal(expected, results.GeneratedTrees[1].ToString());
Assert.Equal(expected, results.GeneratedTrees[2].ToString());
}

private static Compilation CreateCompilation(params string[] source)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
{
context.RegisterPostInitializationOutput(context =>
{
context.AddEmbeddedAttributeDefinition();
context.AddSource("ServiceScanAttributes.Generated.cs", SourceText.From(GenerateAttributeInfo.Source, Encoding.UTF8));
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;

namespace ServiceScan.SourceGenerator.Extensions;

internal static class IncrementalGeneratorPostInitializationContextExtensions
{
private const string EmbeddedAttributeSource = """
namespace Microsoft.CodeAnalysis
{
internal sealed partial class EmbeddedAttribute : global::System.Attribute
{
}
}
""";

public static void AddEmbeddedAttributeDefinition(this IncrementalGeneratorPostInitializationContext context)
{
context.AddSource("Microsoft.CodeAnalysis.EmbeddedAttribute", SourceText.From(EmbeddedAttributeSource, Encoding.UTF8));
}
}
4 changes: 2 additions & 2 deletions ServiceScan.SourceGenerator/GenerateAttributeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ internal static class GenerateAttributeInfo
#nullable enable

using System;
using System.Diagnostics;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.DependencyInjection;

namespace ServiceScan.SourceGenerator;

[Conditional("CODE_ANALYSIS")]
[Embedded]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
internal class GenerateServiceRegistrationsAttribute : Attribute
{
Expand Down
Loading