11using System . Collections . Immutable ;
2- using System . Xml . Linq ;
32using Microsoft . CodeAnalysis ;
43using Microsoft . CodeAnalysis . CSharp ;
54using static ExampleTestsHelper ;
@@ -82,40 +81,32 @@ await AssertRunsEqual(firstResult, secondResult,
8281
8382 private static CompilationBuilder CreateCompilation ( CodeFileTheoryData theoryData )
8483 {
85- var srcDir = BaseDir ? . Parent ;
86- var packageVersionsFile = Path . Combine ( srcDir ? . FullName ?? "" , "Directory.Packages.props" ) ;
87-
88- var doc = XDocument . Load ( packageVersionsFile ) ;
89- var versionXml = doc . Root ? . Descendants ( "PackageVersion" )
90- . FirstOrDefault ( el => el . Attribute ( "Include" ) ? . Value == "Microsoft.Extensions.DependencyInjection.Abstractions" ) ;
91-
92- var version = versionXml ? . Attribute ( "Version" ) ? . Value ?? "9.0.8" ;
84+ var version = TestFileHelper . GetPackageVersion ( "Microsoft.Extensions.DependencyInjection.Abstractions" ) ;
9385
9486 return CreateCompilation < AutoConstructAttribute > ( theoryData )
95- . AddNugetReference (
96- "Microsoft.Extensions.DependencyInjection.Abstractions" , version ) ;
87+ . AddNugetReference ( "Microsoft.Extensions.DependencyInjection.Abstractions" , version ) ;
9788 }
9889
99- private static DirectoryInfo ? BaseDir { get ; } = new DirectoryInfo ( Environment . CurrentDirectory ) ? . Parent ? . Parent ;
100-
101- private static IEnumerable < string > GetExamplesFiles ( string path ) => Directory . GetFiles ( Path . Combine ( BaseDir ? . FullName ?? "" , path ) , "*.cs" ) . Where ( e => ! e . Contains ( ".g." ) ) ;
90+ private static IEnumerable < string > GetExamplesFiles ( string path )
91+ => Directory . GetFiles ( Path . Combine ( TestFileHelper . BaseDir ? . FullName ?? "" , path ) , "*.cs" )
92+ . Where ( e => ! e . Contains ( ".g." ) ) ;
10293
103- public static IEnumerable < CodeFileTheoryData > GetExamples ( )
94+ public static IEnumerable < Func < CodeFileTheoryData > > GetExamples ( )
10495 {
105- if ( BaseDir == null )
96+ if ( TestFileHelper . BaseDir is null )
10697 throw new Exception ( "BaseDir is null" ) ;
10798
10899 foreach ( var example in GetExamplesFiles ( "Examples" ) )
109100 {
110- yield return new CodeFileTheoryData ( example ) with
101+ yield return ( ) => new CodeFileTheoryData ( example ) with
111102 {
112103 IgnoredCompileDiagnostics = [ "CS0414" , "CS0169" ] // Ignore unused fields
113104 } ;
114105 }
115106
116107 foreach ( var guardExample in GetExamplesFiles ( "GuardExamples" ) )
117108 {
118- yield return new CodeFileTheoryData ( guardExample ) with
109+ yield return ( ) => new CodeFileTheoryData ( guardExample ) with
119110 {
120111 Options = new ( ) { { "build_property.AutoCtorGuards" , "true" } }
121112 } ;
@@ -124,7 +115,7 @@ public static IEnumerable<CodeFileTheoryData> GetExamples()
124115 foreach ( var langExample in GetExamplesFiles ( "LangExamples" ) )
125116 {
126117 var verifiedName = string . Concat ( "Verified_" , PreprocessorSymbols . Last ( ) . AsSpan ( 7 ) ) ;
127- yield return new CodeFileTheoryData ( langExample ) with
118+ yield return ( ) => new CodeFileTheoryData ( langExample ) with
128119 {
129120 VerifiedDirectory = Path . Combine ( Path . GetDirectoryName ( langExample ) ?? "" , verifiedName ) ,
130121 LangPreview = true ,
0 commit comments