From 597061e3ab4434b56ace210f0f1624e3cf55a828 Mon Sep 17 00:00:00 2001 From: Rodney Littles II <6969701+RLittlesII@users.noreply.github.com> Date: Tue, 26 Mar 2024 19:45:29 -0500 Subject: [PATCH] fix: generate the generic type parameter (#1173) * fix: generate the generic type parameter * bump --- .../AutoFixtureGenerator+StaticGenerator.cs | 25 +++++++++++++------ .../AutoFixtureGenerator.cs | 7 +++--- ...de#Authenticator.AutoFixture.g.verified.cs | 5 ++-- ...0127f939922#Deck.AutoFixture.g.verified.cs | 5 ++-- ...de#Authenticator.AutoFixture.g.verified.cs | 5 ++-- ...de#Authenticator.AutoFixture.g.verified.cs | 5 ++-- ...fa#Authenticator.AutoFixture.g.verified.cs | 5 ++-- 7 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/Testing.AutoFixtures/AutoFixtureGenerator+StaticGenerator.cs b/src/Testing.AutoFixtures/AutoFixtureGenerator+StaticGenerator.cs index db18455733..b52b3f255c 100644 --- a/src/Testing.AutoFixtures/AutoFixtureGenerator+StaticGenerator.cs +++ b/src/Testing.AutoFixtures/AutoFixtureGenerator+StaticGenerator.cs @@ -38,10 +38,12 @@ private static NamespaceDeclarationSyntax BuildNamespace(ISymbol namedTypeSymbol private static ClassDeclarationSyntax BuildClassDeclaration(ISymbol namedTypeSymbol) { + var fixture = $"{namedTypeSymbol.Name}{Fixture}"; + return ClassDeclaration( Identifier( TriviaList(), - $"{namedTypeSymbol.Name}{Fixture}", + fixture, TriviaList( Space ) @@ -89,15 +91,22 @@ private static ClassDeclarationSyntax BuildClassDeclaration(ISymbol namedTypeSym BaseList( SingletonSeparatedList( SimpleBaseType( - IdentifierName( - Identifier( - TriviaList(), - nameof(AutoFixtureBase), - TriviaList( - LineFeed + GenericName( + Identifier( + TriviaList(), + nameof(AutoFixtureBase), + TriviaList( + LineFeed + ) + ) + ) + .WithTypeArgumentList( + TypeArgumentList( + SingletonSeparatedList( + IdentifierName(fixture) + ) ) ) - ) ) ) ) diff --git a/src/Testing.AutoFixtures/AutoFixtureGenerator.cs b/src/Testing.AutoFixtures/AutoFixtureGenerator.cs index 7049c8ad6c..e0c5228313 100644 --- a/src/Testing.AutoFixtures/AutoFixtureGenerator.cs +++ b/src/Testing.AutoFixtures/AutoFixtureGenerator.cs @@ -88,11 +88,11 @@ void GenerateFixtureBuilder( var usings = parameterSymbols - .Select(symbol => symbol.Type.ContainingNamespace?.ToDisplayString()) + .Select(symbol => symbol.Type.ContainingNamespace?.ToDisplayString() ?? string.Empty) .Where(x => !string.IsNullOrWhiteSpace(x)) .Distinct() .OrderBy(x => x) - .Select(x => UsingDirective(ParseName(x!))) + .Select(x => UsingDirective(ParseName(x))) .ToArray(); var mockLibrary = UsingDirective( @@ -106,9 +106,10 @@ void GenerateFixtureBuilder( ); var unit = CompilationUnit() - .AddUsings(mockLibrary) .AddUsings(UsingDirective(ParseName("System.Collections.ObjectModel"))) .AddUsings(usings) + .AddUsings(mockLibrary) + .AddUsings(UsingDirective(ParseName("Rocket.Surgery.Extensions.Testing.AutoFixtures"))) .AddMembers(namespaceDeclaration) .NormalizeWhitespace(); diff --git a/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenAutoFixtureAttributeUsage_WhenGenerate_ThenGeneratedAutoFixture_8dd3a84350cd8ade#Authenticator.AutoFixture.g.verified.cs b/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenAutoFixtureAttributeUsage_WhenGenerate_ThenGeneratedAutoFixture_8dd3a84350cd8ade#Authenticator.AutoFixture.g.verified.cs index e329eb0444..645a101160 100644 --- a/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenAutoFixtureAttributeUsage_WhenGenerate_ThenGeneratedAutoFixture_8dd3a84350cd8ade#Authenticator.AutoFixture.g.verified.cs +++ b/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenAutoFixtureAttributeUsage_WhenGenerate_ThenGeneratedAutoFixture_8dd3a84350cd8ade#Authenticator.AutoFixture.g.verified.cs @@ -1,12 +1,13 @@ //HintName: Rocket.Surgery.Extensions.Testing.AutoFixtures/Rocket.Surgery.Extensions.Testing.AutoFixtures.AutoFixtureGenerator/Authenticator.AutoFixture.g.cs -using NSubstitute; using System.Collections.ObjectModel; using Goony.Goo.Goo; using Microsoft.Extensions.Logging; +using NSubstitute; +using Rocket.Surgery.Extensions.Testing.AutoFixtures; namespace Goony.Goo.Goo.Tests { - internal sealed partial class AuthenticatorFixture : AutoFixtureBase + internal sealed partial class AuthenticatorFixture : AutoFixtureBase { public static implicit operator Authenticator(AuthenticatorFixture fixture) => fixture.Build(); public AuthenticatorFixture WithClient(Goony.Goo.Goo.IAuthenticationClient authenticationClient) => With(ref _authenticationClient, authenticationClient); diff --git a/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenDeckSource_WhenGenerate_ThenGeneratedAutoFixture_619350127f939922#Deck.AutoFixture.g.verified.cs b/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenDeckSource_WhenGenerate_ThenGeneratedAutoFixture_619350127f939922#Deck.AutoFixture.g.verified.cs index 24caad91cc..b2788a6512 100644 --- a/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenDeckSource_WhenGenerate_ThenGeneratedAutoFixture_619350127f939922#Deck.AutoFixture.g.verified.cs +++ b/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenDeckSource_WhenGenerate_ThenGeneratedAutoFixture_619350127f939922#Deck.AutoFixture.g.verified.cs @@ -1,11 +1,12 @@ //HintName: Rocket.Surgery.Extensions.Testing.AutoFixtures/Rocket.Surgery.Extensions.Testing.AutoFixtures.AutoFixtureGenerator/Deck.AutoFixture.g.cs -using NSubstitute; using System.Collections.ObjectModel; using System.Collections.Generic; +using NSubstitute; +using Rocket.Surgery.Extensions.Testing.AutoFixtures; namespace Goony.Goo.Goo.Tests { - internal sealed partial class DeckFixture : AutoFixtureBase + internal sealed partial class DeckFixture : AutoFixtureBase { public static implicit operator Deck(DeckFixture fixture) => fixture.Build(); public DeckFixture WithEnumerable(System.Collections.Generic.IEnumerable cards) => With(ref _cards, cards); diff --git a/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenFakeItEasy_WhenGenerate_ThenGeneratedAutoFixtureWithFakes_8dd3a84350cd8ade#Authenticator.AutoFixture.g.verified.cs b/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenFakeItEasy_WhenGenerate_ThenGeneratedAutoFixtureWithFakes_8dd3a84350cd8ade#Authenticator.AutoFixture.g.verified.cs index edc7f43365..5282790f7a 100644 --- a/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenFakeItEasy_WhenGenerate_ThenGeneratedAutoFixtureWithFakes_8dd3a84350cd8ade#Authenticator.AutoFixture.g.verified.cs +++ b/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenFakeItEasy_WhenGenerate_ThenGeneratedAutoFixtureWithFakes_8dd3a84350cd8ade#Authenticator.AutoFixture.g.verified.cs @@ -1,12 +1,13 @@ //HintName: Rocket.Surgery.Extensions.Testing.AutoFixtures/Rocket.Surgery.Extensions.Testing.AutoFixtures.AutoFixtureGenerator/Authenticator.AutoFixture.g.cs -using FakeItEasy; using System.Collections.ObjectModel; using Goony.Goo.Goo; using Microsoft.Extensions.Logging; +using FakeItEasy; +using Rocket.Surgery.Extensions.Testing.AutoFixtures; namespace Goony.Goo.Goo.Tests { - internal sealed partial class AuthenticatorFixture : AutoFixtureBase + internal sealed partial class AuthenticatorFixture : AutoFixtureBase { public static implicit operator Authenticator(AuthenticatorFixture fixture) => fixture.Build(); public AuthenticatorFixture WithClient(Goony.Goo.Goo.IAuthenticationClient authenticationClient) => With(ref _authenticationClient, authenticationClient); diff --git a/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenNSubstitute_WhenGenerate_ThenGeneratedAutoFixtureWithFakes_8dd3a84350cd8ade#Authenticator.AutoFixture.g.verified.cs b/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenNSubstitute_WhenGenerate_ThenGeneratedAutoFixtureWithFakes_8dd3a84350cd8ade#Authenticator.AutoFixture.g.verified.cs index e329eb0444..645a101160 100644 --- a/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenNSubstitute_WhenGenerate_ThenGeneratedAutoFixtureWithFakes_8dd3a84350cd8ade#Authenticator.AutoFixture.g.verified.cs +++ b/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenNSubstitute_WhenGenerate_ThenGeneratedAutoFixtureWithFakes_8dd3a84350cd8ade#Authenticator.AutoFixture.g.verified.cs @@ -1,12 +1,13 @@ //HintName: Rocket.Surgery.Extensions.Testing.AutoFixtures/Rocket.Surgery.Extensions.Testing.AutoFixtures.AutoFixtureGenerator/Authenticator.AutoFixture.g.cs -using NSubstitute; using System.Collections.ObjectModel; using Goony.Goo.Goo; using Microsoft.Extensions.Logging; +using NSubstitute; +using Rocket.Surgery.Extensions.Testing.AutoFixtures; namespace Goony.Goo.Goo.Tests { - internal sealed partial class AuthenticatorFixture : AutoFixtureBase + internal sealed partial class AuthenticatorFixture : AutoFixtureBase { public static implicit operator Authenticator(AuthenticatorFixture fixture) => fixture.Build(); public AuthenticatorFixture WithClient(Goony.Goo.Goo.IAuthenticationClient authenticationClient) => With(ref _authenticationClient, authenticationClient); diff --git a/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenSeparateNamespace_WhenGenerate_ThenGeneratedAutoFixtureWithFakes_530b28ef607437fa#Authenticator.AutoFixture.g.verified.cs b/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenSeparateNamespace_WhenGenerate_ThenGeneratedAutoFixtureWithFakes_530b28ef607437fa#Authenticator.AutoFixture.g.verified.cs index e329eb0444..645a101160 100644 --- a/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenSeparateNamespace_WhenGenerate_ThenGeneratedAutoFixtureWithFakes_530b28ef607437fa#Authenticator.AutoFixture.g.verified.cs +++ b/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.GivenSeparateNamespace_WhenGenerate_ThenGeneratedAutoFixtureWithFakes_530b28ef607437fa#Authenticator.AutoFixture.g.verified.cs @@ -1,12 +1,13 @@ //HintName: Rocket.Surgery.Extensions.Testing.AutoFixtures/Rocket.Surgery.Extensions.Testing.AutoFixtures.AutoFixtureGenerator/Authenticator.AutoFixture.g.cs -using NSubstitute; using System.Collections.ObjectModel; using Goony.Goo.Goo; using Microsoft.Extensions.Logging; +using NSubstitute; +using Rocket.Surgery.Extensions.Testing.AutoFixtures; namespace Goony.Goo.Goo.Tests { - internal sealed partial class AuthenticatorFixture : AutoFixtureBase + internal sealed partial class AuthenticatorFixture : AutoFixtureBase { public static implicit operator Authenticator(AuthenticatorFixture fixture) => fixture.Build(); public AuthenticatorFixture WithClient(Goony.Goo.Goo.IAuthenticationClient authenticationClient) => With(ref _authenticationClient, authenticationClient);