Skip to content

Commit

Permalink
test: generator and mvc solution
Browse files Browse the repository at this point in the history
verify mvc solution is not ported
  • Loading branch information
cslong committed Jul 13, 2022
1 parent c4d4dc8 commit e8620e9
Showing 1 changed file with 79 additions and 11 deletions.
90 changes: 79 additions & 11 deletions tst/CTA.Rules.Test/VisualBasicTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Codelyzer.Analysis;
using Codelyzer.Analysis.Analyzer;
using CTA.Rules.Models;
using CTA.Rules.PortCore;
using Microsoft.Extensions.Logging.Abstractions;
using System.Threading.Tasks;
using NUnit.Framework;

namespace CTA.Rules.Test
Expand All @@ -11,7 +18,7 @@ internal class VisualBasicTests : AwsRulesBaseTest
private string _tempDir;
private string _downloadLocation;
private List<string> _ctaFiles;
private readonly string _version = "net5.0";
private readonly string _version = "net6.0";
//We don't care about version for CTA-only rules:

[SetUp]
Expand Down Expand Up @@ -51,9 +58,9 @@ public void TestOwinParadiseVb()

//Check method actions
StringAssert.Contains("UseEndpoints", signalR);

//Check project porting
StringAssert.Contains("net5.0", projectFile);
StringAssert.Contains("net6.0", projectFile);
StringAssert.Contains("Microsoft.AspNetCore.Diagnostics", projectFile);
}

Expand All @@ -66,13 +73,12 @@ public void TestVbNetMvc()
_version)
.ProjectResults.FirstOrDefault();
// Check that nothing is ported.

// uncomment once template in datastore is merged.
// StringAssert.Contains(
// "<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>",
// results.CsProjectContent);
StringAssert.Contains(
"<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>",
results.CsProjectContent);
}



[Test]
public void TestMixedClassLibrary()
{
Expand All @@ -84,10 +90,72 @@ public void TestMixedClassLibrary()
Assert.IsTrue(projresults != null);
Assert.IsTrue(projresults.Count() == 2);
//check both projects ported
Assert.IsTrue(projresults.All(content => content.Contains("net5.0")));
Assert.IsTrue(projresults.All(content => content.Contains("net6.0")));
Assert.IsTrue(slnResults.ProjectResults
.Find(p => p.CsProjectPath.EndsWith(".vbproj"))
.CsProjectContent.Contains("BouncyCastle.NetCore"));
}

[Test]
public async Task RunMixedUsingGenerator()
{
var solutionPath = CopySolutionFolderToTemp("MixedClassLibrary.sln", _tempDir);

AnalyzerConfiguration configuration = new AnalyzerConfiguration(LanguageOptions.CSharp)
{
ExportSettings =
{
GenerateJsonOutput = false,
OutputPath = @"/tmp/UnitTests"
},

MetaDataSettings =
{
LiteralExpressions = true,
MethodInvocations = true,
Annotations = true,
DeclarationNodes = true,
LocationData = false,
ReferenceData = true,
LoadBuildData = true,
ElementAccess = true,
MemberAccess = true
}
};

//CodeAnalyzer analyzer = CodeAnalyzerFactory.GetAnalyzer(configuration, NullLogger.Instance);
CodeAnalyzerByLanguage analyzer = new CodeAnalyzerByLanguage(configuration, NullLogger.Instance);

SolutionPort solutionPort = new SolutionPort(solutionPath);

var resultEnumerator = analyzer.AnalyzeSolutionGeneratorAsync(solutionPath).GetAsyncEnumerator();

while (await resultEnumerator.MoveNextAsync())
{
using var result = resultEnumerator.Current;
PortCoreConfiguration projectConfiguration = new PortCoreConfiguration()
{
SolutionPath = solutionPath,
ProjectPath = result.ProjectResult.ProjectFilePath,
IsMockRun = false,
UseDefaultRules = true,
PortCode = true,
PortProject = true,
TargetVersions = new List<string> { _version }
};

solutionPort.RunProject(result, projectConfiguration);
}
var portSolutionResult = solutionPort.GenerateResults();
var testSolutionResult = GenerateSolutionResult(solutionPath, solutionPort.GetAnalysisResult(), portSolutionResult);
var projResults = testSolutionResult.ProjectResults.Select(p => p.CsProjectContent).ToList();
Assert.IsTrue(projResults != null);
Assert.IsTrue(projResults.Count() == 2);
//check both projects ported
Assert.IsTrue(projResults.All(content => content.Contains("net6.0")));
Assert.IsTrue(testSolutionResult.ProjectResults
.Find(p => p.CsProjectPath.EndsWith(".vbproj"))
.CsProjectContent.Contains("BouncyCastle.NetCore"));
}
}
}

0 comments on commit e8620e9

Please sign in to comment.