dependabot-nuget 0.240.0 → 0.242.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/helpers/build +45 -0
- data/helpers/lib/NuGetUpdater/.editorconfig +364 -0
- data/helpers/lib/NuGetUpdater/.gitignore +5 -0
- data/helpers/lib/NuGetUpdater/Directory.Build.props +10 -0
- data/helpers/lib/NuGetUpdater/Directory.Common.props +16 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Build.props +14 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Build.targets +7 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Packages.props +29 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Build.Tasks/NuGet.Build.Tasks.csproj +27 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.CommandLine/AssemblyMetadataExtractor.cs +203 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.CommandLine/NuGet.CommandLine.csproj +33 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Commands/NuGet.Commands.csproj +26 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Common/NuGet.Common.csproj +21 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Config +6 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Configuration/NuGet.Configuration.csproj +24 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Credentials/NuGet.Credentials.csproj +20 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.DependencyResolver.Core/NuGet.DependencyResolver.Core.csproj +22 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Frameworks/NuGet.Frameworks.csproj +17 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.LibraryModel/NuGet.LibraryModel.csproj +17 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.PackageManagement/NuGet.PackageManagement.csproj +27 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Packaging/NuGet.Packaging.csproj +28 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.ProjectModel/NuGet.ProjectModel.csproj +20 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Protocol/NuGet.Protocol.csproj +21 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Resolver/NuGet.Resolver.csproj +20 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Versioning/NuGet.Versioning.csproj +17 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/README.md +1 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/FrameworkCheckCommand.cs +35 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/UpdateCommand.cs +43 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/NuGetUpdater.Cli.csproj +20 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Program.cs +31 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.FrameworkCheck.cs +42 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Update.cs +323 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/NuGetUpdater.Cli.Test.csproj +24 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Dependency.cs +3 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyType.cs +12 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/BuildFile.cs +97 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/DotNetToolsJsonBuildFile.cs +23 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/GlobalJsonBuildFile.cs +36 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/JsonBuildFile.cs +47 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/PackagesConfigBuildFile.cs +31 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/ProjectBuildFile.cs +94 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/XmlBuildFile.cs +14 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/CompatabilityChecker.cs +39 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/FrameworkCompatibilityService.cs +73 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/SupportedFrameworks.cs +146 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/NuGetUpdater.Core.csproj +27 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectManager.cs +316 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectResolver.cs +87 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/ConfigurationFile.cs +3 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/DotNetToolsJsonUpdater.cs +66 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/GlobalJsonUpdater.cs +48 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackagesConfigUpdater.cs +172 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/SdkPackageUpdater.cs +498 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdateResult.cs +7 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +105 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/JsonHelper.cs +222 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/Logger.cs +24 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +460 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/NuGetHelper.cs +15 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/PathHelper.cs +69 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ProcessExtensions.cs +83 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/XmlExtensions.cs +124 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/DotNetToolsJsonBuildFileTests.cs +53 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/GlobalJsonBuildFileTests.cs +80 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/PackagesConfigBuildFileTests.cs +63 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/ProjectBuildFileTests.cs +154 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/CompatibilityCheckerFacts.cs +64 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/FrameworkCompatibilityServiceFacts.cs +122 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/SupportedFrameworkFacts.cs +68 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/NuGetUpdater.Core.Test.csproj +23 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TemporaryDirectory.cs +36 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestExtensions.cs +15 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackagesConfigUpdaterTests.cs +79 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorker.DirsProj.cs +201 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +147 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DotNetTools.cs +225 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.GlobalJson.cs +217 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Mixed.cs +94 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +938 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Sdk.cs +2177 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/JsonHelperTests.cs +239 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +598 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterHelperTests.cs +179 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterTests.cs +238 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.sln +152 -0
- data/helpers/lib/NuGetUpdater/xunit.runner.json +4 -0
- data/lib/dependabot/nuget/metadata_finder.rb +4 -4
- metadata +91 -5
@@ -0,0 +1,124 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Collections.Generic;
|
3
|
+
using System.Linq;
|
4
|
+
|
5
|
+
using Microsoft.Language.Xml;
|
6
|
+
|
7
|
+
namespace NuGetUpdater.Core;
|
8
|
+
|
9
|
+
public static class XmlExtensions
|
10
|
+
{
|
11
|
+
public static string? GetAttributeOrSubElementValue(this IXmlElementSyntax element, string name, StringComparison comparisonType = StringComparison.Ordinal)
|
12
|
+
{
|
13
|
+
var attribute = element.GetAttribute(name, comparisonType);
|
14
|
+
if (attribute is not null)
|
15
|
+
{
|
16
|
+
return attribute.Value;
|
17
|
+
}
|
18
|
+
|
19
|
+
var subElement = element.GetElements(name, comparisonType).FirstOrDefault();
|
20
|
+
return subElement?.GetContentValue();
|
21
|
+
}
|
22
|
+
|
23
|
+
public static IEnumerable<IXmlElementSyntax> GetElements(this IXmlElementSyntax element, string name, StringComparison comparisonType = StringComparison.Ordinal)
|
24
|
+
{
|
25
|
+
return element.Elements.Where(a => a.Name.Equals(name, comparisonType));
|
26
|
+
}
|
27
|
+
|
28
|
+
public static XmlAttributeSyntax? GetAttribute(this IXmlElementSyntax element, string name, StringComparison comparisonType)
|
29
|
+
{
|
30
|
+
return element.Attributes.FirstOrDefault(a => a.Name.Equals(name, comparisonType));
|
31
|
+
}
|
32
|
+
|
33
|
+
public static string GetAttributeValue(this IXmlElementSyntax element, string name, StringComparison comparisonType)
|
34
|
+
{
|
35
|
+
return element.Attributes.First(a => a.Name.Equals(name, comparisonType)).Value;
|
36
|
+
}
|
37
|
+
|
38
|
+
public static XmlAttributeSyntax? GetAttributeCaseInsensitive(this IXmlElementSyntax xml, string name) => GetAttribute(xml, name, StringComparison.OrdinalIgnoreCase);
|
39
|
+
|
40
|
+
public static string? GetAttributeValueCaseInsensitive(this IXmlElementSyntax xml, string name) => xml.GetAttributeCaseInsensitive(name)?.Value;
|
41
|
+
|
42
|
+
public static IXmlElementSyntax WithChildElement(this IXmlElementSyntax parent, string name)
|
43
|
+
{
|
44
|
+
var element = CreateOpenCloseXmlElementSyntax(name);
|
45
|
+
return parent.AddChild(element);
|
46
|
+
}
|
47
|
+
|
48
|
+
public static IXmlElementSyntax WithEmptyChildElement(this IXmlElementSyntax parent, string name)
|
49
|
+
{
|
50
|
+
var element = CreateSingleLineXmlElementSyntax(name);
|
51
|
+
return parent.AddChild(element);
|
52
|
+
}
|
53
|
+
|
54
|
+
public static IXmlElementSyntax WithContent(this IXmlElementSyntax element, string text)
|
55
|
+
{
|
56
|
+
var textSyntax = SyntaxFactory.XmlText(SyntaxFactory.Token(null, SyntaxKind.XmlTextLiteralToken, null, text));
|
57
|
+
return element.WithContent(SyntaxFactory.SingletonList(textSyntax));
|
58
|
+
}
|
59
|
+
|
60
|
+
public static IXmlElementSyntax WithAttribute(this IXmlElementSyntax parent, string name, string value)
|
61
|
+
{
|
62
|
+
var singleSpanceTrivia = SyntaxFactory.WhitespaceTrivia(" ");
|
63
|
+
|
64
|
+
return parent.AddAttribute(SyntaxFactory.XmlAttribute(
|
65
|
+
SyntaxFactory.XmlName(null, SyntaxFactory.XmlNameToken(name, null, null)),
|
66
|
+
SyntaxFactory.Punctuation(SyntaxKind.EqualsToken, "=", null, null),
|
67
|
+
SyntaxFactory.XmlString(
|
68
|
+
SyntaxFactory.Punctuation(SyntaxKind.SingleQuoteToken, "\"", null, null),
|
69
|
+
SyntaxFactory.XmlTextLiteralToken(value, null, null),
|
70
|
+
SyntaxFactory.Punctuation(SyntaxKind.SingleQuoteToken, "\"", null, singleSpanceTrivia))));
|
71
|
+
}
|
72
|
+
|
73
|
+
public static XmlElementSyntax CreateOpenCloseXmlElementSyntax(string name, int indentation = 2, bool spaces = true)
|
74
|
+
{
|
75
|
+
var leadingTrivia = SyntaxFactory.WhitespaceTrivia(new string(' ', indentation));
|
76
|
+
return CreateOpenCloseXmlElementSyntax(name, new SyntaxList<SyntaxNode>(leadingTrivia));
|
77
|
+
}
|
78
|
+
|
79
|
+
public static XmlElementSyntax CreateOpenCloseXmlElementSyntax(string name, SyntaxList<SyntaxNode> leadingTrivia)
|
80
|
+
{
|
81
|
+
var newlineTrivia = SyntaxFactory.WhitespaceTrivia(Environment.NewLine);
|
82
|
+
|
83
|
+
return SyntaxFactory.XmlElement(
|
84
|
+
SyntaxFactory.XmlElementStartTag(
|
85
|
+
SyntaxFactory.Punctuation(SyntaxKind.LessThanToken, "<", leadingTrivia, default),
|
86
|
+
SyntaxFactory.XmlName(null, SyntaxFactory.XmlNameToken(name, null, null)),
|
87
|
+
new SyntaxList<XmlAttributeSyntax>(),
|
88
|
+
SyntaxFactory.Punctuation(SyntaxKind.GreaterThanToken, ">", null, newlineTrivia)),
|
89
|
+
new SyntaxList<SyntaxNode>(),
|
90
|
+
SyntaxFactory.XmlElementEndTag(
|
91
|
+
SyntaxFactory.Punctuation(SyntaxKind.LessThanSlashToken, "</", leadingTrivia, default),
|
92
|
+
SyntaxFactory.XmlName(null, SyntaxFactory.XmlNameToken(name, null, null)),
|
93
|
+
SyntaxFactory.Punctuation(SyntaxKind.GreaterThanToken, ">", null, null)));
|
94
|
+
}
|
95
|
+
|
96
|
+
public static XmlEmptyElementSyntax CreateSingleLineXmlElementSyntax(string name, int indentation = 2, bool spaces = true)
|
97
|
+
{
|
98
|
+
var leadingTrivia = SyntaxFactory.WhitespaceTrivia(new string(' ', indentation));
|
99
|
+
var followingTrivia = SyntaxFactory.WhitespaceTrivia(Environment.NewLine);
|
100
|
+
|
101
|
+
return CreateSingleLineXmlElementSyntax(name, new SyntaxList<SyntaxNode>(leadingTrivia), new SyntaxList<SyntaxNode>(followingTrivia));
|
102
|
+
}
|
103
|
+
|
104
|
+
public static XmlEmptyElementSyntax CreateSingleLineXmlElementSyntax(string name, SyntaxList<SyntaxNode> leadingTrivia, SyntaxList<SyntaxNode> trailingTrivia = default)
|
105
|
+
{
|
106
|
+
var singleSpanceTrivia = SyntaxFactory.WhitespaceTrivia(" ");
|
107
|
+
|
108
|
+
return SyntaxFactory.XmlEmptyElement(
|
109
|
+
SyntaxFactory.Punctuation(SyntaxKind.LessThanToken, "<", leadingTrivia, default),
|
110
|
+
SyntaxFactory.XmlName(null, SyntaxFactory.XmlNameToken(name, null, singleSpanceTrivia)),
|
111
|
+
attributes: new SyntaxList<SyntaxNode>(),
|
112
|
+
SyntaxFactory.Punctuation(SyntaxKind.SlashGreaterThanToken, "/>", default, trailingTrivia));
|
113
|
+
}
|
114
|
+
|
115
|
+
public static IXmlElementSyntax ReplaceAttribute(this IXmlElementSyntax element, XmlAttributeSyntax oldAttribute, XmlAttributeSyntax newAttribute)
|
116
|
+
{
|
117
|
+
return element.WithAttributes(element.AttributesNode.Replace(oldAttribute, newAttribute));
|
118
|
+
}
|
119
|
+
|
120
|
+
public static IXmlElementSyntax ReplaceChildElement(this IXmlElementSyntax element, IXmlElementSyntax oldChildElement, IXmlElementSyntax newChildElement)
|
121
|
+
{
|
122
|
+
return element.WithContent(element.Content.Replace(oldChildElement.AsNode, newChildElement.AsNode));
|
123
|
+
}
|
124
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
using System.Collections.Generic;
|
2
|
+
using System.Diagnostics.CodeAnalysis;
|
3
|
+
|
4
|
+
using Xunit;
|
5
|
+
|
6
|
+
namespace NuGetUpdater.Core.Test.Files;
|
7
|
+
|
8
|
+
public class DotnetToolsJsonBuildFileTests
|
9
|
+
{
|
10
|
+
[StringSyntax(StringSyntaxAttribute.Json)]
|
11
|
+
const string DotnetToolsJson = """
|
12
|
+
{
|
13
|
+
"version": 1,
|
14
|
+
"isRoot": true,
|
15
|
+
"tools": {
|
16
|
+
"microsoft.botsay": {
|
17
|
+
"version": "1.0.0",
|
18
|
+
"commands": [
|
19
|
+
"botsay"
|
20
|
+
]
|
21
|
+
},
|
22
|
+
"dotnetsay": {
|
23
|
+
"version": "2.1.3",
|
24
|
+
"commands": [
|
25
|
+
"dotnetsay"
|
26
|
+
]
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
""";
|
31
|
+
|
32
|
+
private static DotNetToolsJsonBuildFile GetBuildFile() => new(
|
33
|
+
repoRootPath: "/",
|
34
|
+
path: "/.config/dotnet-tools.json",
|
35
|
+
contents: DotnetToolsJson,
|
36
|
+
logger: new Logger(verbose: true));
|
37
|
+
|
38
|
+
[Fact]
|
39
|
+
public void GetDependencies_ReturnsDependencies()
|
40
|
+
{
|
41
|
+
var expectedDependencies = new List<Dependency>
|
42
|
+
{
|
43
|
+
new("microsoft.botsay", "1.0.0", DependencyType.DotNetTool),
|
44
|
+
new("dotnetsay", "2.1.3", DependencyType.DotNetTool)
|
45
|
+
};
|
46
|
+
|
47
|
+
var buildFile = GetBuildFile();
|
48
|
+
|
49
|
+
var dependencies = buildFile.GetDependencies();
|
50
|
+
|
51
|
+
Assert.Equal(expectedDependencies, dependencies);
|
52
|
+
}
|
53
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
using System.Collections.Generic;
|
2
|
+
using System.Diagnostics.CodeAnalysis;
|
3
|
+
using System.Linq;
|
4
|
+
|
5
|
+
using Xunit;
|
6
|
+
|
7
|
+
namespace NuGetUpdater.Core.Test.Files;
|
8
|
+
|
9
|
+
public class GlobalJsonBuildFileTests
|
10
|
+
{
|
11
|
+
[StringSyntax(StringSyntaxAttribute.Json)]
|
12
|
+
const string GlobalJson = """
|
13
|
+
{
|
14
|
+
"sdk": {
|
15
|
+
"version": "6.0.405",
|
16
|
+
"rollForward": "latestPatch"
|
17
|
+
},
|
18
|
+
"msbuild-sdks": {
|
19
|
+
"My.Custom.Sdk": "5.0.0",
|
20
|
+
"My.Other.Sdk": "1.0.0-beta"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
""";
|
24
|
+
|
25
|
+
[StringSyntax(StringSyntaxAttribute.Json)]
|
26
|
+
const string EmptyGlobalJson = """
|
27
|
+
{
|
28
|
+
}
|
29
|
+
""";
|
30
|
+
|
31
|
+
private static GlobalJsonBuildFile GetBuildFile(string contents) => new(
|
32
|
+
repoRootPath: "/",
|
33
|
+
path: "/global.json",
|
34
|
+
contents: contents,
|
35
|
+
logger: new Logger(verbose: true));
|
36
|
+
|
37
|
+
[Fact]
|
38
|
+
public void GlobalJson_Malformed_DoesNotThrow()
|
39
|
+
{
|
40
|
+
var buildFile = GetBuildFile("""[{ "Random": "stuff"}]""");
|
41
|
+
|
42
|
+
Assert.Null(buildFile.MSBuildSdks);
|
43
|
+
}
|
44
|
+
|
45
|
+
[Fact]
|
46
|
+
public void GlobalJson_NotJson_DoesNotThrow()
|
47
|
+
{
|
48
|
+
var buildFile = GetBuildFile("not json");
|
49
|
+
|
50
|
+
Assert.Null(buildFile.MSBuildSdks);
|
51
|
+
}
|
52
|
+
|
53
|
+
[Fact]
|
54
|
+
public void GlobalJson_GetDependencies_ReturnsDependencies()
|
55
|
+
{
|
56
|
+
var expectedDependencies = new List<Dependency>
|
57
|
+
{
|
58
|
+
new("My.Custom.Sdk", "5.0.0", DependencyType.MSBuildSdk),
|
59
|
+
new("My.Other.Sdk", "1.0.0-beta", DependencyType.MSBuildSdk)
|
60
|
+
};
|
61
|
+
|
62
|
+
var buildFile = GetBuildFile(GlobalJson);
|
63
|
+
|
64
|
+
var dependencies = buildFile.GetDependencies();
|
65
|
+
|
66
|
+
Assert.Equal(expectedDependencies, dependencies);
|
67
|
+
}
|
68
|
+
|
69
|
+
[Fact]
|
70
|
+
public void EmptyGlobalJson_GetDependencies_ReturnsNoDependencies()
|
71
|
+
{
|
72
|
+
var expectedDependencies = Enumerable.Empty<Dependency>();
|
73
|
+
|
74
|
+
var buildFile = GetBuildFile(EmptyGlobalJson);
|
75
|
+
|
76
|
+
var dependencies = buildFile.GetDependencies();
|
77
|
+
|
78
|
+
Assert.Equal(expectedDependencies, dependencies);
|
79
|
+
}
|
80
|
+
}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
using System.Collections.Generic;
|
2
|
+
using System.Diagnostics.CodeAnalysis;
|
3
|
+
using System.Linq;
|
4
|
+
|
5
|
+
using Microsoft.Language.Xml;
|
6
|
+
|
7
|
+
using Xunit;
|
8
|
+
|
9
|
+
namespace NuGetUpdater.Core.Test.Files;
|
10
|
+
|
11
|
+
public class PackagesConfigBuildFileTests
|
12
|
+
{
|
13
|
+
[StringSyntax(StringSyntaxAttribute.Xml)]
|
14
|
+
const string PackagesConfig = """
|
15
|
+
<?xml version="1.0" encoding="utf-8"?>
|
16
|
+
<packages>
|
17
|
+
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net46" />
|
18
|
+
<package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net46" developmentDependency="true" />
|
19
|
+
<package id="Newtonsoft.Json" version="8.0.3" allowedVersions="[8,10)" targetFramework="net46" />
|
20
|
+
</packages>
|
21
|
+
""";
|
22
|
+
|
23
|
+
[StringSyntax(StringSyntaxAttribute.Xml)]
|
24
|
+
const string EmptyPackagesConfig = """
|
25
|
+
<?xml version="1.0" encoding="utf-8"?>
|
26
|
+
<packages>
|
27
|
+
</packages>
|
28
|
+
""";
|
29
|
+
|
30
|
+
private static PackagesConfigBuildFile GetBuildFile(string contents) => new(
|
31
|
+
repoRootPath: "/",
|
32
|
+
path: "/packages.config",
|
33
|
+
contents: Parser.ParseText(contents));
|
34
|
+
|
35
|
+
[Fact]
|
36
|
+
public void PackagesConfig_GetDependencies_ReturnsDependencies()
|
37
|
+
{
|
38
|
+
var expectedDependencies = new List<Dependency>
|
39
|
+
{
|
40
|
+
new("Microsoft.CodeDom.Providers.DotNetCompilerPlatform", "1.0.0", DependencyType.PackageConfig),
|
41
|
+
new("Microsoft.Net.Compilers", "1.0.0", DependencyType.PackageConfig, true),
|
42
|
+
new("Newtonsoft.Json", "8.0.3", DependencyType.PackageConfig)
|
43
|
+
};
|
44
|
+
|
45
|
+
var buildFile = GetBuildFile(PackagesConfig);
|
46
|
+
|
47
|
+
var dependencies = buildFile.GetDependencies();
|
48
|
+
|
49
|
+
Assert.Equal(expectedDependencies, dependencies);
|
50
|
+
}
|
51
|
+
|
52
|
+
[Fact]
|
53
|
+
public void EmptyPackagesConfig_GetDependencies_ReturnsNoDependencies()
|
54
|
+
{
|
55
|
+
var expectedDependencies = Enumerable.Empty<Dependency>();
|
56
|
+
|
57
|
+
var buildFile = GetBuildFile(EmptyPackagesConfig);
|
58
|
+
|
59
|
+
var dependencies = buildFile.GetDependencies();
|
60
|
+
|
61
|
+
Assert.Equal(expectedDependencies, dependencies);
|
62
|
+
}
|
63
|
+
}
|
@@ -0,0 +1,154 @@
|
|
1
|
+
using System.Collections.Generic;
|
2
|
+
using System.Diagnostics.CodeAnalysis;
|
3
|
+
using System.Linq;
|
4
|
+
using System.Text.RegularExpressions;
|
5
|
+
|
6
|
+
using Microsoft.Language.Xml;
|
7
|
+
|
8
|
+
using Xunit;
|
9
|
+
|
10
|
+
namespace NuGetUpdater.Core.Test.Files;
|
11
|
+
|
12
|
+
public class ProjectBuildFileTests
|
13
|
+
{
|
14
|
+
[StringSyntax(StringSyntaxAttribute.Xml)]
|
15
|
+
const string ProjectCsProj = """
|
16
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
17
|
+
<PropertyGroup>
|
18
|
+
<OutputType>Exe</OutputType>
|
19
|
+
<TargetFramework>net7.0</TargetFramework>
|
20
|
+
</PropertyGroup>
|
21
|
+
<ItemGroup>
|
22
|
+
<ProjectReference Include=".\Library\Library.csproj" />
|
23
|
+
</ItemGroup>
|
24
|
+
<ItemGroup>
|
25
|
+
<PackageReference Include="GuiLabs.Language.Xml" Version="1.2.60" />
|
26
|
+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
|
27
|
+
<PackageReference Update="Newtonsoft.Json" VersionOverride="13.0.3" />
|
28
|
+
</ItemGroup>
|
29
|
+
</Project>
|
30
|
+
""";
|
31
|
+
|
32
|
+
[StringSyntax(StringSyntaxAttribute.Xml)]
|
33
|
+
const string EmptyProject = """
|
34
|
+
<Project>
|
35
|
+
</Project>
|
36
|
+
""";
|
37
|
+
|
38
|
+
[StringSyntax(StringSyntaxAttribute.Xml)]
|
39
|
+
const string DirectoryPackagesProps = """
|
40
|
+
<Project>
|
41
|
+
<PropertyGroup>
|
42
|
+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
43
|
+
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
|
44
|
+
</PropertyGroup>
|
45
|
+
<ItemGroup>
|
46
|
+
<GlobalPackageReference Include="Microsoft.CodeAnalysis.Common" Version="$(RoslynVersion)" />
|
47
|
+
<PackageVersion Include="Newtonsoft.Json" VersionOverride="13.0.1" />
|
48
|
+
</ItemGroup>
|
49
|
+
</Project>
|
50
|
+
""";
|
51
|
+
|
52
|
+
private static ProjectBuildFile GetBuildFile(string contents, string filename) => new(
|
53
|
+
repoRootPath: "/",
|
54
|
+
path: $"/{filename}",
|
55
|
+
contents: Parser.ParseText(contents));
|
56
|
+
|
57
|
+
[Fact]
|
58
|
+
public void ProjectCsProj_GetDependencies_ReturnsDependencies()
|
59
|
+
{
|
60
|
+
var expectedDependencies = new List<Dependency>
|
61
|
+
{
|
62
|
+
new("GuiLabs.Language.Xml", "1.2.60", DependencyType.PackageReference),
|
63
|
+
new("Microsoft.CodeAnalysis.CSharp", null, DependencyType.PackageReference),
|
64
|
+
new("Newtonsoft.Json", "13.0.3", DependencyType.PackageReference, IsOverride: true)
|
65
|
+
};
|
66
|
+
|
67
|
+
var buildFile = GetBuildFile(ProjectCsProj, "Project.csproj");
|
68
|
+
|
69
|
+
var dependencies = buildFile.GetDependencies();
|
70
|
+
|
71
|
+
Assert.Equal(expectedDependencies, dependencies);
|
72
|
+
}
|
73
|
+
|
74
|
+
[Fact]
|
75
|
+
public void ProjectCsProj_ReferencedProjectPaths_ReturnsPaths()
|
76
|
+
{
|
77
|
+
var expectedReferencedProjectPaths = new List<string>
|
78
|
+
{
|
79
|
+
"/Library/Library.csproj"
|
80
|
+
};
|
81
|
+
|
82
|
+
var buildFile = GetBuildFile(ProjectCsProj, "Project.csproj");
|
83
|
+
|
84
|
+
var referencedProjectPaths = buildFile.GetReferencedProjectPaths()
|
85
|
+
.Select(p => Regex.IsMatch(p, @"^[A-Z]:\\") ? "/" + p.Substring(@"C:\".Length) : p) // remove drive letter when testing on Windows
|
86
|
+
.Select(p => p.NormalizePathToUnix());
|
87
|
+
|
88
|
+
Assert.Equal(expectedReferencedProjectPaths, referencedProjectPaths);
|
89
|
+
}
|
90
|
+
|
91
|
+
[Fact]
|
92
|
+
public void DirectoryPackagesProps_GetDependencies_ReturnsDependencies()
|
93
|
+
{
|
94
|
+
var expectedDependencies = new List<Dependency>
|
95
|
+
{
|
96
|
+
new("Microsoft.CodeAnalysis.Common", "$(RoslynVersion)", DependencyType.GlobalPackageReference),
|
97
|
+
new("Newtonsoft.Json", "13.0.1", DependencyType.PackageVersion, IsOverride: true)
|
98
|
+
};
|
99
|
+
|
100
|
+
var buildFile = GetBuildFile(DirectoryPackagesProps, "Directory.Packages.props");
|
101
|
+
|
102
|
+
var dependencies = buildFile.GetDependencies();
|
103
|
+
|
104
|
+
Assert.Equal(expectedDependencies, dependencies);
|
105
|
+
}
|
106
|
+
|
107
|
+
[Fact]
|
108
|
+
public void DirectoryPackagesProps_Properties_ReturnsProperties()
|
109
|
+
{
|
110
|
+
var expectedProperties = new List<KeyValuePair<string, string>>
|
111
|
+
{
|
112
|
+
new("ManagePackageVersionsCentrally", "true"),
|
113
|
+
new("CentralPackageTransitivePinningEnabled", "true")
|
114
|
+
};
|
115
|
+
|
116
|
+
var buildFile = GetBuildFile(DirectoryPackagesProps, "Directory.Packages.props");
|
117
|
+
|
118
|
+
var properties = buildFile.GetProperties();
|
119
|
+
|
120
|
+
Assert.Equal(expectedProperties, properties);
|
121
|
+
}
|
122
|
+
|
123
|
+
[Fact]
|
124
|
+
public void EmptyProject_GetDependencies_ReturnsNoDependencies()
|
125
|
+
{
|
126
|
+
var expectedDependencies = Enumerable.Empty<Dependency>();
|
127
|
+
|
128
|
+
var buildFile = GetBuildFile(EmptyProject, "project.csproj");
|
129
|
+
|
130
|
+
var dependencies = buildFile.GetDependencies();
|
131
|
+
|
132
|
+
Assert.Equal(expectedDependencies, dependencies);
|
133
|
+
}
|
134
|
+
|
135
|
+
[Theory]
|
136
|
+
[InlineData( // no change made
|
137
|
+
@"<Project><ItemGroup><Reference><HintPath>path\to\file.dll</HintPath></Reference></ItemGroup></Project>",
|
138
|
+
@"<Project><ItemGroup><Reference><HintPath>path\to\file.dll</HintPath></Reference></ItemGroup></Project>"
|
139
|
+
)]
|
140
|
+
[InlineData( // change from `/` to `\`
|
141
|
+
"<Project><ItemGroup><Reference><HintPath>path/to/file.dll</HintPath></Reference></ItemGroup></Project>",
|
142
|
+
@"<Project><ItemGroup><Reference><HintPath>path\to\file.dll</HintPath></Reference></ItemGroup></Project>"
|
143
|
+
)]
|
144
|
+
[InlineData( // multiple changes made
|
145
|
+
"<Project><ItemGroup><Reference><HintPath>path1/to1/file1.dll</HintPath></Reference><Reference><HintPath>path2/to2/file2.dll</HintPath></Reference></ItemGroup></Project>",
|
146
|
+
@"<Project><ItemGroup><Reference><HintPath>path1\to1\file1.dll</HintPath></Reference><Reference><HintPath>path2\to2\file2.dll</HintPath></Reference></ItemGroup></Project>"
|
147
|
+
)]
|
148
|
+
public void ReferenceHintPathsCanBeNormalized(string originalXml, string expectedXml)
|
149
|
+
{
|
150
|
+
ProjectBuildFile? buildFile = GetBuildFile(originalXml, "project.csproj");
|
151
|
+
buildFile.NormalizeDirectorySeparatorsInProject();
|
152
|
+
Assert.Equal(expectedXml, buildFile.Contents.ToFullString());
|
153
|
+
}
|
154
|
+
}
|
data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/CompatibilityCheckerFacts.cs
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
using NuGetUpdater.Core.FrameworkChecker;
|
2
|
+
|
3
|
+
using Xunit;
|
4
|
+
|
5
|
+
namespace NuGetUpdater.Core.Test.FrameworkChecker;
|
6
|
+
|
7
|
+
public class CompatibilityCheckerFacts
|
8
|
+
{
|
9
|
+
[Theory]
|
10
|
+
[InlineData("net8.0", "net8.0")]
|
11
|
+
[InlineData("net8.0", "net7.0")]
|
12
|
+
[InlineData("net7.0", "net7.0")]
|
13
|
+
[InlineData("net7.0", "net6.0")]
|
14
|
+
[InlineData("net7.0", "net5.0")]
|
15
|
+
[InlineData("net7.0", "netcoreapp3.1")]
|
16
|
+
[InlineData("net7.0", "netstandard2.1")]
|
17
|
+
[InlineData("net7.0", "netstandard2.0")]
|
18
|
+
[InlineData("net7.0", "netstandard1.3")]
|
19
|
+
[InlineData("net4.8", "netstandard2.0")]
|
20
|
+
[InlineData("net4.8", "netstandard1.3")]
|
21
|
+
public void PackageContainsCompatibleFramework(string projectTfm, string packageTfm)
|
22
|
+
{
|
23
|
+
var result = CompatibilityChecker.IsCompatible(new[] { projectTfm }, new[] { packageTfm }, new Logger(verbose: true));
|
24
|
+
|
25
|
+
Assert.True(result);
|
26
|
+
}
|
27
|
+
|
28
|
+
[Theory]
|
29
|
+
[InlineData("net48", "netcoreapp3.1")]
|
30
|
+
[InlineData("net48", "netstandard2.1")]
|
31
|
+
[InlineData("net7.0", "net8.0")]
|
32
|
+
[InlineData("net6.0", "net7.0")]
|
33
|
+
[InlineData("net5.0", "net6.0")]
|
34
|
+
[InlineData("netcoreapp3.1", "net5.0")]
|
35
|
+
[InlineData("netstandard2.0", "netstandard2.1")]
|
36
|
+
[InlineData("netstandard1.3", "netstandard2.0")]
|
37
|
+
[InlineData("net7.0", "net48")]
|
38
|
+
public void PackageContainsIncompatibleFramework(string projectTfm, string packageTfm)
|
39
|
+
{
|
40
|
+
var result = CompatibilityChecker.IsCompatible(new[] { projectTfm }, new[] { packageTfm }, new Logger(verbose: true));
|
41
|
+
|
42
|
+
Assert.False(result);
|
43
|
+
}
|
44
|
+
|
45
|
+
[Theory]
|
46
|
+
[InlineData(new[] { "net8.0", "net7.0", "net472" }, new[] { "netstandard2.0" })]
|
47
|
+
[InlineData(new[] { "net8.0", "net7.0", "net472" }, new[] { "net5.0", "net461" })]
|
48
|
+
[InlineData(new[] { "net6.0", "net6.0-windows10.0.19041" }, new[] { "net6.0", ".NETStandard2.0" })]
|
49
|
+
public void PackageContainsCompatibleFrameworks(string[] projectTfms, string[] packageTfms)
|
50
|
+
{
|
51
|
+
var result = CompatibilityChecker.IsCompatible(projectTfms, packageTfms, new Logger(verbose: true));
|
52
|
+
|
53
|
+
Assert.True(result);
|
54
|
+
}
|
55
|
+
|
56
|
+
[Theory]
|
57
|
+
[InlineData(new[] { "net7.0", "net472" }, new[] { "net5.0" })]
|
58
|
+
public void PackageContainsIncompatibleFrameworks(string[] projectTfms, string[] packageTfms)
|
59
|
+
{
|
60
|
+
var result = CompatibilityChecker.IsCompatible(projectTfms, packageTfms, new Logger(verbose: true));
|
61
|
+
|
62
|
+
Assert.False(result);
|
63
|
+
}
|
64
|
+
}
|
@@ -0,0 +1,122 @@
|
|
1
|
+
// Copyright (c) .NET Foundation. All rights reserved.
|
2
|
+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
3
|
+
|
4
|
+
using System;
|
5
|
+
using System.Collections.Generic;
|
6
|
+
using System.Linq;
|
7
|
+
|
8
|
+
using NuGet.Frameworks;
|
9
|
+
|
10
|
+
using NuGetUpdater.Core.FrameworkChecker;
|
11
|
+
|
12
|
+
using Xunit;
|
13
|
+
|
14
|
+
namespace NuGetUpdater.Core.Test.FrameworkChecker;
|
15
|
+
|
16
|
+
public class FrameworkCompatibilityServiceFacts
|
17
|
+
{
|
18
|
+
private readonly FrameworkCompatibilityService _service;
|
19
|
+
private readonly IFrameworkCompatibilityProvider _compatibilityProvider = DefaultCompatibilityProvider.Instance;
|
20
|
+
|
21
|
+
public FrameworkCompatibilityServiceFacts()
|
22
|
+
{
|
23
|
+
_service = new FrameworkCompatibilityService();
|
24
|
+
}
|
25
|
+
|
26
|
+
[Fact]
|
27
|
+
public void NullPackageFrameworksThrowsArgumentNullException()
|
28
|
+
{
|
29
|
+
Assert.Throws<ArgumentNullException>(() => _service.GetCompatibleFrameworks(null));
|
30
|
+
}
|
31
|
+
|
32
|
+
[Fact]
|
33
|
+
public void EmptyPackageFrameworksReturnsEmptySet()
|
34
|
+
{
|
35
|
+
var result = _service.GetCompatibleFrameworks(new List<NuGetFramework>());
|
36
|
+
|
37
|
+
Assert.Empty(result);
|
38
|
+
}
|
39
|
+
|
40
|
+
[Fact]
|
41
|
+
public void UnknownSupportedPackageReturnsSetWithSameFramework()
|
42
|
+
{
|
43
|
+
var framework = NuGetFramework.Parse("net45-client");
|
44
|
+
var frameworks = new List<NuGetFramework>() { framework };
|
45
|
+
var compatible = _service.GetCompatibleFrameworks(frameworks);
|
46
|
+
|
47
|
+
Assert.False(framework.IsUnsupported);
|
48
|
+
Assert.Equal(expected: 1, compatible.Count);
|
49
|
+
Assert.Contains(framework, compatible);
|
50
|
+
}
|
51
|
+
|
52
|
+
[Theory]
|
53
|
+
[InlineData("1000")]
|
54
|
+
[InlineData("lib")]
|
55
|
+
[InlineData("nuget")]
|
56
|
+
public void UnsupportedPackageFrameworksReturnsEmptySet(string unsupportedFrameworkName)
|
57
|
+
{
|
58
|
+
var unsupportedFramework = NuGetFramework.Parse(unsupportedFrameworkName);
|
59
|
+
|
60
|
+
var result = _service.GetCompatibleFrameworks(new List<NuGetFramework>() { unsupportedFramework });
|
61
|
+
|
62
|
+
Assert.True(unsupportedFramework.IsUnsupported);
|
63
|
+
Assert.Equal(expected: 0, actual: result.Count);
|
64
|
+
}
|
65
|
+
|
66
|
+
[Theory]
|
67
|
+
[InlineData("portable-net45+sl4+win8+wp7")]
|
68
|
+
[InlineData("portable-net40+sl4")]
|
69
|
+
[InlineData("portable-net45+sl5+win8+wpa81+wp8")]
|
70
|
+
public void PCLPackageFrameworksReturnsEmptySet(string pclFrameworkName)
|
71
|
+
{
|
72
|
+
var portableFramework = NuGetFramework.Parse(pclFrameworkName);
|
73
|
+
|
74
|
+
var result = _service.GetCompatibleFrameworks(new List<NuGetFramework>() { portableFramework });
|
75
|
+
|
76
|
+
Assert.True(portableFramework.IsPCL);
|
77
|
+
Assert.Equal(expected: 0, actual: result.Count);
|
78
|
+
}
|
79
|
+
|
80
|
+
[Theory]
|
81
|
+
[InlineData("net5.0", "netcoreapp2.0", "win81")]
|
82
|
+
[InlineData("sl4", "netstandard1.2", "netmf")]
|
83
|
+
public void ValidPackageFrameworksReturnsFrameworksCompatibleForAtLeastOne(params string[] frameworkNames)
|
84
|
+
{
|
85
|
+
var frameworks = new List<NuGetFramework>();
|
86
|
+
|
87
|
+
foreach (var frameworkName in frameworkNames)
|
88
|
+
{
|
89
|
+
frameworks.Add(NuGetFramework.Parse(frameworkName));
|
90
|
+
}
|
91
|
+
|
92
|
+
var compatibleFrameworks = _service.GetCompatibleFrameworks(frameworks);
|
93
|
+
|
94
|
+
Assert.True(compatibleFrameworks.Count > 0);
|
95
|
+
|
96
|
+
foreach (var compatibleFramework in compatibleFrameworks)
|
97
|
+
{
|
98
|
+
var isCompatible = frameworks.Any(f => _compatibilityProvider.IsCompatible(compatibleFramework, f));
|
99
|
+
|
100
|
+
Assert.True(isCompatible);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
[Theory]
|
105
|
+
[InlineData("net6.0-windows7.0", "net6.0-windows", "net6.0-windows7.0", "net7.0-windows", "net7.0-windows7.0")]
|
106
|
+
public void WindowsPlatformVersionsShouldContainAllSpecifiedFrameworks(string windowsDefaultVersionFramework, params string[] windowsProjectFrameworks)
|
107
|
+
{
|
108
|
+
var packageFramework = NuGetFramework.Parse(windowsDefaultVersionFramework);
|
109
|
+
var projectFrameworks = new HashSet<NuGetFramework>();
|
110
|
+
|
111
|
+
foreach (var frameworkName in windowsProjectFrameworks)
|
112
|
+
{
|
113
|
+
projectFrameworks.Add(NuGetFramework.Parse(frameworkName));
|
114
|
+
}
|
115
|
+
|
116
|
+
var compatibleFrameworks = _service.GetCompatibleFrameworks(new HashSet<NuGetFramework>() { packageFramework });
|
117
|
+
Assert.Equal(windowsProjectFrameworks.Length, compatibleFrameworks.Count);
|
118
|
+
|
119
|
+
var containsAllCompatibleFrameworks = compatibleFrameworks.All(cf => projectFrameworks.Contains(cf));
|
120
|
+
Assert.True(containsAllCompatibleFrameworks);
|
121
|
+
}
|
122
|
+
}
|