-
Notifications
You must be signed in to change notification settings - Fork 686
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SdkAnalysisLevel in restorecommand http-errors (#5925)
Use SdkAnalysisLevel in restorecommand http-errors (#5925)
- Loading branch information
1 parent
12a39e1
commit 18a6790
Showing
4 changed files
with
191 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/NuGet.Core/NuGet.Commands/Utility/SdkAnalysisLevelMinimums.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using NuGet.Versioning; | ||
|
||
namespace NuGet.Commands | ||
{ | ||
/// <summary> | ||
/// Defines constants that specify the minimum SDK analysis level required to enable new features. | ||
/// </summary> | ||
internal static class SdkAnalysisLevelMinimums | ||
{ | ||
/// <summary> | ||
/// Minimum SDK Analysis Level required to enable HTTP Errors is 9.0.100. | ||
/// </summary> | ||
internal static readonly NuGetVersion HttpErrorSdkAnalysisLevelMinimumValue = new("9.0.100"); | ||
|
||
/// <summary> | ||
/// Determines whether the feature is enabled based on the SDK analysis level. | ||
/// </summary> | ||
/// <param name="sdkAnalysisLevel">The project SdkAnalysisLevel value </param> | ||
/// <param name="usingMicrosoftNetSdk">Is it SDK project or not</param> | ||
/// <param name="minSdkVersion">The minimum version of the SDK required for the feature to be enabled.</param> | ||
/// <returns>Returns true if the feature should be enabled based on the given parameters; otherwise, false.</returns> | ||
public static bool IsEnabled(NuGetVersion sdkAnalysisLevel, bool usingMicrosoftNetSdk, NuGetVersion minSdkVersion) | ||
{ | ||
if (sdkAnalysisLevel != null && sdkAnalysisLevel >= minSdkVersion || | ||
sdkAnalysisLevel == null && usingMicrosoftNetSdk == false) | ||
{ | ||
// SdkAnalysisLevel >= minSdkVersion or SdkAnalysisLevel is null and not using Microsoft NET Sdk | ||
return true; | ||
} | ||
else | ||
{ | ||
// SdkAnalysisLevel < minSdkVersion or SdkAnalysisLevel is null and using Microsoft NET Sdk | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
test/NuGet.Core.Tests/NuGet.Commands.Test/SdkAnalysisLevelMinimumsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using NuGet.Versioning; | ||
using Xunit; | ||
|
||
namespace NuGet.Commands.Test | ||
{ | ||
public class SdkAnalysisLevelMinimumsTests | ||
{ | ||
[Fact] | ||
public void IsEnabled_WhenSdkAnalysisLevelIsNullAndUsingMicrosoftNetSdkIsFalse_ShouldReturnTrue() | ||
{ | ||
var result = SdkAnalysisLevelMinimums.IsEnabled(null, false, new NuGetVersion("9.0.100")); | ||
Assert.True(result); | ||
} | ||
|
||
[Fact] | ||
public void IsEnabled_WhenSdkAnalysisLevelIsNullAndUsingMicrosoftNetSdkIsTrue_ShouldReturnFalse() | ||
{ | ||
var result = SdkAnalysisLevelMinimums.IsEnabled(null, true, new NuGetVersion("9.0.100")); | ||
Assert.False(result); | ||
} | ||
|
||
[Fact] | ||
public void IsEnabled_WhenSdkAnalysisLevelIsLessThanMinSdkVersion_ShouldReturnFalse() | ||
{ | ||
var result = SdkAnalysisLevelMinimums.IsEnabled(new NuGetVersion("8.0.900"), true, new NuGetVersion("9.0.100")); | ||
Assert.False(result); | ||
} | ||
|
||
[Fact] | ||
public void IsEnabled_WhenSdkAnalysisLevelIsEqualToMinSdkVersion_ShouldReturnTrue() | ||
{ | ||
var result = SdkAnalysisLevelMinimums.IsEnabled(new NuGetVersion("9.0.100"), true, new NuGetVersion("9.0.100")); | ||
Assert.True(result); | ||
} | ||
|
||
[Fact] | ||
public void IsEnabled_WhenSdkAnalysisLevelIsGreaterThanMinSdkVersion_ShouldReturnTrue() | ||
{ | ||
var result = SdkAnalysisLevelMinimums.IsEnabled(new NuGetVersion("9.0.101"), true, new NuGetVersion("9.0.100")); | ||
Assert.True(result); | ||
} | ||
} | ||
} |