diff --git a/src/Testing.AutoFixtures/Attribute.cs b/src/Testing.AutoFixtures/Attribute.cs index f8f4a3c4..0ed3c826 100644 --- a/src/Testing.AutoFixtures/Attribute.cs +++ b/src/Testing.AutoFixtures/Attribute.cs @@ -2,21 +2,22 @@ namespace Rocket.Surgery.Extensions.Testing.AutoFixtures; internal static class Attribute { - public const string Source = @"#nullable enable + public static readonly string source = @$"#nullable enable using System; using System.Diagnostics; namespace Rocket.Surgery.Extensions.Testing.AutoFixtures -{ +{{ + {AutoFixtures.CodeGenerationAttribute} [AttributeUsage(AttributeTargets.Class)] [Conditional(""CODEGEN"")] internal class AutoFixtureAttribute : Attribute - { - public AutoFixtureAttribute() : this(null) {} + {{ + public AutoFixtureAttribute() : this(null) {{}} public AutoFixtureAttribute(Type? type) => Type = type; - public Type? Type { get; } - } -}"; + public Type? Type {{ get; }} + }} +}}"; } \ No newline at end of file diff --git a/src/Testing.AutoFixtures/AutoFixtureGenerator.cs b/src/Testing.AutoFixtures/AutoFixtureGenerator.cs index 27ee48e8..49ae1c8a 100644 --- a/src/Testing.AutoFixtures/AutoFixtureGenerator.cs +++ b/src/Testing.AutoFixtures/AutoFixtureGenerator.cs @@ -26,7 +26,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) context.RegisterPostInitializationOutput( initializationContext => { - initializationContext.AddSource("AutoFixtureAttribute.g.cs", Attribute.Source); + initializationContext.AddSource("AutoFixtureAttribute.g.cs", Attribute.source); initializationContext.AddSource($"{nameof(AutoFixtureBase)}.g.cs", AutoFixtureBase.Source); } ); @@ -108,10 +108,12 @@ void generateFixtureBuilder( usingDirectives.Add(substituteMetadata.ContainingNamespace.ToDisplayString()); } - var usingDirectiveSyntax = usingDirectives - .OrderBy(usingDirective => usingDirective, NamespaceComparer.Default) - .Select(x => UsingDirective(ParseName(x))) - .ToArray(); + var usingDirectiveSyntax = + usingDirectives + .OrderBy(usingDirective => usingDirective, NamespaceComparer.Default) + .Select(x => UsingDirective(ParseName(x))) + .ToArray(); + var unit = CompilationUnit() .AddUsings(usingDirectiveSyntax) diff --git a/src/Testing.AutoFixtures/AutoFixtures.cs b/src/Testing.AutoFixtures/AutoFixtures.cs new file mode 100644 index 00000000..2a634339 --- /dev/null +++ b/src/Testing.AutoFixtures/AutoFixtures.cs @@ -0,0 +1,9 @@ +using System.Diagnostics; + +namespace Rocket.Surgery.Extensions.Testing.AutoFixtures; + +internal static class AutoFixtures +{ + public static string Version { get; } = FileVersionInfo.GetVersionInfo(typeof(AutoFixtureGenerator).Assembly.Location).ProductVersion; + public static string CodeGenerationAttribute { get; } = $@"[System.CodeDom.Compiler.GeneratedCode(""AutoFixtures"", ""{Version}"")]"; +} \ No newline at end of file diff --git a/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.cs b/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.cs index 861472fb..14c65501 100644 --- a/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.cs +++ b/test/Testing.AutoFixtures.Tests/AutoFixtureGeneratorTests.cs @@ -21,7 +21,7 @@ public async Task GivenAutoFixture_WhenGenerate_ThenShouldGenerateAutoFixtureAtt var result = await generatorInstance.GenerateAsync(); // Then - await Verify(result); + await Verify(result).ScrubLines(text => text.Contains("System.CodeDom.Compiler.GeneratedCode")); } [Fact]