-
Notifications
You must be signed in to change notification settings - Fork 753
Expand file tree
/
Copy pathNuGetPropertyDefaultsTests.cs
More file actions
110 lines (96 loc) · 4.46 KB
/
NuGetPropertyDefaultsTests.cs
File metadata and controls
110 lines (96 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// 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 System.IO;
using FluentAssertions;
using NuGet.Frameworks;
using NuGet.Test.Utility;
using Xunit;
using Xunit.Abstractions;
namespace Msbuild.Integration.Test
{
public class NuGetPropertyDefaultsTests : IClassFixture<MsbuildIntegrationTestFixture>
{
private MsbuildIntegrationTestFixture _fixture;
private ITestOutputHelper _output;
public NuGetPropertyDefaultsTests(MsbuildIntegrationTestFixture fixture, ITestOutputHelper output)
{
_fixture = fixture;
_output = output;
}
[Theory]
// .NET 9 SDK
[InlineData("9.0.100", "true", "direct")]
// .NET 8 SDK
[InlineData(null, "true", "direct")]
// non-SDK style project
[InlineData(null, null, "direct")]
// non-SDK style project explicit opt-out
[InlineData("8.0", null, "direct")]
public void NuGetAuditModeDefaults(string SdkAnalysisLevel, string UsingMicrosoftNETSdk, string expected)
{
// Arrange
using var testDirectory = TestDirectory.Create();
string projectText = @"<Project>
<Import Project=""$(NuGetRestoreTargets)"" />
</Project>";
var projectFilePath = Path.Combine(testDirectory, "my.proj");
File.WriteAllText(projectFilePath, projectText);
string args = $"{projectFilePath} -getProperty:NuGetAuditMode";
if (!string.IsNullOrEmpty(SdkAnalysisLevel)) args += $" -p:SdkAnalysisLevel={SdkAnalysisLevel}";
if (!string.IsNullOrEmpty(UsingMicrosoftNETSdk)) args += $" -p:UsingMicrosoftNETSdk={UsingMicrosoftNETSdk}";
// Act
var result = _fixture.RunMsBuild(testDirectory, args);
var resultText = result.Output.Trim();
// Assert
resultText.Should().Be(expected);
}
[Theory]
// .NET (Core) SDK 10.0
[InlineData("10.0.100", "net10.0", "false")]
[InlineData("10.0.100", "net9.0", "false")]
[InlineData("10.0.100", "net8.0", "false")]
[InlineData("10.0.100", "net7.0", "false")]
[InlineData("10.0.100", "net6.0", "false")]
[InlineData("10.0.100", "net5.0", "false")]
[InlineData("10.0.100", "netcoreapp3.1", "false")]
[InlineData("10.0.100", "netcoreapp3.0", "false")]
[InlineData("10.0.100", "netcoreapp2.2", "false")]
[InlineData("10.0.100", "netcoreapp2.1", "false")]
[InlineData("10.0.100", "netcoreapp2.0", "false")]
[InlineData("10.0.100", "netcoreapp1.1", "false")]
[InlineData("10.0.100", "netcoreapp1.0", "false")]
// .NET Standard SDK 10.0
[InlineData("10.0.100", "netstandard2.1", "false")]
[InlineData("10.0.100", "netstandard2.0", "false")]
[InlineData("10.0.100", "netstandard1.6", "false")]
// .NET Framework SDK 10.0
[InlineData("10.0.100", "net48", "false")]
// SDK 10.0
[InlineData("9.0.100", "net10.0", "false")]
[InlineData("9.0.100", "net9.0", "false")]
[InlineData("9.0.100", "net8.0", "false")]
[InlineData("9.0.100", "netstandard2.1", "false")]
[InlineData("9.0.100", "netstandard2.0", "false")]
public void PackagePruningDefaults_RestoreEnablePackagePruning(string SdkAnalysisLevel, string targetFramework, string expected)
{
// Arrange
using var testDirectory = TestDirectory.Create();
string projectText = @"<Project>
<Import Project=""$(NuGetRestoreTargets)"" />
</Project>";
var projectFilePath = Path.Combine(testDirectory, "my.proj");
File.WriteAllText(projectFilePath, projectText);
string args = $"{projectFilePath} -getProperty:RestoreEnablePackagePruning";
if (!string.IsNullOrEmpty(SdkAnalysisLevel)) args += $" -p:SdkAnalysisLevel={SdkAnalysisLevel}";
var framework = NuGetFramework.Parse(targetFramework);
args += $" -p:TargetFrameworkIdentifier={framework.Framework}";
args += $" -p:TargetFrameworkVersion={framework.Version}";
args += $" -p:UsingMicrosoftNETSdk=true";
// Act
var result = _fixture.RunMsBuild(testDirectory, args);
var resultText = result.Output.Trim();
// Assert
resultText.Should().Be(expected);
}
}
}