Skip to content

Commit ed2f291

Browse files
Adding implementation for class based resources
1 parent d099687 commit ed2f291

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

Rules/DscTestsPresent.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,39 @@ public IEnumerable<DiagnosticRecord> AnalyzeDSCResource(Ast ast, string fileName
7373
/// <returns></returns>
7474
public IEnumerable<DiagnosticRecord> AnalyzeDSCClass(Ast ast, string fileName)
7575
{
76-
76+
String resourceName = null;
77+
78+
IEnumerable<Ast> dscClasses = ast.FindAll(item =>
79+
item is TypeDefinitionAst
80+
&& ((item as TypeDefinitionAst).IsClass)
81+
&& (item as TypeDefinitionAst).Attributes.Any(attr => String.Equals("DSCResource", attr.TypeName.FullName, StringComparison.OrdinalIgnoreCase)), true);
82+
83+
foreach (TypeDefinitionAst dscClass in dscClasses)
84+
{
85+
resourceName = dscClass.Name;
86+
87+
String testsQuery = String.Format("*{0}*", resourceName);
88+
Boolean testsPresent = false;
89+
String expectedTestsPath = Path.Combine(new String[] { fileName, "..", "Tests" });
90+
91+
// Verify tests are present
92+
if (Directory.Exists(expectedTestsPath))
93+
{
94+
DirectoryInfo testsFolder = new DirectoryInfo(expectedTestsPath);
95+
FileInfo[] testFiles = testsFolder.GetFiles(testsQuery);
96+
if (testFiles.Length != 0)
97+
{
98+
testsPresent = true;
99+
}
100+
}
101+
102+
// Return error if no tests present
103+
if (!testsPresent)
104+
{
105+
yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.DscTestsPresentNoTestsError, resourceName),
106+
dscClass.Extent, GetName(), DiagnosticSeverity.Information, fileName);
107+
}
108+
}
77109
}
78110

79111
/// <summary>

0 commit comments

Comments
 (0)