Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UTs caused by .NET 8 release by using specific nuget version #8362

Merged
merged 1 commit into from
Nov 15, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static void VerifyNoIssueReported(AnalyzerLanguage language, ImmutableAr
.AddPaths(@$"Hotspots\{GetTestCaseFileName(analyzerName)}{language.FileExtension}")
.AddAnalyzer(() => analyzer)
.WithOptions(parseOptions)
.AddReferences(GetAdditionalReferences(analyzerName, Constants.NuGetLatestVersion))
.AddReferences(GetAdditionalReferences(analyzerName))
.WithConcurrentAnalysis(analyzerName is not nameof(ClearTextProtocolsAreSensitive))
.VerifyNoIssueReported();
}
Expand Down Expand Up @@ -88,15 +88,15 @@ private static string GetTestCaseFileName(string analyzerName) =>
_ => analyzerName
};

private static IEnumerable<MetadataReference> GetAdditionalReferences(string analyzerName, string version) =>
private static IEnumerable<MetadataReference> GetAdditionalReferences(string analyzerName) =>
analyzerName switch
{
nameof(ClearTextProtocolsAreSensitive) => ClearTextProtocolsAreSensitiveTest.AdditionalReferences,
nameof(CookieShouldBeHttpOnly) => CookieShouldBeHttpOnlyTest.AdditionalReferences,
nameof(CookieShouldBeSecure) => CookieShouldBeSecureTest.AdditionalReferences,
nameof(ConfiguringLoggers) => ConfiguringLoggersTest.Log4NetReferences,
nameof(DeliveringDebugFeaturesInProduction) => DeliveringDebugFeaturesInProductionTest.AdditionalReferencesForAspNetCore2,
nameof(DisablingRequestValidation) => NuGetMetadataReference.MicrosoftAspNetMvc(version),
nameof(DisablingRequestValidation) => NuGetMetadataReference.MicrosoftAspNetMvc(Constants.NuGetLatestVersion),
nameof(DoNotHardcodeCredentials) => DoNotHardcodeCredentialsTest.AdditionalReferences,
nameof(DoNotUseRandom) => MetadataReferenceFacade.SystemSecurityCryptography,
nameof(ExpandingArchives) => ExpandingArchivesTest.AdditionalReferences,
Expand All @@ -106,11 +106,11 @@ private static IEnumerable<MetadataReference> GetAdditionalReferences(string ana

#if NET
nameof(DisablingCsrfProtection) => DisablingCsrfProtectionTest.AdditionalReferences(),
nameof(ExecutingSqlQueries) => ExecutingSqlQueriesTest.GetReferencesEntityFrameworkNetCore(version),
nameof(ExecutingSqlQueries) => ExecutingSqlQueriesTest.GetReferencesEntityFrameworkNetCore("7.0.14"),
nameof(LooseFilePermissions) => NuGetMetadataReference.MonoPosixNetStandard(),
nameof(PermissiveCors) => PermissiveCorsTest.AdditionalReferences,
#else
nameof(ExecutingSqlQueries) => ExecutingSqlQueriesTest.GetReferencesNet46(version),
nameof(ExecutingSqlQueries) => ExecutingSqlQueriesTest.GetReferencesNet46(Constants.NuGetLatestVersion),
#endif
_ => MetadataReferenceFacade.SystemNetHttp
.Concat(MetadataReferenceFacade.SystemDiagnosticsProcess)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ public void ExecutingSqlQueries_CS_EntityFrameworkCore2() =>
.Verify();

[TestMethod]
public void ExecutingSqlQueries_CS_EntityFrameworkCoreLatest() =>
public void ExecutingSqlQueries_CS_EntityFrameworkCore7() =>
builderCS
.AddPaths("ExecutingSqlQueries.EntityFrameworkCoreLatest.cs")
.WithOptions(ParseOptionsHelper.FromCSharp8)
.AddReferences(GetReferencesEntityFrameworkNetCore(Constants.NuGetLatestVersion))
.AddReferences(GetReferencesEntityFrameworkNetCore("7.0.14"))
.Verify();

[TestMethod]
Expand Down Expand Up @@ -132,11 +132,11 @@ public void ExecutingSqlQueries_VB_EntityFrameworkCore2() =>
.Verify();

[TestMethod]
public void ExecutingSqlQueries_VB_EntityFrameworkCoreLatest() =>
public void ExecutingSqlQueries_VB_EntityFrameworkCore7() =>
builderVB
.AddPaths(@"ExecutingSqlQueries.EntityFrameworkCoreLatest.vb")
.WithOptions(ParseOptionsHelper.FromVisualBasic15)
.AddReferences(GetReferencesEntityFrameworkNetCore(Constants.NuGetLatestVersion))
.AddReferences(GetReferencesEntityFrameworkNetCore("7.0.14"))
.Verify();

internal static IEnumerable<MetadataReference> GetReferencesEntityFrameworkNetCore(string entityFrameworkVersion) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void PermissiveCors_AspNet_WebApi() =>
.Verify();

private static IEnumerable<MetadataReference> AdditionalReferences =>
NuGetMetadataReference.MicrosoftNetHttpHeaders(Constants.NuGetLatestVersion)
NuGetMetadataReference.MicrosoftNetHttpHeaders("2.1.14")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will you open a ticket to bring this back to NuGet Latest?

why: we keep LatestVersion to be aware if some API changes lead to our rules creating FPs or FNs (e.g. a deprecated attribute might be removed, so we won't raise anymore on net8 and we need to update the rule)

.Concat(NuGetMetadataReference.MicrosoftAspNetMvc(Constants.NuGetLatestVersion))
.Concat(NuGetMetadataReference.MicrosoftAspNetWebApiCors(Constants.NuGetLatestVersion))
.Concat(NuGetMetadataReference.MicrosoftNetWebApiCore(Constants.NuGetLatestVersion))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace SonarAnalyzer.UnitTest.Rules;
public class JSInvokableMethodsShouldBePublicTest
{
private readonly VerifierBuilder builder = new VerifierBuilder<JSInvokableMethodsShouldBePublic>()
.AddReferences(NuGetMetadataReference.MicrosoftJSInterop(Constants.NuGetLatestVersion));
.AddReferences(NuGetMetadataReference.MicrosoftJSInterop("7.0.14"));

public TestContext TestContext { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private void SomeMethod(bool condition) { } // Compliant

protected override void Up(MigrationBuilder migrationBuilder) { }
}
}").AddReferences(EntityFrameworkCoreReferences(Constants.NuGetLatestVersion)).Verify();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will you open a ticket to bring this back to NuGet Latest?

For example, will we still ignore migrations on Net 8?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we will revert this PR during the migration of UT project to net8.0

}").AddReferences(EntityFrameworkCoreReferences("7.0.14")).Verify();

[DataTestMethod]
[DataRow(ProjectType.Product)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void UriShouldNotBeHardcoded_CSharp_VirtualPath_AspNet(string aspNetMvcVe

[DataTestMethod]
[DataRow("2.0.4", "2.0.3", "2.1.1")]
[DataRow(Constants.NuGetLatestVersion, Constants.NuGetLatestVersion, Constants.NuGetLatestVersion)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will you open a ticket to bring this back to NuGet Latest?

why: we keep LatestVersion to be aware if some API changes lead to our rules creating FPs or FNs (e.g. a deprecated attribute might be removed, so we won't raise anymore on net8 and we need to update the rule)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created the ticket #8363

The goal would be to revert this PR when changing the target framework of the UT project to net8.0

[DataRow("2.2.0", "2.2.0", "2.2.0")]
public void UriShouldNotBeHardcoded_CSharp_VirtualPath_AspNetCore(string aspNetCoreMvcVersion, string aspNetCoreRoutingVersion, string netHttpHeadersVersion) =>
builderCS
.AddPaths("UriShouldNotBeHardcoded.AspNetCore.cs")
Expand Down