44 using System . Collections . Immutable ;
55 using System . Linq ;
66 using System . Threading ;
7- using GitBuildInfo . SourceGenerator ;
87 using Microsoft . CodeAnalysis ;
98 using Microsoft . CodeAnalysis . CSharp ;
109 using Microsoft . CodeAnalysis . Text ;
1312
1413 public class SourceGeneratorTests
1514 {
15+ [ Fact ]
16+ public void TestGeneratingDefaultNamespace ( )
17+ {
18+ var result = DoTest ( "Elskom.Generic.Libs.Test" , false , TestGenerate ) ;
19+ Assert . Equal ( @"// <autogenerated/>
20+ using Elskom.Generic.Libs;
21+
22+ [assembly: GitInformationAttribute(""fbgtgretgtre"", ""vfdbttregter"", ""vsdfvfdsv"", typeof(Test))]
23+ " , result ) ;
24+ }
25+
26+ [ Fact ]
27+ public void TestGeneratingNoNamespace ( )
28+ {
29+ var result = DoTest ( "Test" , false , TestGenerate ) ;
30+ Assert . Equal ( @"// <autogenerated/>
31+ using Elskom.Generic.Libs;
32+
33+ [assembly: GitInformationAttribute(""fbgtgretgtre"", ""vfdbttregter"", ""vsdfvfdsv"", typeof(Test))]
34+ " , result ) ;
35+ }
36+
1637 [ Fact ]
1738 public void TestGeneratingNonGeneric ( )
1839 {
@@ -55,7 +76,26 @@ public void TestVBGeneratingAbort()
5576 [ Fact ]
5677 public void TestGenerateWithOnlyOptions ( )
5778 {
58- var result = DoTest ( "TestNamespace.Test" , TestGenerateSingle ) ;
79+ var result = DoTest (
80+ @"{
81+ ""$schema"": ""https://raw.githubusercontent.com/Elskom/GitBuildInfo.SourceGenerator/main/settings.schema.json"",
82+ ""AssemblyType"": ""TestNamespace.Test"",
83+ ""IsGeneric"": false,
84+ }" ,
85+ TestGenerateOptionsOnly ) ;
86+ Assert . Equal ( string . Empty , result ) ;
87+ }
88+
89+ [ Fact ]
90+ public void TestGenerateWithOnlyGitInformation ( )
91+ {
92+ var result = DoTest (
93+ @"{
94+ ""GitHead"": ""fbgtgretgtre"",
95+ ""CommitHash"": ""vfdbttregter"",
96+ ""GitBranch"": ""vsdfvfdsv"",
97+ }" ,
98+ TestGenerateGitInformationOnly ) ;
5999 Assert . Equal ( string . Empty , result ) ;
60100 }
61101
@@ -74,25 +114,27 @@ private static string DoTest(string? assemblyType, bool generic, Func<string, st
74114 ""GitBranch"": ""vsdfvfdsv"",
75115}" ) ;
76116
77- private static string DoTest ( string ? assemblyType , Func < string , string > func )
78- => func . Invoke ( $@ "{{
79- ""$schema"": ""https://raw.githubusercontent.com/Elskom/GitBuildInfo.SourceGenerator/main/settings.schema.json"",
80- ""AssemblyType"": ""{ assemblyType } "",
81- ""IsGeneric"": false,
82- }}" ) ;
117+ private static string DoTest ( string text , Func < string , string > func )
118+ => func . Invoke ( text ) ;
83119
84120 private static string TestGenerate ( string optionsText , string gitInfoText )
85121 => TestGenerateInternal (
86122 CreateCSharpCompilation ( ) ,
87123 ImmutableArray . Create < AdditionalText > (
88- new CustomAdditionalText ( "GitBuildInfo.json" , optionsText ) ,
89- new CustomAdditionalText ( "GitInfo.json" , gitInfoText ) ) ) ;
124+ CreateGitBuildInfoText ( optionsText ) ,
125+ CreateGitInfoText ( gitInfoText ) ) ) ;
90126
91- private static string TestGenerateSingle ( string optionsText )
127+ private static string TestGenerateOptionsOnly ( string optionsText )
92128 => TestGenerateInternal (
93129 CreateCSharpCompilation ( ) ,
94130 ImmutableArray . Create < AdditionalText > (
95- new CustomAdditionalText ( "GitBuildInfo.json" , optionsText ) ) ) ;
131+ CreateGitBuildInfoText ( optionsText ) ) ) ;
132+
133+ private static string TestGenerateGitInformationOnly ( string gitInfoText )
134+ => TestGenerateInternal (
135+ CreateCSharpCompilation ( ) ,
136+ ImmutableArray . Create < AdditionalText > (
137+ CreateGitInfoText ( gitInfoText ) ) ) ;
96138
97139 private static string TestGenerateVB ( string optionsText , string gitInfoText )
98140 => TestGenerateInternal (
@@ -103,8 +145,8 @@ private static string TestGenerateVB(string optionsText, string gitInfoText)
103145 new VisualBasicCompilationOptions (
104146 OutputKind . DynamicallyLinkedLibrary ) ) ,
105147 ImmutableArray . Create < AdditionalText > (
106- new CustomAdditionalText ( "GitBuildInfo.json" , optionsText ) ,
107- new CustomAdditionalText ( "GitInfo.json" , gitInfoText ) ) ) ;
148+ CreateGitBuildInfoText ( optionsText ) ,
149+ CreateGitInfoText ( gitInfoText ) ) ) ;
108150
109151 private static string TestGenerateInternal ( Compilation compilation , ImmutableArray < AdditionalText > additionalTexts )
110152 {
@@ -134,6 +176,12 @@ private static Compilation CreateCSharpCompilation()
134176 new CSharpCompilationOptions (
135177 OutputKind . DynamicallyLinkedLibrary ) ) ;
136178
179+ private static CustomAdditionalText CreateGitBuildInfoText ( string text )
180+ => new ( "GitBuildInfo.json" , text ) ;
181+
182+ private static CustomAdditionalText CreateGitInfoText ( string text )
183+ => new ( "GitInfo.json" , text ) ;
184+
137185 private class CustomAdditionalText : AdditionalText
138186 {
139187 private readonly string _text ;
0 commit comments