Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tst/CTA.Rules.Test/CTA.Rules.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
</None>
<None Update="CTAFiles\action.namespace.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TempRules\project.all.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TempTemplates\webforms\appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestFiles\Configs\Web.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
42 changes: 28 additions & 14 deletions tst/CTA.Rules.Test/RuleContributionTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using NUnit.Framework;

namespace CTA.Rules.Test;
Expand All @@ -15,18 +13,17 @@ namespace CTA.Rules.Test;
[TestFixture]
class RuleContributionTests : AwsRulesBaseTest
{
private const string RuleContributionsSolutionFileName = "RuleContributions.sln";
private const string RuleContributionsProjectFileName = "RuleContributions.csproj";
private string _tempDir = "";
private string _downloadLocation;
private Dictionary<string, TestSolutionAnalysis> _resultsDict;

[OneTimeSetUp]
public void Setup()
{
_tempDir = SetupTests.TempDir;
_downloadLocation = SetupTests.DownloadLocation;

var solutionName = "RuleContributions.sln";
var solutionPath = CopySolutionFolderToTemp(solutionName, _tempDir);
var solutionPath = CopySolutionFolderToTemp(RuleContributionsSolutionFileName, _tempDir);
var net31Results = AnalyzeSolution(solutionPath, TargetFramework.DotnetCoreApp31);
var net50Results = AnalyzeSolution(solutionPath, TargetFramework.Dotnet5);
var net60Results = AnalyzeSolution(solutionPath, TargetFramework.Dotnet6);
Expand All @@ -38,29 +35,46 @@ public void Setup()
{TargetFramework.Dotnet6, net60Results}
};
}

[TestCase(TargetFramework.DotnetCoreApp31)]
[TestCase(TargetFramework.Dotnet5)]
[TestCase(TargetFramework.Dotnet6)]
public void TestProjectFilePortingResults(string version)
public void Porting_With_All_Contributed_Rules_Results_In_Zero_Build_Errors(string version)
{
var solutionPortingResult = _resultsDict[version];
CollectionAssert.IsEmpty(solutionPortingResult.SolutionRunResult.BuildErrors);
}

[TestCase(TargetFramework.DotnetCoreApp31)]
[TestCase(TargetFramework.Dotnet5)]
[TestCase(TargetFramework.Dotnet6)]
public void DynamicQuery_Package_Is_Added_And_Namespaces_Are_Replaced(string version)
{
var projectFileName = "RuleContributions.csproj";
var csFileName = "System.Linq.Dynamic.cs";

var solutionPortingResult = _resultsDict[version];
var ruleContributionsResult = solutionPortingResult.ProjectResults.First(proj => proj.CsProjectPath.EndsWith(projectFileName));
var ruleContributionsResult = solutionPortingResult.ProjectResults.First(proj => proj.CsProjectPath.EndsWith(RuleContributionsProjectFileName));
var ruleContributionsFile = Directory.EnumerateFiles(ruleContributionsResult.ProjectDirectory, "*.cs", SearchOption.AllDirectories)
.First(file => file.EndsWith(csFileName));
var ruleContributionsFileContent = File.ReadAllText(ruleContributionsFile);

// Verify there are no build errors after porting
CollectionAssert.IsEmpty(solutionPortingResult.SolutionRunResult.BuildErrors);

// Verify expected package is in .csproj
StringAssert.Contains(@"PackageReference Include=""System.Linq.Dynamic.Core""", ruleContributionsResult.CsProjectContent);

// Verify namespaces were updated
StringAssert.Contains("using System.Linq.Dynamic.Core;", ruleContributionsFileContent);
StringAssert.DoesNotContain("using System.Linq.Dynamic;", ruleContributionsFileContent);
}

[TestCase(TargetFramework.DotnetCoreApp31)]
[TestCase(TargetFramework.Dotnet5)]
[TestCase(TargetFramework.Dotnet6)]
public void BouncyCastleNetCore_Package_Is_Added(string version)
{
var solutionPortingResult = _resultsDict[version];
var ruleContributionsResult = solutionPortingResult.ProjectResults.First(proj => proj.CsProjectPath.EndsWith(RuleContributionsProjectFileName));

// Verify expected package is in .csproj
StringAssert.Contains(@"PackageReference Include=""BouncyCastle.NetCore""", ruleContributionsResult.CsProjectContent);
}
}