@@ -4,8 +4,6 @@ namespace MattSourceGenHelpers.Tests;
44
55public class Tests
66{
7- private const char UnicodeBom = '\uFEFF ' ;
8-
97 [ Test ]
108 public void ColorsClassLikeGenerator_ProducesExpectedRuntimeOutput ( )
119 {
@@ -19,8 +17,7 @@ public void ColorsClassLikeGenerator_ProducesExpectedRuntimeOutput()
1917 [ Test ]
2018 public void ColorsClassLikeGenerator_ProducesExpectedGeneratedCode ( )
2119 {
22- string generatedCodePath = GetGeneratedCodePath ( ) ;
23- string generatedCode = File . ReadAllText ( generatedCodePath ) . TrimStart ( UnicodeBom ) . ReplaceLineEndings ( "\n " ) . TrimEnd ( ) ;
20+ string generatedCode = GeneratedCodeTestHelper . ReadGeneratedCode ( "TestColorsClass_GetAllColorsString.g.cs" ) ;
2421 string expectedCode = """
2522 namespace MattSourceGenHelpers.Tests;
2623
@@ -35,37 +32,6 @@ public partial string GetAllColorsString()
3532
3633 Assert . That ( generatedCode , Is . EqualTo ( expectedCode ) ) ;
3734 }
38-
39- private static string GetGeneratedCodePath ( )
40- {
41- string projectDirectory = FindProjectDirectory ( ) ;
42- string [ ] generatedFiles = Directory . GetFiles ( projectDirectory , "TestColorsClass_GetAllColorsString.g.cs" , SearchOption . AllDirectories ) ;
43-
44- if ( generatedFiles . Length != 1 )
45- {
46- throw new AssertionException ( $ "Expected exactly one generated file, but found { generatedFiles . Length } .") ;
47- }
48-
49- return generatedFiles [ 0 ] ;
50- }
51-
52- private static string FindProjectDirectory ( )
53- {
54- string ? currentDirectory = TestContext . CurrentContext . TestDirectory ;
55-
56- while ( currentDirectory is not null )
57- {
58- string projectFilePath = Path . Combine ( currentDirectory , "MattSourceGenHelpers.Tests.csproj" ) ;
59- if ( File . Exists ( projectFilePath ) )
60- {
61- return currentDirectory ;
62- }
63-
64- currentDirectory = Directory . GetParent ( currentDirectory ) ? . FullName ;
65- }
66-
67- throw new DirectoryNotFoundException ( "Could not locate MattSourceGenHelpers.Tests project directory." ) ;
68- }
6935}
7036
7137public enum TestColorsEnum
0 commit comments