Skip to content

Commit

Permalink
fix: generate the generic type parameter (#1173)
Browse files Browse the repository at this point in the history
* fix: generate the generic type parameter

* bump
  • Loading branch information
RLittlesII authored Mar 27, 2024
1 parent 3874937 commit 597061e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 21 deletions.
25 changes: 17 additions & 8 deletions src/Testing.AutoFixtures/AutoFixtureGenerator+StaticGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -89,15 +91,22 @@ private static ClassDeclarationSyntax BuildClassDeclaration(ISymbol namedTypeSym
BaseList(
SingletonSeparatedList<BaseTypeSyntax>(
SimpleBaseType(
IdentifierName(
Identifier(
TriviaList(),
nameof(AutoFixtureBase),
TriviaList(
LineFeed
GenericName(
Identifier(
TriviaList(),
nameof(AutoFixtureBase),
TriviaList(
LineFeed
)
)
)
.WithTypeArgumentList(
TypeArgumentList(
SingletonSeparatedList<TypeSyntax>(
IdentifierName(fixture)
)
)
)
)
)
)
)
Expand Down
7 changes: 4 additions & 3 deletions src/Testing.AutoFixtures/AutoFixtureGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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<AuthenticatorFixture>
{
public static implicit operator Authenticator(AuthenticatorFixture fixture) => fixture.Build();
public AuthenticatorFixture WithClient(Goony.Goo.Goo.IAuthenticationClient authenticationClient) => With(ref _authenticationClient, authenticationClient);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<DeckFixture>
{
public static implicit operator Deck(DeckFixture fixture) => fixture.Build();
public DeckFixture WithEnumerable(System.Collections.Generic.IEnumerable<Goony.Goo.Goo.Card> cards) => With(ref _cards, cards);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<AuthenticatorFixture>
{
public static implicit operator Authenticator(AuthenticatorFixture fixture) => fixture.Build();
public AuthenticatorFixture WithClient(Goony.Goo.Goo.IAuthenticationClient authenticationClient) => With(ref _authenticationClient, authenticationClient);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<AuthenticatorFixture>
{
public static implicit operator Authenticator(AuthenticatorFixture fixture) => fixture.Build();
public AuthenticatorFixture WithClient(Goony.Goo.Goo.IAuthenticationClient authenticationClient) => With(ref _authenticationClient, authenticationClient);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<AuthenticatorFixture>
{
public static implicit operator Authenticator(AuthenticatorFixture fixture) => fixture.Build();
public AuthenticatorFixture WithClient(Goony.Goo.Goo.IAuthenticationClient authenticationClient) => With(ref _authenticationClient, authenticationClient);
Expand Down

0 comments on commit 597061e

Please sign in to comment.