@@ -30,7 +30,7 @@ namespace Microsoft.Windows.Powershell.ScriptAnalyzer.BuiltinRules
3030 /// Tests folder should contain test script for given resource - file name should contain resource's name.
3131 /// </summary>
3232 [ Export ( typeof ( IDSCResourceRule ) ) ]
33- public class DscExamplesPresent : IDSCResourceRule
33+ public class DscTestsPresent : IDSCResourceRule
3434 {
3535 /// <summary>
3636 /// AnalyzeDSCResource: Analyzes given DSC Resource
@@ -40,7 +40,29 @@ public class DscExamplesPresent : IDSCResourceRule
4040 /// <returns>The results of the analysis</returns>
4141 public IEnumerable < DiagnosticRecord > AnalyzeDSCResource ( Ast ast , string fileName )
4242 {
43-
43+ String fileNameOnly = Path . GetFileName ( fileName ) ;
44+ String resourceName = Path . GetFileNameWithoutExtension ( fileNameOnly ) ;
45+ String testsQuery = String . Format ( "*{0}*" , resourceName ) ;
46+ Boolean testsPresent = false ;
47+ String expectedTestsPath = Path . Combine ( new String [ ] { fileName , ".." , ".." , ".." , "Tests" } ) ;
48+
49+ // Verify tests are present
50+ if ( Directory . Exists ( expectedTestsPath ) )
51+ {
52+ DirectoryInfo testsFolder = new DirectoryInfo ( expectedTestsPath ) ;
53+ FileInfo [ ] testFiles = testsFolder . GetFiles ( testsQuery ) ;
54+ if ( testFiles . Length != 0 )
55+ {
56+ testsPresent = true ;
57+ }
58+ }
59+
60+ // Return error if no tests present
61+ if ( ! testsPresent )
62+ {
63+ yield return new DiagnosticRecord ( string . Format ( CultureInfo . CurrentCulture , Strings . DscTestsPresentNoTestsError , resourceName ) ,
64+ ast . Extent , GetName ( ) , DiagnosticSeverity . Information , fileName ) ;
65+ }
4466 }
4567
4668 /// <summary>
@@ -60,7 +82,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCClass(Ast ast, string fileName)
6082 /// <returns>The name of this rule</returns>
6183 public string GetName ( )
6284 {
63- return string . Format ( CultureInfo . CurrentCulture , Strings . NameSpaceFormat , GetSourceName ( ) , Strings . DscExamplesPresent ) ;
85+ return string . Format ( CultureInfo . CurrentCulture , Strings . NameSpaceFormat , GetSourceName ( ) , Strings . DscTestsPresent ) ;
6486 }
6587
6688 /// <summary>
@@ -69,7 +91,7 @@ public string GetName()
6991 /// <returns>The common name of this rule</returns>
7092 public string GetCommonName ( )
7193 {
72- return string . Format ( CultureInfo . CurrentCulture , Strings . DscExamplesPresentCommonName ) ;
94+ return string . Format ( CultureInfo . CurrentCulture , Strings . DscTestsPresentCommonName ) ;
7395 }
7496
7597 /// <summary>
@@ -78,7 +100,7 @@ public string GetCommonName()
78100 /// <returns>The description of this rule</returns>
79101 public string GetDescription ( )
80102 {
81- return string . Format ( CultureInfo . CurrentCulture , Strings . DscExamplesPresentDescription ) ;
103+ return string . Format ( CultureInfo . CurrentCulture , Strings . DscTestsPresentDescription ) ;
82104 }
83105
84106 /// <summary>
0 commit comments