11using IntelliTect . Coalesce . Api . Behaviors ;
22using IntelliTect . Coalesce . Api . DataSources ;
3+ using IntelliTect . Coalesce . CodeGeneration . Configuration ;
34using IntelliTect . Coalesce . CodeGeneration . Generation ;
45using IntelliTect . Coalesce . CodeGeneration . Vue . Generators ;
56using IntelliTect . Coalesce . Testing ;
67using IntelliTect . Coalesce . Testing . TargetClasses . TestDbContext ;
78using IntelliTect . Coalesce . Testing . Util ;
9+ using IntelliTect . Coalesce . Validation ;
810using Microsoft . AspNetCore . Hosting ;
911using Microsoft . Extensions . DependencyInjection ;
1012using Moq ;
1113using Newtonsoft . Json ;
1214using Newtonsoft . Json . Linq ;
15+ using System . Reflection ;
16+ using System . Runtime . Versioning ;
17+ using TUnit . Core . Interfaces ;
1318
1419namespace IntelliTect . Coalesce . CodeGeneration . Tests ;
1520
16- public class TargetClassesFullGenerationTest : CodeGenTestBase
21+ public class VueSuiteFixture : IAsyncInitializer
22+ {
23+ public IRootGenerator Suite { get ; private set ; } = null ! ;
24+
25+ public async Task InitializeAsync ( )
26+ {
27+ var executor = new GenerationExecutor (
28+ new CoalesceConfiguration
29+ {
30+ WebProject = new ProjectConfiguration { RootNamespace = "MyProject" }
31+ } ,
32+ Microsoft . Extensions . Logging . LogLevel . Information
33+ ) ;
34+
35+ var suite = executor . CreateRootGenerator < VueSuite > ( )
36+ . WithModel ( ReflectionRepositoryFactory . Symbol ) ;
37+
38+ var validationResult = ValidateContext . Validate ( suite . Model ) ;
39+ await Assert . That ( validationResult . Where ( r => r . IsError ) ) . IsEmpty ( ) ;
40+
41+ var tfmAttr = System . Reflection . Assembly . GetExecutingAssembly ( ) . GetCustomAttribute < TargetFrameworkAttribute > ( ) ! ;
42+ var outDir = Path . Combine ( FilesystemExtensions . GetRepoRoot ( ) . FullName , "src" , "IntelliTect.Coalesce.CodeGeneration.Tests" , "out" , tfmAttr . FrameworkName ! , "VueSuite" ) ;
43+ suite = suite . WithOutputPath ( outDir ) ;
44+
45+ await suite . GenerateAsync ( ) ;
46+ Suite = suite ;
47+ }
48+ }
49+
50+ [ ClassDataSource < VueSuiteFixture > ( Shared = SharedType . PerTestSession ) ]
51+ public class TargetClassesFullGenerationTest ( VueSuiteFixture fixture ) : CodeGenTestBase
1752{
1853 // #IF directive so this doesn't needlessly run for multiple TFMs. It only needs to run for one.
1954#if NET10_0
@@ -55,44 +90,24 @@ public async Task CreateVitestTargets()
5590#endif
5691
5792 [ Test ]
58- public async Task VueOutputCompiles ( )
93+ [ Arguments ( "5" ) ]
94+ [ Arguments ( "5.9" ) ]
95+ [ Arguments ( "6" ) ]
96+ public async Task VueOutputTypescriptCompiles ( string tsVersion )
5997 {
60- var executor = BuildExecutor ( ) ;
61-
62- var suite = executor . CreateRootGenerator < VueSuite > ( )
63- . WithModel ( ReflectionRepositoryFactory . Symbol ) ;
64- suite = await ConfigureAndValidateSuite ( suite ) ;
65- await suite . GenerateAsync ( ) ;
66-
67- await Task . WhenAll (
68- Task . Run ( ( ) => AssertVueSuiteTypescriptOutputCompiles ( suite , "5" ) ) ,
69- Task . Run ( ( ) => AssertVueSuiteTypescriptOutputCompiles ( suite , "5.5" ) ) ,
70- Task . Run ( ( ) => AssertVueSuiteTypescriptOutputCompiles ( suite , "5.9" ) ) ,
71- Task . Run ( ( ) => AssertSuiteCSharpOutputCompiles ( suite ) )
72- ) ;
73- }
98+ var outputPath = fixture . Suite . EffectiveOutputPath . Replace ( "\\ " , "/" ) ;
7499
75- protected async Task AssertVueSuiteTypescriptOutputCompiles ( IRootGenerator suite , string tsVersion )
76- {
77- var coalesceVue = GetRepoRoot ( ) . GetDirectory ( "src/coalesce-vue" ) ;
78-
79- await Assert . That ( coalesceVue . GetDirectory ( "node_modules" ) . Exists ) . IsTrue ( ) . Because ( "Test relies on NPM packages for coalesce-vue being restored." ) ;
80-
81- // We use coalesce-vue as our working directory here
82- // because it contains both tsc and all the dependencies of the generated code.
83- var workingDirectory = coalesceVue . FullName . Replace ( "\\ " , "/" ) ;
84100 var tsConfig =
85101 $$ """
86102 {
87103 "compilerOptions": {
88104 "target": "ES2022",
105+ "module": "preserve",
106+ "moduleResolution": "bundler",
89107 "strict": true,
90- "moduleResolution": "node",
91108 "verbatimModuleSyntax": true,
92- "baseUrl": ".",
93109 "paths": {
94- "coalesce-vue/lib/*": [ "{{ workingDirectory }} /src/*" ],
95- "*": [ "{{ workingDirectory }} /node_modules/*" ],
110+ "coalesce-vue/lib/*": [ "../../node_modules/coalesce-vue/src/*" ],
96111 },
97112 "types": ["vue-router"]
98113 },
@@ -101,16 +116,22 @@ protected async Task AssertVueSuiteTypescriptOutputCompiles(IRootGenerator suite
101116 ],
102117 }
103118 """ ;
104- var tsConfigPath = $ "{ suite . EffectiveOutputPath } /tsconfig.{ tsVersion } .json";
119+ var tsConfigPath = $ "{ outputPath } /tsconfig.{ tsVersion } .json";
105120 File . WriteAllText ( tsConfigPath , tsConfig ) ;
106121
107122 await AssertTypescriptProjectCompiles (
108123 tsConfigPath : tsConfigPath ,
109- workingDirectory : workingDirectory ,
124+ workingDirectory : outputPath ,
110125 tsVersion : tsVersion
111126 ) ;
112127 }
113128
129+ [ Test ]
130+ public async Task VueOutputCSharpCompiles ( )
131+ {
132+ await AssertSuiteCSharpOutputCompiles ( fixture . Suite ) ;
133+ }
134+
114135 [ Test ]
115136 public async Task SecurityOverviewDataGenerates ( )
116137 {
0 commit comments