Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -4,11 +4,13 @@ using Microsoft.Extensions.Logging.Abstractions;
|
||||
using StellaOps.Scanner.Analyzers.OS.Windows.Chocolatey;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Scanner.Analyzers.OS.Windows.Chocolatey.Tests;
|
||||
|
||||
public class ChocolateyAnalyzerPluginTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Name_ReturnsCorrectPluginName()
|
||||
{
|
||||
// Arrange
|
||||
@@ -21,7 +23,8 @@ public class ChocolateyAnalyzerPluginTests
|
||||
Assert.Equal("StellaOps.Scanner.Analyzers.OS.Windows.Chocolatey", name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void IsAvailable_WithValidServiceProvider_ReturnsTrue()
|
||||
{
|
||||
// Arrange
|
||||
@@ -37,7 +40,8 @@ public class ChocolateyAnalyzerPluginTests
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void IsAvailable_WithNullServiceProvider_ReturnsFalse()
|
||||
{
|
||||
// Arrange
|
||||
@@ -50,7 +54,8 @@ public class ChocolateyAnalyzerPluginTests
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void CreateAnalyzer_WithValidServiceProvider_ReturnsAnalyzer()
|
||||
{
|
||||
// Arrange
|
||||
@@ -68,7 +73,8 @@ public class ChocolateyAnalyzerPluginTests
|
||||
Assert.Equal("windows-chocolatey", analyzer.AnalyzerId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void CreateAnalyzer_WithNullServiceProvider_ThrowsArgumentNullException()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -25,13 +25,15 @@ public class ChocolateyPackageAnalyzerTests
|
||||
_logger);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void AnalyzerId_ReturnsCorrectValue()
|
||||
{
|
||||
Assert.Equal("windows-chocolatey", _analyzer.AnalyzerId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AnalyzeAsync_WithNoChocolateyDirectory_ReturnsEmptyList()
|
||||
{
|
||||
// Arrange
|
||||
@@ -55,7 +57,8 @@ public class ChocolateyPackageAnalyzerTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AnalyzeAsync_WithEmptyChocolateyLib_ReturnsEmptyList()
|
||||
{
|
||||
// Arrange
|
||||
@@ -80,7 +83,8 @@ public class ChocolateyPackageAnalyzerTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AnalyzeAsync_WithNuspecFile_ReturnsPackageRecord()
|
||||
{
|
||||
// Arrange
|
||||
@@ -113,7 +117,8 @@ public class ChocolateyPackageAnalyzerTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AnalyzeAsync_WithMultiplePackages_ReturnsAllRecords()
|
||||
{
|
||||
// Arrange
|
||||
@@ -160,7 +165,8 @@ public class ChocolateyPackageAnalyzerTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AnalyzeAsync_ExtractsVendorMetadata()
|
||||
{
|
||||
// Arrange
|
||||
@@ -198,7 +204,8 @@ public class ChocolateyPackageAnalyzerTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AnalyzeAsync_WithInstallScript_ComputesHash()
|
||||
{
|
||||
// Arrange
|
||||
@@ -231,7 +238,8 @@ public class ChocolateyPackageAnalyzerTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AnalyzeAsync_FallsBackToDirectoryParsing_WhenNoNuspec()
|
||||
{
|
||||
// Arrange
|
||||
@@ -264,7 +272,8 @@ public class ChocolateyPackageAnalyzerTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AnalyzeAsync_IncludesFileEvidence()
|
||||
{
|
||||
// Arrange
|
||||
@@ -307,7 +316,8 @@ public class ChocolateyPackageAnalyzerTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AnalyzeAsync_ResultsAreSortedDeterministically()
|
||||
{
|
||||
// Arrange
|
||||
@@ -346,7 +356,8 @@ public class ChocolateyPackageAnalyzerTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AnalyzeAsync_SkipsHiddenDirectories()
|
||||
{
|
||||
// Arrange
|
||||
@@ -379,7 +390,8 @@ public class ChocolateyPackageAnalyzerTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AnalyzeAsync_HandlesLowerCaseChocolateyPath()
|
||||
{
|
||||
// Arrange
|
||||
@@ -407,7 +419,8 @@ public class ChocolateyPackageAnalyzerTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AnalyzeAsync_TruncatesLongDescription()
|
||||
{
|
||||
// Arrange
|
||||
@@ -440,7 +453,8 @@ public class ChocolateyPackageAnalyzerTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AnalyzeAsync_WithCancellation_ThrowsOperationCanceledException()
|
||||
{
|
||||
// Arrange
|
||||
@@ -452,6 +466,7 @@ public class ChocolateyPackageAnalyzerTests
|
||||
CreateNuspecFile(packageDir, "git", "2.42.0", "Git", "Author", "Git");
|
||||
|
||||
using var cts = new CancellationTokenSource();
|
||||
using StellaOps.TestKit;
|
||||
cts.Cancel();
|
||||
|
||||
try
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
using StellaOps.Scanner.Analyzers.OS.Windows.Chocolatey;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Scanner.Analyzers.OS.Windows.Chocolatey.Tests;
|
||||
|
||||
public class NuspecParserTests
|
||||
{
|
||||
private readonly NuspecParser _parser = new();
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parse_WithValidNuspec_ReturnsMetadata()
|
||||
{
|
||||
// Arrange
|
||||
@@ -49,7 +51,8 @@ public class NuspecParserTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parse_WithOldNamespace_ReturnsMetadata()
|
||||
{
|
||||
// Arrange
|
||||
@@ -81,7 +84,8 @@ public class NuspecParserTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parse_WithOld2011Namespace_ReturnsMetadata()
|
||||
{
|
||||
// Arrange
|
||||
@@ -113,7 +117,8 @@ public class NuspecParserTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parse_WithNoNamespace_ReturnsMetadata()
|
||||
{
|
||||
// Arrange
|
||||
@@ -145,7 +150,8 @@ public class NuspecParserTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parse_WithMissingId_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
@@ -174,7 +180,8 @@ public class NuspecParserTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parse_WithMissingVersion_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
@@ -203,7 +210,8 @@ public class NuspecParserTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parse_WithInvalidXml_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
@@ -227,7 +235,8 @@ public class NuspecParserTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parse_WithNonExistentFile_ReturnsNull()
|
||||
{
|
||||
// Act
|
||||
@@ -237,7 +246,8 @@ public class NuspecParserTests
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parse_WithNullPath_ReturnsNull()
|
||||
{
|
||||
// Act
|
||||
@@ -247,7 +257,8 @@ public class NuspecParserTests
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parse_WithEmptyPath_ReturnsNull()
|
||||
{
|
||||
// Act
|
||||
@@ -257,7 +268,8 @@ public class NuspecParserTests
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parse_WithWhitespacePath_ReturnsNull()
|
||||
{
|
||||
// Act
|
||||
@@ -267,7 +279,8 @@ public class NuspecParserTests
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parse_ComputesInstallScriptHash_FromToolsDirectory()
|
||||
{
|
||||
// Arrange
|
||||
@@ -302,7 +315,8 @@ public class NuspecParserTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parse_ComputesInstallScriptHash_FromRootDirectory()
|
||||
{
|
||||
// Arrange
|
||||
@@ -336,7 +350,8 @@ public class NuspecParserTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parse_EnumeratesInstalledFiles()
|
||||
{
|
||||
// Arrange
|
||||
@@ -373,7 +388,8 @@ public class NuspecParserTests
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("git.2.42.0", "git", "2.42.0")]
|
||||
[InlineData("nodejs.20.10.0", "nodejs", "20.10.0")]
|
||||
[InlineData("7zip.23.01", "7zip", "23.01")]
|
||||
@@ -391,7 +407,8 @@ public class NuspecParserTests
|
||||
Assert.Equal(expectedVersion, result.Value.Version);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
|
||||
Reference in New Issue
Block a user