From 3ad7693acb27d239a1978f12283473cfc0939a68 Mon Sep 17 00:00:00 2001 From: Chris Long Date: Thu, 30 Jun 2022 21:10:20 -0700 Subject: [PATCH 1/5] fix: set language on project rewriter initialization --- src/CTA.Rules.Update/ProjectRewriters/ProjectRewriter.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CTA.Rules.Update/ProjectRewriters/ProjectRewriter.cs b/src/CTA.Rules.Update/ProjectRewriters/ProjectRewriter.cs index 5e074137..631ba7c4 100644 --- a/src/CTA.Rules.Update/ProjectRewriters/ProjectRewriter.cs +++ b/src/CTA.Rules.Update/ProjectRewriters/ProjectRewriter.cs @@ -78,6 +78,7 @@ public ProjectRewriter(IDEProjectResult projectResult, ProjectConfiguration proj Version = p.Value.Item2 }).ToList() }; + _projectLanguage = VisualBasicUtils.IsVisualBasicProject(ProjectConfiguration.ProjectPath) ? ProjectLanguage.VisualBasic : ProjectLanguage.Csharp; } /// From ae7fdef182ab06e10f170a2c20911290aa9ce95e Mon Sep 17 00:00:00 2001 From: Chris Long Date: Fri, 1 Jul 2022 09:03:42 -0700 Subject: [PATCH 2/5] chore: update codelyzer --- .../packages.lock.json | 46 +++++++++---------- src/CTA.Rules.Config/CTA.Rules.Config.csproj | 4 +- src/CTA.Rules.Models/packages.lock.json | 46 +++++++++---------- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/CTA.FeatureDetection.Common/packages.lock.json b/src/CTA.FeatureDetection.Common/packages.lock.json index d05c9bf9..975f246b 100644 --- a/src/CTA.FeatureDetection.Common/packages.lock.json +++ b/src/CTA.FeatureDetection.Common/packages.lock.json @@ -54,12 +54,12 @@ }, "Codelyzer.Analysis": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "iynKNXyC15wF0u9ZUTr4cKAmdYa1470AaGtvACuULL2BRK3VMHpzE01a/UvKbulKSXq0cZYaEMX+GrOlMVJuDQ==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "5t+uGKQVjm85toghCUBsM69wUfTVBxhYT+eCuZLceMiK4TbJ7MJwfCEfai3Qj41mnJ8g4yPIsMyGkCAARF/F0g==", "dependencies": { - "Codelyzer.Analysis.Build": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.CSharp": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.VisualBasic": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis.Build": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.CSharp": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.VisualBasic": "2.4.72-alpha-g154f8975ce", "CommandLineParser": "2.8.0", "Microsoft.Build.Utilities.Core": "17.1.0", "Microsoft.Extensions.Logging.Console": "6.0.0", @@ -69,23 +69,23 @@ }, "Codelyzer.Analysis.Build": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "+senXLbp84O5oiiT1hp/B+AzCDSo7/+C+1KkDQlNrMBANBseSpcoXVacYigGTGHbSK79V16ahIlvAjpE9e9RBA==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "Ymx4lk0aILNUnjK/Ln7DvY84fV8rkeHbRjvXqmkMZvYgB35WtRSMw2qKMbmXUxeNP+evogviHgt6Cmcafn2n6Q==", "dependencies": { "Buildalyzer": "4.1.4", "Buildalyzer.Logger": "4.1.4", "Buildalyzer.Workspaces": "4.1.4", - "Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis.Common": "2.4.72-alpha-g154f8975ce", "Microsoft.Extensions.Logging": "6.0.0", "NuGet.Packaging": "6.0.0" } }, "Codelyzer.Analysis.Common": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "4nEVXfTc/FFzxkEulKOSd2s/2uh4bcTVbCncPCp4BZpf5qKLLXeLwf4VBzS/PFo6T5Y2D3A1F9kRlub74dLSXQ==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "PNRf7eXbink/4MpEzUorwPZqiw0oh/Ac3hML5Q3+peCsWq8SWxy0Xj8eHfoxlQjaJ9tqkhWz1wzTx15wfmMUPw==", "dependencies": { - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce", "Microsoft.Build": "17.0.0", "Microsoft.VisualStudio.Setup.Configuration.Interop": "3.1.2196", "Newtonsoft.Json": "13.0.1" @@ -93,17 +93,17 @@ }, "Codelyzer.Analysis.CSharp": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "Q5Fs/FoDo6tz14aWEMCENHEjgTKJojE2/Wd1jSbFmjV8a8q27q6sk2gqMT5FcTO86THzt+GFeKq8b7FF8w2MoQ==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "EknM1pQWlGb0dCZaPTdl4dJ35OV9Np2CgZ98iXPWKSSGjk+0TdJSPikQ6skbJ2iiqogyOpuycfJ5CXv64gx0VA==", "dependencies": { - "Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c" + "Codelyzer.Analysis.Common": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce" } }, "Codelyzer.Analysis.Model": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "Ma1ACdIXjWStzw7ImhowEsI4E9p2fNhiANgP8FU0uegQSZOaA4x/IaUU0Aij5s5mCTbNVPX6Z5j89g2+L9YftA==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "rBpfp+QH75M5c4cOY/nMc1Kd7trfiDQfl86CZbS0nbe2fteK9F+V0t2wpEBKlitm/STD+NyBcED4jm013u8H8Q==", "dependencies": { "Microsoft.CodeAnalysis": "4.1.0", "Microsoft.CodeAnalysis.CSharp": "4.1.0", @@ -114,11 +114,11 @@ }, "Codelyzer.Analysis.VisualBasic": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "Hxpzw8CXD+oKN47DnYqgoajIucyAIrEW8YOdwcJgT+RGyJ9biLentcSws/9yzVgoIQWV042ppIKp7PlgwRGrJA==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "taucX8Bw2QpqMDJRhoRx0AhXq8n6WTNwtvz/FbxAgQszwV4FrcAnEl6yrngB0kYumaABHSsjy/vFjmd6vCwsGw==", "dependencies": { - "Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c" + "Codelyzer.Analysis.Common": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce" } }, "CommandLineParser": { @@ -1711,8 +1711,8 @@ "cta.rules.config": { "type": "Project", "dependencies": { - "Codelyzer.Analysis": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce", "Microsoft.Extensions.Logging": "6.0.0", "Microsoft.Extensions.Logging.Abstractions": "6.0.0", "Microsoft.Extensions.Logging.Console": "6.0.0", diff --git a/src/CTA.Rules.Config/CTA.Rules.Config.csproj b/src/CTA.Rules.Config/CTA.Rules.Config.csproj index a1e0bb35..55e26924 100644 --- a/src/CTA.Rules.Config/CTA.Rules.Config.csproj +++ b/src/CTA.Rules.Config/CTA.Rules.Config.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/src/CTA.Rules.Models/packages.lock.json b/src/CTA.Rules.Models/packages.lock.json index ac41963b..181f99dd 100644 --- a/src/CTA.Rules.Models/packages.lock.json +++ b/src/CTA.Rules.Models/packages.lock.json @@ -60,12 +60,12 @@ }, "Codelyzer.Analysis": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "iynKNXyC15wF0u9ZUTr4cKAmdYa1470AaGtvACuULL2BRK3VMHpzE01a/UvKbulKSXq0cZYaEMX+GrOlMVJuDQ==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "5t+uGKQVjm85toghCUBsM69wUfTVBxhYT+eCuZLceMiK4TbJ7MJwfCEfai3Qj41mnJ8g4yPIsMyGkCAARF/F0g==", "dependencies": { - "Codelyzer.Analysis.Build": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.CSharp": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.VisualBasic": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis.Build": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.CSharp": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.VisualBasic": "2.4.72-alpha-g154f8975ce", "CommandLineParser": "2.8.0", "Microsoft.Build.Utilities.Core": "17.1.0", "Microsoft.Extensions.Logging.Console": "6.0.0", @@ -75,23 +75,23 @@ }, "Codelyzer.Analysis.Build": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "+senXLbp84O5oiiT1hp/B+AzCDSo7/+C+1KkDQlNrMBANBseSpcoXVacYigGTGHbSK79V16ahIlvAjpE9e9RBA==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "Ymx4lk0aILNUnjK/Ln7DvY84fV8rkeHbRjvXqmkMZvYgB35WtRSMw2qKMbmXUxeNP+evogviHgt6Cmcafn2n6Q==", "dependencies": { "Buildalyzer": "4.1.4", "Buildalyzer.Logger": "4.1.4", "Buildalyzer.Workspaces": "4.1.4", - "Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis.Common": "2.4.72-alpha-g154f8975ce", "Microsoft.Extensions.Logging": "6.0.0", "NuGet.Packaging": "6.0.0" } }, "Codelyzer.Analysis.Common": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "4nEVXfTc/FFzxkEulKOSd2s/2uh4bcTVbCncPCp4BZpf5qKLLXeLwf4VBzS/PFo6T5Y2D3A1F9kRlub74dLSXQ==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "PNRf7eXbink/4MpEzUorwPZqiw0oh/Ac3hML5Q3+peCsWq8SWxy0Xj8eHfoxlQjaJ9tqkhWz1wzTx15wfmMUPw==", "dependencies": { - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce", "Microsoft.Build": "17.0.0", "Microsoft.VisualStudio.Setup.Configuration.Interop": "3.1.2196", "Newtonsoft.Json": "13.0.1" @@ -99,17 +99,17 @@ }, "Codelyzer.Analysis.CSharp": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "Q5Fs/FoDo6tz14aWEMCENHEjgTKJojE2/Wd1jSbFmjV8a8q27q6sk2gqMT5FcTO86THzt+GFeKq8b7FF8w2MoQ==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "EknM1pQWlGb0dCZaPTdl4dJ35OV9Np2CgZ98iXPWKSSGjk+0TdJSPikQ6skbJ2iiqogyOpuycfJ5CXv64gx0VA==", "dependencies": { - "Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c" + "Codelyzer.Analysis.Common": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce" } }, "Codelyzer.Analysis.Model": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "Ma1ACdIXjWStzw7ImhowEsI4E9p2fNhiANgP8FU0uegQSZOaA4x/IaUU0Aij5s5mCTbNVPX6Z5j89g2+L9YftA==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "rBpfp+QH75M5c4cOY/nMc1Kd7trfiDQfl86CZbS0nbe2fteK9F+V0t2wpEBKlitm/STD+NyBcED4jm013u8H8Q==", "dependencies": { "Microsoft.CodeAnalysis": "4.1.0", "Microsoft.CodeAnalysis.CSharp": "4.1.0", @@ -120,11 +120,11 @@ }, "Codelyzer.Analysis.VisualBasic": { "type": "Transitive", - "resolved": "2.4.71-alpha-g6b1f22778c", - "contentHash": "Hxpzw8CXD+oKN47DnYqgoajIucyAIrEW8YOdwcJgT+RGyJ9biLentcSws/9yzVgoIQWV042ppIKp7PlgwRGrJA==", + "resolved": "2.4.72-alpha-g154f8975ce", + "contentHash": "taucX8Bw2QpqMDJRhoRx0AhXq8n6WTNwtvz/FbxAgQszwV4FrcAnEl6yrngB0kYumaABHSsjy/vFjmd6vCwsGw==", "dependencies": { - "Codelyzer.Analysis.Common": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c" + "Codelyzer.Analysis.Common": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce" } }, "CommandLineParser": { @@ -1717,8 +1717,8 @@ "cta.rules.config": { "type": "Project", "dependencies": { - "Codelyzer.Analysis": "2.4.71-alpha-g6b1f22778c", - "Codelyzer.Analysis.Model": "2.4.71-alpha-g6b1f22778c", + "Codelyzer.Analysis": "2.4.72-alpha-g154f8975ce", + "Codelyzer.Analysis.Model": "2.4.72-alpha-g154f8975ce", "Microsoft.Extensions.Logging": "6.0.0", "Microsoft.Extensions.Logging.Abstractions": "6.0.0", "Microsoft.Extensions.Logging.Console": "6.0.0", From 83195344ffe9790a8c4789ed45d2a2a8d13cc844 Mon Sep 17 00:00:00 2001 From: Chris Long Date: Fri, 1 Jul 2022 15:29:27 -0700 Subject: [PATCH 3/5] fix: load references from imports for vb projects --- src/CTA.Rules.PortCore/PortCoreUtils.cs | 40 +++++++++++++++++++++++++ src/CTA.Rules.PortCore/ProjectPort.cs | 19 ++---------- src/CTA.Rules.PortCore/SolutionPort.cs | 22 ++++---------- tst/CTA.Rules.Test/VisualBasicTests.cs | 3 ++ 4 files changed, 50 insertions(+), 34 deletions(-) create mode 100644 src/CTA.Rules.PortCore/PortCoreUtils.cs diff --git a/src/CTA.Rules.PortCore/PortCoreUtils.cs b/src/CTA.Rules.PortCore/PortCoreUtils.cs new file mode 100644 index 00000000..3d84b6dd --- /dev/null +++ b/src/CTA.Rules.PortCore/PortCoreUtils.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Linq; +using Codelyzer.Analysis; +using Codelyzer.Analysis.Model; +using CTA.Rules.Models; + +namespace CTA.Rules.PortCore; + +public class PortCoreUtils +{ + public static HashSet GetReferencesForProject(PortCoreConfiguration projectConfiguration, AnalyzerResult analyzerResult) + { + var allReferences = new HashSet(); + var projectResult = analyzerResult.ProjectResult; + + projectResult?.SourceFileResults?.SelectMany(s => s.References)?.Select(r => r.Namespace).Distinct().ToList().ForEach(currentReference=> { + if (currentReference != null && !allReferences.Contains(currentReference)) + { + allReferences.Add(currentReference); + } + }); + + projectResult?.SourceFileResults?.SelectMany(s => s.Children.OfType())?.Select(u=>u.Identifier).Distinct().ToList().ForEach(currentReference => { + if (currentReference != null && !allReferences.Contains(currentReference)) + { + allReferences.Add(currentReference); + } + }); + + projectResult?.SourceFileResults?.SelectMany(s => s.Children.OfType())?.Select(u => u.Identifier).Distinct().ToList().ForEach(currentReference => + { + if (currentReference != null && !allReferences.Contains(currentReference)) + { + allReferences.Add(currentReference); + } + }); + + return allReferences; + } +} diff --git a/src/CTA.Rules.PortCore/ProjectPort.cs b/src/CTA.Rules.PortCore/ProjectPort.cs index b9513b01..59130db8 100644 --- a/src/CTA.Rules.PortCore/ProjectPort.cs +++ b/src/CTA.Rules.PortCore/ProjectPort.cs @@ -56,23 +56,8 @@ private void InitRules(PortCoreConfiguration projectConfiguration, AnalyzerResul _solutionPort.CopyOverrideRules(projectConfiguration.RulesDir); } projectConfiguration.RulesDir = Constants.RulesDefaultPath; - var projectResult = analyzerResult.ProjectResult; - - projectResult?.SourceFileResults?.SelectMany(s => s.References)?.Select(r => r.Namespace).Distinct().ToList().ForEach(currentReference => - { - if (currentReference != null && !ProjectReferences.Contains(currentReference)) - { - ProjectReferences.Add(currentReference); - } - }); - - projectResult?.SourceFileResults?.SelectMany(s => s.Children.OfType())?.Select(u => u.Identifier).Distinct().ToList().ForEach(currentReference => - { - if (currentReference != null && !ProjectReferences.Contains(currentReference)) - { - ProjectReferences.Add(currentReference); - } - }); + + ProjectReferences.UnionWith(PortCoreUtils.GetReferencesForProject(projectConfiguration, analyzerResult)); ProjectReferences.Add(Constants.ProjectRecommendationFile); } diff --git a/src/CTA.Rules.PortCore/SolutionPort.cs b/src/CTA.Rules.PortCore/SolutionPort.cs index 436dfd14..3effafd0 100644 --- a/src/CTA.Rules.PortCore/SolutionPort.cs +++ b/src/CTA.Rules.PortCore/SolutionPort.cs @@ -218,23 +218,11 @@ private void InitRules(List solutionConfiguration, List a.ProjectResult?.ProjectFilePath == projectConfiguration.ProjectPath) - .ProjectResult; - - projectResult?.SourceFileResults?.SelectMany(s => s.References)?.Select(r => r.Namespace).Distinct().ToList().ForEach(currentReference=> { - if (currentReference != null && !allReferences.Contains(currentReference)) - { - allReferences.Add(currentReference); - } - }); - - projectResult?.SourceFileResults?.SelectMany(s => s.Children.OfType())?.Select(u=>u.Identifier).Distinct().ToList().ForEach(currentReference => { - if (currentReference != null && !allReferences.Contains(currentReference)) - { - allReferences.Add(currentReference); - } - }); + allReferences.UnionWith(PortCoreUtils.GetReferencesForProject( + projectConfiguration, + analyzerResults.FirstOrDefault(a => + a.ProjectResult?.ProjectFilePath == + projectConfiguration.ProjectPath))); } AddWCFReferences(projectConfiguration); diff --git a/tst/CTA.Rules.Test/VisualBasicTests.cs b/tst/CTA.Rules.Test/VisualBasicTests.cs index caeeea5c..1285ac20 100644 --- a/tst/CTA.Rules.Test/VisualBasicTests.cs +++ b/tst/CTA.Rules.Test/VisualBasicTests.cs @@ -85,6 +85,9 @@ public void TestMixedClassLibrary() Assert.IsTrue(projresults.Count() == 2); //check both projects ported Assert.IsTrue(projresults.All(content => content.Contains("net5.0"))); + Assert.IsTrue(slnResults.ProjectResults + .Find(p => p.CsProjectPath.EndsWith(".vbproj")) + .CsProjectContent.Contains("BouncyCastle.NetCore")); } } } From 8a1eba8b1fb53f2f3978ec17f703dd073e1ea60d Mon Sep 17 00:00:00 2001 From: Chris Long Date: Fri, 1 Jul 2022 15:58:49 -0700 Subject: [PATCH 4/5] fix: unnecessary parameter --- src/CTA.Rules.PortCore/PortCoreUtils.cs | 2 +- src/CTA.Rules.PortCore/ProjectPort.cs | 2 +- src/CTA.Rules.PortCore/SolutionPort.cs | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/CTA.Rules.PortCore/PortCoreUtils.cs b/src/CTA.Rules.PortCore/PortCoreUtils.cs index 3d84b6dd..b20c972e 100644 --- a/src/CTA.Rules.PortCore/PortCoreUtils.cs +++ b/src/CTA.Rules.PortCore/PortCoreUtils.cs @@ -8,7 +8,7 @@ namespace CTA.Rules.PortCore; public class PortCoreUtils { - public static HashSet GetReferencesForProject(PortCoreConfiguration projectConfiguration, AnalyzerResult analyzerResult) + public static HashSet GetReferencesForProject(AnalyzerResult analyzerResult) { var allReferences = new HashSet(); var projectResult = analyzerResult.ProjectResult; diff --git a/src/CTA.Rules.PortCore/ProjectPort.cs b/src/CTA.Rules.PortCore/ProjectPort.cs index 59130db8..a10cf4f8 100644 --- a/src/CTA.Rules.PortCore/ProjectPort.cs +++ b/src/CTA.Rules.PortCore/ProjectPort.cs @@ -57,7 +57,7 @@ private void InitRules(PortCoreConfiguration projectConfiguration, AnalyzerResul } projectConfiguration.RulesDir = Constants.RulesDefaultPath; - ProjectReferences.UnionWith(PortCoreUtils.GetReferencesForProject(projectConfiguration, analyzerResult)); + ProjectReferences.UnionWith(PortCoreUtils.GetReferencesForProject(analyzerResult)); ProjectReferences.Add(Constants.ProjectRecommendationFile); } diff --git a/src/CTA.Rules.PortCore/SolutionPort.cs b/src/CTA.Rules.PortCore/SolutionPort.cs index 3effafd0..d860e771 100644 --- a/src/CTA.Rules.PortCore/SolutionPort.cs +++ b/src/CTA.Rules.PortCore/SolutionPort.cs @@ -219,7 +219,6 @@ private void InitRules(List solutionConfiguration, List a.ProjectResult?.ProjectFilePath == projectConfiguration.ProjectPath))); From 861281d260347aea6ec89d7f9b6bdaa489c69b6c Mon Sep 17 00:00:00 2001 From: Chris Long Date: Fri, 1 Jul 2022 16:03:20 -0700 Subject: [PATCH 5/5] test: unit test for load reference util --- tst/CTA.Rules.Test/UtilsTest.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tst/CTA.Rules.Test/UtilsTest.cs b/tst/CTA.Rules.Test/UtilsTest.cs index 7f0a5750..ce817b89 100644 --- a/tst/CTA.Rules.Test/UtilsTest.cs +++ b/tst/CTA.Rules.Test/UtilsTest.cs @@ -5,7 +5,10 @@ using System.IO; using System.Linq; using System.Threading.Tasks; +using Codelyzer.Analysis; +using Codelyzer.Analysis.Model; using CTA.Rules.Common.Helpers; +using CTA.Rules.PortCore; namespace CTA.Rules.Test { @@ -121,5 +124,34 @@ public void Test_Is_VisualBasic_Project() Assert.IsTrue(VisualBasicUtils.IsVisualBasicProject("C://user/john/repos/test.vbproj")); Assert.IsFalse(VisualBasicUtils.IsVisualBasicProject("vbprojproject.cs")); } + + [Test] + public void TestLoadReferencesFromProject() + { + var analyzeResult = new AnalyzerResult + { + ProjectResult = new ProjectWorkspace("dummy.csproj") + { + SourceFileResults = new UstList() + { + new RootUstNode() + { + Children = new UstList + { + new ImportsStatement { Identifier = "Newtonsoft.Json"}, + new UsingDirective {Identifier = "BouncyCastle.NetCore"} + }, + References = new UstList() + { + new Reference() {Namespace = "BouncyCastle.NetCore"} + } + } + } + } + }; + + var references = PortCoreUtils.GetReferencesForProject(analyzeResult); + Assert.IsTrue(references.Count == 2); + } } } \ No newline at end of file