diff --git a/tests/Immediate.Apis.Tests/.editorconfig b/tests/Immediate.Apis.Tests/.editorconfig index 7944128..20168be 100644 --- a/tests/Immediate.Apis.Tests/.editorconfig +++ b/tests/Immediate.Apis.Tests/.editorconfig @@ -1,3 +1,7 @@ +[*.cs] + +dotnet_diagnostic.CA1822.severity = none # CA1822: Mark members as static + [*.g.verified.cs] # Mark code as excluded and generated diff --git a/tests/Immediate.Apis.Tests/AnalyzerTests/AnalyzerTestHelpers.cs b/tests/Immediate.Apis.Tests/AnalyzerTests/AnalyzerTestHelpers.cs index 3cc37bd..e0e8be2 100644 --- a/tests/Immediate.Apis.Tests/AnalyzerTests/AnalyzerTestHelpers.cs +++ b/tests/Immediate.Apis.Tests/AnalyzerTests/AnalyzerTestHelpers.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Testing; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Testing; @@ -7,7 +8,7 @@ namespace Immediate.Apis.Tests.AnalyzerTests; public static class AnalyzerTestHelpers { public static CSharpAnalyzerTest CreateAnalyzerTest( - string inputSource + [StringSyntax("c#-test")] string inputSource ) where TAnalyzer : DiagnosticAnalyzer, new() { diff --git a/tests/Immediate.Apis.Tests/AnalyzerTests/CustomizeEndpointUsageAnalyzerTests.cs b/tests/Immediate.Apis.Tests/AnalyzerTests/CustomizeEndpointUsageAnalyzerTests.cs index 3c359b1..c631254 100644 --- a/tests/Immediate.Apis.Tests/AnalyzerTests/CustomizeEndpointUsageAnalyzerTests.cs +++ b/tests/Immediate.Apis.Tests/AnalyzerTests/CustomizeEndpointUsageAnalyzerTests.cs @@ -4,8 +4,8 @@ namespace Immediate.Apis.Tests.AnalyzerTests; public sealed class CustomizeEndpointUsageAnalyzerTests { - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task ValidDefinitionShouldNotWarn(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" @@ -39,8 +39,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task MultipleDefinitionShouldNotWarn(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" @@ -77,8 +77,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task InvalidAccessibilityShouldWarn(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" @@ -112,8 +112,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task InstanceMethodShouldWarn(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" @@ -147,8 +147,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task InvalidReturnShouldWarn(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" @@ -182,8 +182,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task InvalidParameterTypeShouldWarn(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" diff --git a/tests/Immediate.Apis.Tests/AnalyzerTests/InvalidAuthorizeAttributeAnalyzerTests.cs b/tests/Immediate.Apis.Tests/AnalyzerTests/InvalidAuthorizeAttributeAnalyzerTests.cs index 9fdcec4..7380150 100644 --- a/tests/Immediate.Apis.Tests/AnalyzerTests/InvalidAuthorizeAttributeAnalyzerTests.cs +++ b/tests/Immediate.Apis.Tests/AnalyzerTests/InvalidAuthorizeAttributeAnalyzerTests.cs @@ -4,10 +4,10 @@ namespace Immediate.Apis.Tests.AnalyzerTests; public sealed class InvalidAuthorizeAttributeAnalyzerTests { - [Fact] + [Test] public async Task AuthorizeAloneShouldNotError() => await AnalyzerTestHelpers.CreateAnalyzerTest( - $$""" + """ using System.Threading; using System.Threading.Tasks; using Immediate.Apis.Shared; @@ -32,8 +32,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task AuthorizeRolesShouldError(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" @@ -62,8 +62,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task AuthorizeAuthenticationSchemesShouldError(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" @@ -92,8 +92,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task AuthorizeShouldNotError(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" @@ -122,8 +122,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task AuthorizeConstructorShouldNotError(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" @@ -152,8 +152,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task AuthorizePolicyShouldNotError(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" @@ -182,8 +182,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task AuthorizeAndAllowAnonymousShouldWarn(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" diff --git a/tests/Immediate.Apis.Tests/AnalyzerTests/MissingCustomizeEndpointMethodAnalyzerTests.cs b/tests/Immediate.Apis.Tests/AnalyzerTests/MissingCustomizeEndpointMethodAnalyzerTests.cs index 12fe0d1..a0758c0 100644 --- a/tests/Immediate.Apis.Tests/AnalyzerTests/MissingCustomizeEndpointMethodAnalyzerTests.cs +++ b/tests/Immediate.Apis.Tests/AnalyzerTests/MissingCustomizeEndpointMethodAnalyzerTests.cs @@ -9,8 +9,8 @@ namespace Immediate.Apis.Tests.AnalyzerTests; [SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Test names")] public sealed class MissingCustomizeEndpointMethodAnalyzerTests { - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task ValidDefinitionShouldRaiseHiddenDiagnostic(string method) { await AnalyzerTestHelpers.CreateAnalyzerTest( @@ -40,8 +40,8 @@ private static async ValueTask Handle( ).RunAsync(); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task ValidDefinition_WithExistingCustomizeEndpointMethod_ShouldNotRaiseHiddenDiagnostic(string method) { await AnalyzerTestHelpers.CreateAnalyzerTest( diff --git a/tests/Immediate.Apis.Tests/AnalyzerTests/MissingHandlerAttributeAnalyzerTests.cs b/tests/Immediate.Apis.Tests/AnalyzerTests/MissingHandlerAttributeAnalyzerTests.cs index a09a17a..d17e9de 100644 --- a/tests/Immediate.Apis.Tests/AnalyzerTests/MissingHandlerAttributeAnalyzerTests.cs +++ b/tests/Immediate.Apis.Tests/AnalyzerTests/MissingHandlerAttributeAnalyzerTests.cs @@ -4,8 +4,8 @@ namespace Immediate.Apis.Tests.AnalyzerTests; public sealed class MissingHandlerAttributeAnalyzerTests { - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task MissingHandlerAttributeShouldError(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" diff --git a/tests/Immediate.Apis.Tests/AnalyzerTests/MissingTransformResultMethodAnalyzerTests.cs b/tests/Immediate.Apis.Tests/AnalyzerTests/MissingTransformResultMethodAnalyzerTests.cs index f0911ab..93316e7 100644 --- a/tests/Immediate.Apis.Tests/AnalyzerTests/MissingTransformResultMethodAnalyzerTests.cs +++ b/tests/Immediate.Apis.Tests/AnalyzerTests/MissingTransformResultMethodAnalyzerTests.cs @@ -9,8 +9,8 @@ namespace Immediate.Apis.Tests.AnalyzerTests; [SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Test names")] public sealed class MissingTransformResultMethodAnalyzerTests { - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task ValidDefinitionShouldRaiseHiddenDiagnostic(string method) { await AnalyzerTestHelpers.CreateAnalyzerTest( @@ -40,8 +40,8 @@ private static async ValueTask Handle( ).RunAsync(); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task ValidDefinition_WithExistingTransformResultMethod_ShouldNotRaiseHiddenDiagnostic(string method) { await AnalyzerTestHelpers.CreateAnalyzerTest( @@ -77,8 +77,8 @@ private static async ValueTask Handle( ).RunAsync(); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task InvalidDefinition_ShouldNotRaiseHiddenDiagnostic(string method) { await AnalyzerTestHelpers.CreateAnalyzerTest( diff --git a/tests/Immediate.Apis.Tests/AnalyzerTests/TransformResultUsageAnalyzerTests.cs b/tests/Immediate.Apis.Tests/AnalyzerTests/TransformResultUsageAnalyzerTests.cs index a0afed5..c657272 100644 --- a/tests/Immediate.Apis.Tests/AnalyzerTests/TransformResultUsageAnalyzerTests.cs +++ b/tests/Immediate.Apis.Tests/AnalyzerTests/TransformResultUsageAnalyzerTests.cs @@ -4,8 +4,8 @@ namespace Immediate.Apis.Tests.AnalyzerTests; public sealed class TransformResultUsageAnalyzerTests { - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task ValidDefinitionShouldNotWarn(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" @@ -34,8 +34,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task MultipleDefinitionShouldNotWarn(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" @@ -65,8 +65,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task InvalidAccessibilityShouldWarn(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" @@ -95,8 +95,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task InstanceMethodShouldWarn(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" @@ -125,8 +125,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task InvalidParameterTypeShouldWarn(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" @@ -155,8 +155,8 @@ private static async ValueTask Handle( """ ).RunAsync(); - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task VoidReturnShouldWarn(string method) => await AnalyzerTestHelpers.CreateAnalyzerTest( $$""" diff --git a/tests/Immediate.Apis.Tests/CodeFixTests/CodeFixTestHelper.cs b/tests/Immediate.Apis.Tests/CodeFixTests/CodeFixTestHelper.cs index 961df6f..7ddf043 100644 --- a/tests/Immediate.Apis.Tests/CodeFixTests/CodeFixTestHelper.cs +++ b/tests/Immediate.Apis.Tests/CodeFixTests/CodeFixTestHelper.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Testing; using Microsoft.CodeAnalysis.Diagnostics; @@ -19,8 +20,8 @@ public static class CodeFixTestHelper """; public static CSharpCodeFixTest CreateCodeFixTest( - string inputSource, - string fixedSource, + [StringSyntax("c#-test")] string inputSource, + [StringSyntax("c#-test")] string fixedSource, int codeActionIndex = 0 ) where TAnalyzer : DiagnosticAnalyzer, new() diff --git a/tests/Immediate.Apis.Tests/CodeFixTests/MissingCustomizeEndpointMethodCodeFixTests.cs b/tests/Immediate.Apis.Tests/CodeFixTests/MissingCustomizeEndpointMethodCodeFixTests.cs index b0c82c0..e5c3f3b 100644 --- a/tests/Immediate.Apis.Tests/CodeFixTests/MissingCustomizeEndpointMethodCodeFixTests.cs +++ b/tests/Immediate.Apis.Tests/CodeFixTests/MissingCustomizeEndpointMethodCodeFixTests.cs @@ -7,8 +7,8 @@ namespace Immediate.Apis.Tests.CodeFixTests; [SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Test names")] public sealed class MissingCustomizeEndpointMethodCodeFixTests { - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task ValidDefinition_ShouldAddCustomizeEndpointMethod(string method) { await CodeFixTestHelper diff --git a/tests/Immediate.Apis.Tests/CodeFixTests/MissingHandlerAttributeCodeFixTests.cs b/tests/Immediate.Apis.Tests/CodeFixTests/MissingHandlerAttributeCodeFixTests.cs index 0d5eaa9..72bb6fa 100644 --- a/tests/Immediate.Apis.Tests/CodeFixTests/MissingHandlerAttributeCodeFixTests.cs +++ b/tests/Immediate.Apis.Tests/CodeFixTests/MissingHandlerAttributeCodeFixTests.cs @@ -7,8 +7,8 @@ namespace Immediate.Apis.Tests.CodeFixTests; [SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Test names")] public sealed class MissingHandlerAttributeCodeFixTests { - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task MissingHandlerAttribute_ShouldAddAttributeAndUsing(string method) { await CodeFixTestHelper @@ -58,8 +58,8 @@ private static async ValueTask Handle( ).RunAsync(); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task MissingHandlerAttributeWithUsing_ShouldAddAttributeOnly(string method) { await CodeFixTestHelper diff --git a/tests/Immediate.Apis.Tests/CodeFixTests/MissingTransformResultMethodCodeFixTests.cs b/tests/Immediate.Apis.Tests/CodeFixTests/MissingTransformResultMethodCodeFixTests.cs index 7aee9a9..3454df7 100644 --- a/tests/Immediate.Apis.Tests/CodeFixTests/MissingTransformResultMethodCodeFixTests.cs +++ b/tests/Immediate.Apis.Tests/CodeFixTests/MissingTransformResultMethodCodeFixTests.cs @@ -7,8 +7,8 @@ namespace Immediate.Apis.Tests.CodeFixTests; [SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Test names")] public sealed class MissingTransformResultMethodCodeFixTests { - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task ValidDefinition_ShouldAddTransformResultMethod(string method) { await CodeFixTestHelper diff --git a/tests/Immediate.Apis.Tests/Directory.Packages.props b/tests/Immediate.Apis.Tests/Directory.Packages.props index d8337f2..78c00ab 100644 --- a/tests/Immediate.Apis.Tests/Directory.Packages.props +++ b/tests/Immediate.Apis.Tests/Directory.Packages.props @@ -22,16 +22,14 @@ - + - - - + diff --git a/tests/Immediate.Apis.Tests/GeneratorTests/ApiAllowAnonymousTests.cs b/tests/Immediate.Apis.Tests/GeneratorTests/ApiAllowAnonymousTests.cs index d345b57..e248164 100644 --- a/tests/Immediate.Apis.Tests/GeneratorTests/ApiAllowAnonymousTests.cs +++ b/tests/Immediate.Apis.Tests/GeneratorTests/ApiAllowAnonymousTests.cs @@ -2,11 +2,11 @@ namespace Immediate.Apis.Tests.GeneratorTests; public sealed class ApiAllowAnonymousTests { - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task MapMethodWithAllowAnonymousTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -32,15 +32,14 @@ private static ValueTask HandleAsync( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } diff --git a/tests/Immediate.Apis.Tests/GeneratorTests/ApiAuthorizeTests.cs b/tests/Immediate.Apis.Tests/GeneratorTests/ApiAuthorizeTests.cs index 0af1949..b25813e 100644 --- a/tests/Immediate.Apis.Tests/GeneratorTests/ApiAuthorizeTests.cs +++ b/tests/Immediate.Apis.Tests/GeneratorTests/ApiAuthorizeTests.cs @@ -2,11 +2,11 @@ namespace Immediate.Apis.Tests.GeneratorTests; public sealed class ApiAuthorizeTests { - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task MapMethodWithSimpleAuthorizeTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -32,24 +32,23 @@ private static ValueTask HandleAsync( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task MapMethodWithAuthorizeConstructorTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -75,24 +74,23 @@ private static ValueTask HandleAsync( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task MapMethodWithAuthorizeNamedPolicyArgumentTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -118,15 +116,14 @@ private static ValueTask HandleAsync( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } diff --git a/tests/Immediate.Apis.Tests/GeneratorTests/CustomizeEndpointsTests.cs b/tests/Immediate.Apis.Tests/GeneratorTests/CustomizeEndpointsTests.cs index b5e368a..a56d865 100644 --- a/tests/Immediate.Apis.Tests/GeneratorTests/CustomizeEndpointsTests.cs +++ b/tests/Immediate.Apis.Tests/GeneratorTests/CustomizeEndpointsTests.cs @@ -2,11 +2,11 @@ namespace Immediate.Apis.Tests.GeneratorTests; public sealed class CustomizeEndpointsTests { - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task MapMethodCustomizeEndpointTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -36,15 +36,14 @@ private static ValueTask HandleAsync( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } diff --git a/tests/Immediate.Apis.Tests/GeneratorTests/GeneratorTestHelper.cs b/tests/Immediate.Apis.Tests/GeneratorTests/GeneratorTestHelper.cs index 2d447c9..56eaf6e 100644 --- a/tests/Immediate.Apis.Tests/GeneratorTests/GeneratorTestHelper.cs +++ b/tests/Immediate.Apis.Tests/GeneratorTests/GeneratorTestHelper.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using Immediate.Apis.Generators; using Immediate.Handlers.Generators.ImmediateHandlers; using Microsoft.CodeAnalysis; @@ -7,7 +8,7 @@ namespace Immediate.Apis.Tests.GeneratorTests; public static class GeneratorTestHelper { - public static GeneratorDriverRunResult RunGenerator(string source) + public static async Task RunGenerator([StringSyntax("c#-test")] string source) { var syntaxTree = CSharpSyntaxTree.ParseText(source); @@ -34,13 +35,15 @@ .. Utility.GetMetadataReferences(), out var diagnostics ); - Assert.Empty( - outputCompilation - .GetDiagnostics() - .Where(d => d.Severity is DiagnosticSeverity.Error or DiagnosticSeverity.Warning) - ); + _ = await Assert + .That( + outputCompilation + .GetDiagnostics() + .Where(d => d.Severity is DiagnosticSeverity.Error or DiagnosticSeverity.Warning) + ) + .IsEmpty(); - Assert.Empty(diagnostics); + _ = await Assert.That(diagnostics).IsEmpty(); return driver.GetRunResult(); } } diff --git a/tests/Immediate.Apis.Tests/GeneratorTests/InvalidCodeTests.cs b/tests/Immediate.Apis.Tests/GeneratorTests/InvalidCodeTests.cs index c5ea68d..0a6cc95 100644 --- a/tests/Immediate.Apis.Tests/GeneratorTests/InvalidCodeTests.cs +++ b/tests/Immediate.Apis.Tests/GeneratorTests/InvalidCodeTests.cs @@ -2,11 +2,11 @@ namespace Immediate.Apis.Tests.GeneratorTests; public sealed class InvalidCodeTests { - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task MissingHandlerAttribute(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -28,21 +28,20 @@ private static ValueTask Handle( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task MissingHandler(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading.Tasks; using Immediate.Apis.Shared; @@ -58,19 +57,18 @@ public record Query; } """); - Assert.Equal( - [], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEmpty(); _ = await Verify(result).UseParameters(method); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task InvalidHandler(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading.Tasks; using Immediate.Apis.Shared; @@ -91,19 +89,18 @@ private static ValueTask Handle() } """); - Assert.Equal( - [], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEmpty(); _ = await Verify(result).UseParameters(method); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task AuthorizeUsesAuthenticationSchemes(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -129,22 +126,21 @@ private static ValueTask HandleAsync( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task AuthorizeUsesRoles(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -170,13 +166,12 @@ private static ValueTask HandleAsync( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } diff --git a/tests/Immediate.Apis.Tests/GeneratorTests/ParameterAttributeTests.cs b/tests/Immediate.Apis.Tests/GeneratorTests/ParameterAttributeTests.cs index 199843d..0a5f891 100644 --- a/tests/Immediate.Apis.Tests/GeneratorTests/ParameterAttributeTests.cs +++ b/tests/Immediate.Apis.Tests/GeneratorTests/ParameterAttributeTests.cs @@ -2,11 +2,11 @@ namespace Immediate.Apis.Tests.GeneratorTests; public sealed class ParameterAttributeTests { - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task IFormFileTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -34,24 +34,23 @@ private static ValueTask Handle( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task AsParametersTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -78,24 +77,23 @@ private static ValueTask Handle( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task FromBodyTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -122,24 +120,23 @@ private static ValueTask Handle( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task FromFormTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -166,24 +163,23 @@ private static ValueTask Handle( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task FromHeaderTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -210,24 +206,23 @@ private static ValueTask Handle( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task FromQueryTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -254,24 +249,23 @@ private static ValueTask Handle( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task FromRouteTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -298,15 +292,14 @@ private static ValueTask Handle( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } diff --git a/tests/Immediate.Apis.Tests/GeneratorTests/SimpleApiTests.cs b/tests/Immediate.Apis.Tests/GeneratorTests/SimpleApiTests.cs index 632887b..95845c5 100644 --- a/tests/Immediate.Apis.Tests/GeneratorTests/SimpleApiTests.cs +++ b/tests/Immediate.Apis.Tests/GeneratorTests/SimpleApiTests.cs @@ -2,11 +2,11 @@ namespace Immediate.Apis.Tests.GeneratorTests; public sealed class SimpleApiTests { - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task MapMethodHandleTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -30,24 +30,23 @@ private static ValueTask Handle( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task MapMethodHandleAsyncTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -71,24 +70,23 @@ private static ValueTask HandleAsync( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task MapMultipleHandlersTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -126,25 +124,24 @@ private static ValueTask HandleAsync( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUserQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUserQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } - [Fact] + [Test] public async Task MapCustomMethodHandleTest() { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -168,23 +165,22 @@ private static ValueTask Handle( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result); } - [Fact] + [Test] public async Task MapCustomMethodHandleAsyncTest() { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -208,15 +204,14 @@ private static ValueTask HandleAsync( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result); } diff --git a/tests/Immediate.Apis.Tests/GeneratorTests/TransformResultTests.cs b/tests/Immediate.Apis.Tests/GeneratorTests/TransformResultTests.cs index 83526eb..0d4e6a6 100644 --- a/tests/Immediate.Apis.Tests/GeneratorTests/TransformResultTests.cs +++ b/tests/Immediate.Apis.Tests/GeneratorTests/TransformResultTests.cs @@ -2,11 +2,11 @@ namespace Immediate.Apis.Tests.GeneratorTests; public sealed class TransformResultTests { - [Theory] - [MemberData(nameof(Utility.Methods), MemberType = typeof(Utility))] + [Test] + [MethodDataSource(typeof(Utility), nameof(Utility.Methods))] public async Task TransformTest(string method) { - var result = GeneratorTestHelper.RunGenerator( + var result = await GeneratorTestHelper.RunGenerator( $$""" using System.Threading; using System.Threading.Tasks; @@ -32,15 +32,14 @@ private static ValueTask Handle( } """); - Assert.Equal( - [ + _ = await Assert + .That(result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/'))) + .IsEquivalentCollectionTo([ @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RouteBuilder.Dummy_GetUsersQuery.g.cs", @"Immediate.Apis.Generators/Immediate.Apis.Generators.ImmediateApisGenerator/RoutesBuilder.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.Dummy.GetUsersQuery.g.cs", @"Immediate.Handlers.Generators/Immediate.Handlers.Generators.ImmediateHandlers.ImmediateHandlersGenerator/IH.ServiceCollectionExtensions.g.cs", - ], - result.GeneratedTrees.Select(t => t.FilePath.Replace('\\', '/')) - ); + ]); _ = await Verify(result).UseParameters(method); } diff --git a/tests/Immediate.Apis.Tests/Immediate.Apis.Tests.csproj b/tests/Immediate.Apis.Tests/Immediate.Apis.Tests.csproj index bccde73..33854e6 100644 --- a/tests/Immediate.Apis.Tests/Immediate.Apis.Tests.csproj +++ b/tests/Immediate.Apis.Tests/Immediate.Apis.Tests.csproj @@ -17,11 +17,10 @@ - + + - - - + diff --git a/tests/Immediate.Apis.Tests/Utility.cs b/tests/Immediate.Apis.Tests/Utility.cs index 1167028..f2e3b37 100644 --- a/tests/Immediate.Apis.Tests/Utility.cs +++ b/tests/Immediate.Apis.Tests/Utility.cs @@ -17,12 +17,12 @@ public static MetadataReference[] GetMetadataReferences() => MetadataReference.CreateFromFile("./Microsoft.Extensions.Primitives.dll"), ]; - public static TheoryData Methods() => - new([ + public static IReadOnlyList Methods() => + [ "Get", "Post", "Patch", "Put", "Delete", - ]); + ]; }