dependabot-nuget 0.240.0 → 0.241.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 +24 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/GlobalJsonBuildFile.cs +25 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/JsonBuildFile.cs +32 -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 +443 -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 +66 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/XmlExtensions.cs +124 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/DotNetToolsJsonBuildFileTests.cs +52 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/GlobalJsonBuildFileTests.cs +63 -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 +394 -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,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
|
+
}
|
data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/SupportedFrameworkFacts.cs
ADDED
@@ -0,0 +1,68 @@
|
|
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.Collections.Generic;
|
5
|
+
using System.Linq;
|
6
|
+
|
7
|
+
using NuGet.Frameworks;
|
8
|
+
|
9
|
+
using NuGetGallery.Frameworks;
|
10
|
+
|
11
|
+
using Xunit;
|
12
|
+
|
13
|
+
using static NuGet.Frameworks.FrameworkConstants;
|
14
|
+
using static NuGet.Frameworks.FrameworkConstants.CommonFrameworks;
|
15
|
+
|
16
|
+
namespace NuGetUpdater.Core.Test.FrameworkChecker;
|
17
|
+
|
18
|
+
public class SupportedFrameworksFacts
|
19
|
+
{
|
20
|
+
private static readonly NuGetFramework Win = new NuGetFramework(FrameworkIdentifiers.Windows, EmptyVersion);
|
21
|
+
private static readonly NuGetFramework WinRt = new NuGetFramework(FrameworkIdentifiers.WinRT, EmptyVersion);
|
22
|
+
|
23
|
+
// See: https://docs.microsoft.com/en-us/dotnet/standard/frameworks#deprecated-target-frameworks
|
24
|
+
private readonly HashSet<NuGetFramework> DeprecatedFrameworks = new HashSet<NuGetFramework>() {
|
25
|
+
AspNet, AspNet50, AspNetCore, AspNetCore50,
|
26
|
+
Dnx, Dnx45, Dnx451, Dnx452, DnxCore, DnxCore50,
|
27
|
+
DotNet, DotNet50, DotNet51, DotNet52, DotNet53, DotNet54, DotNet55, DotNet56,
|
28
|
+
NetCore50,
|
29
|
+
Win, Win8, Win81, Win10,
|
30
|
+
WinRt
|
31
|
+
};
|
32
|
+
// The following frameworks were included in NuGet.Client code but they were not official framework releases.
|
33
|
+
private readonly HashSet<NuGetFramework> UnofficialFrameworks = new HashSet<NuGetFramework>()
|
34
|
+
{
|
35
|
+
NetStandard17, NetStandardApp15
|
36
|
+
};
|
37
|
+
|
38
|
+
[Fact]
|
39
|
+
public void SupportedFrameworksContainsCommonFrameworksWithNoDeprecatedFrameworks()
|
40
|
+
{
|
41
|
+
var fields = typeof(FrameworkConstants.CommonFrameworks)
|
42
|
+
.GetFields()
|
43
|
+
.Where(f => f.FieldType == typeof(NuGetFramework))
|
44
|
+
.ToList();
|
45
|
+
|
46
|
+
Assert.True(fields.Count > 0);
|
47
|
+
|
48
|
+
var supportedFrameworks = new HashSet<NuGetFramework>(SupportedFrameworks.AllSupportedNuGetFrameworks);
|
49
|
+
|
50
|
+
foreach (var field in fields)
|
51
|
+
{
|
52
|
+
var framework = (NuGetFramework)field.GetValue(null);
|
53
|
+
|
54
|
+
if (DeprecatedFrameworks.Contains(framework))
|
55
|
+
{
|
56
|
+
Assert.False(supportedFrameworks.Contains(framework), $"SupportedFrameworks should not contain the deprecated framework {field.Name}.");
|
57
|
+
}
|
58
|
+
else if (UnofficialFrameworks.Contains(framework))
|
59
|
+
{
|
60
|
+
Assert.False(supportedFrameworks.Contains(framework), $"SupportedFrameworks should not contain the unofficial framework {field.Name}.");
|
61
|
+
}
|
62
|
+
else
|
63
|
+
{
|
64
|
+
Assert.True(supportedFrameworks.Contains(framework), $"SupportedFrameworks is missing {field.Name} constant from CommonFrameworks.");
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
2
|
+
|
3
|
+
<PropertyGroup>
|
4
|
+
<TargetFramework>$(CommonTargetFramework)</TargetFramework>
|
5
|
+
<OutputType>Exe</OutputType>
|
6
|
+
<Nullable>enable</Nullable>
|
7
|
+
</PropertyGroup>
|
8
|
+
|
9
|
+
<ItemGroup>
|
10
|
+
<ProjectReference Include="..\NuGetUpdater.Core\NuGetUpdater.Core.csproj" />
|
11
|
+
</ItemGroup>
|
12
|
+
|
13
|
+
<ItemGroup>
|
14
|
+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
|
15
|
+
<PackageReference Include="xunit" Version="2.4.2" />
|
16
|
+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
|
17
|
+
</ItemGroup>
|
18
|
+
|
19
|
+
<ItemGroup>
|
20
|
+
<Content Include="..\xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
|
21
|
+
</ItemGroup>
|
22
|
+
|
23
|
+
</Project>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
using System;
|
2
|
+
using System.IO;
|
3
|
+
|
4
|
+
namespace NuGetUpdater.Core.Test;
|
5
|
+
|
6
|
+
public sealed class TemporaryDirectory : IDisposable
|
7
|
+
{
|
8
|
+
public string DirectoryPath { get; }
|
9
|
+
|
10
|
+
public TemporaryDirectory()
|
11
|
+
{
|
12
|
+
var parentDir = Path.GetDirectoryName(GetType().Assembly.Location)!;
|
13
|
+
var tempDirName = $"nuget-updater-{Guid.NewGuid():d}";
|
14
|
+
DirectoryPath = Path.Combine(parentDir, "test-data", tempDirName);
|
15
|
+
Directory.CreateDirectory(DirectoryPath);
|
16
|
+
}
|
17
|
+
|
18
|
+
public void Dispose()
|
19
|
+
{
|
20
|
+
Directory.Delete(DirectoryPath, true);
|
21
|
+
}
|
22
|
+
|
23
|
+
public static TemporaryDirectory CreateWithContents(params (string Path, string Contents)[] fileContents)
|
24
|
+
{
|
25
|
+
var temporaryDirectory = new TemporaryDirectory();
|
26
|
+
foreach (var (path, contents) in fileContents)
|
27
|
+
{
|
28
|
+
var fullPath = Path.Combine(temporaryDirectory.DirectoryPath, path);
|
29
|
+
var fullDirectory = Path.GetDirectoryName(fullPath)!;
|
30
|
+
Directory.CreateDirectory(fullDirectory);
|
31
|
+
File.WriteAllText(fullPath, contents);
|
32
|
+
}
|
33
|
+
|
34
|
+
return temporaryDirectory;
|
35
|
+
}
|
36
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
using System.Collections.Generic;
|
2
|
+
using System.Linq;
|
3
|
+
using System.Xml.Linq;
|
4
|
+
|
5
|
+
using Microsoft.Language.Xml;
|
6
|
+
|
7
|
+
namespace NuGetUpdater.Core.Test;
|
8
|
+
|
9
|
+
static class TestExtensions
|
10
|
+
{
|
11
|
+
public static XElement ToXElement(this IXmlElementSyntax xml) => XElement.Parse(xml.ToFullString());
|
12
|
+
|
13
|
+
public static Dictionary<string, XElement> ToXElementDictionary(this Dictionary<string, IXmlElementSyntax> dictionary)
|
14
|
+
=> dictionary.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.ToXElement());
|
15
|
+
}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
using System.Collections.Generic;
|
2
|
+
|
3
|
+
using Xunit;
|
4
|
+
|
5
|
+
namespace NuGetUpdater.Core.Test.Update;
|
6
|
+
|
7
|
+
public class PackagesConfigUpdaterTests
|
8
|
+
{
|
9
|
+
public PackagesConfigUpdaterTests()
|
10
|
+
{
|
11
|
+
MSBuildHelper.RegisterMSBuild();
|
12
|
+
}
|
13
|
+
|
14
|
+
[Theory]
|
15
|
+
[MemberData(nameof(PackagesDirectoryPathTestData))]
|
16
|
+
public void PathToPackagesDirectoryCanBeDetermined(string projectContents, string dependencyName, string dependencyVersion, string expectedPackagesDirectoryPath)
|
17
|
+
{
|
18
|
+
var projectBuildFile = ProjectBuildFile.Parse("/", "project.csproj", projectContents);
|
19
|
+
var actualPackagesDirectorypath = PackagesConfigUpdater.GetPathToPackagesDirectory(projectBuildFile, dependencyName, dependencyVersion);
|
20
|
+
Assert.Equal(expectedPackagesDirectoryPath, actualPackagesDirectorypath);
|
21
|
+
}
|
22
|
+
|
23
|
+
public static IEnumerable<object[]> PackagesDirectoryPathTestData()
|
24
|
+
{
|
25
|
+
// project with namespace
|
26
|
+
yield return new object[]
|
27
|
+
{
|
28
|
+
"""
|
29
|
+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
30
|
+
<ItemGroup>
|
31
|
+
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
|
32
|
+
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
33
|
+
<Private>True</Private>
|
34
|
+
</Reference>
|
35
|
+
</ItemGroup>
|
36
|
+
</Project>
|
37
|
+
""",
|
38
|
+
"Newtonsoft.Json",
|
39
|
+
"7.0.1",
|
40
|
+
@"..\packages"
|
41
|
+
};
|
42
|
+
|
43
|
+
// project without namespace
|
44
|
+
yield return new object[]
|
45
|
+
{
|
46
|
+
"""
|
47
|
+
<Project>
|
48
|
+
<ItemGroup>
|
49
|
+
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
|
50
|
+
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
51
|
+
<Private>True</Private>
|
52
|
+
</Reference>
|
53
|
+
</ItemGroup>
|
54
|
+
</Project>
|
55
|
+
""",
|
56
|
+
"Newtonsoft.Json",
|
57
|
+
"7.0.1",
|
58
|
+
@"..\packages"
|
59
|
+
};
|
60
|
+
|
61
|
+
// project with non-standard packages path
|
62
|
+
yield return new object[]
|
63
|
+
{
|
64
|
+
"""
|
65
|
+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
66
|
+
<ItemGroup>
|
67
|
+
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
|
68
|
+
<HintPath>..\not-a-path-you-would-expect\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
69
|
+
<Private>True</Private>
|
70
|
+
</Reference>
|
71
|
+
</ItemGroup>
|
72
|
+
</Project>
|
73
|
+
""",
|
74
|
+
"Newtonsoft.Json",
|
75
|
+
"7.0.1",
|
76
|
+
@"..\not-a-path-you-would-expect"
|
77
|
+
};
|
78
|
+
}
|
79
|
+
}
|
@@ -0,0 +1,201 @@
|
|
1
|
+
using System;
|
2
|
+
using System.IO;
|
3
|
+
using System.Linq;
|
4
|
+
using System.Threading.Tasks;
|
5
|
+
|
6
|
+
using Xunit;
|
7
|
+
|
8
|
+
namespace NuGetUpdater.Core.Test.Update;
|
9
|
+
|
10
|
+
public partial class UpdateWorkerTests
|
11
|
+
{
|
12
|
+
public class DirsProj : UpdateWorkerTestBase
|
13
|
+
{
|
14
|
+
public DirsProj()
|
15
|
+
{
|
16
|
+
MSBuildHelper.RegisterMSBuild();
|
17
|
+
}
|
18
|
+
|
19
|
+
[Fact]
|
20
|
+
public async Task UpdateSingleDependencyInDirsProj()
|
21
|
+
{
|
22
|
+
await TestUpdateForDirsProj("Newtonsoft.Json", "9.0.1", "13.0.1",
|
23
|
+
// initial
|
24
|
+
projectContents: """
|
25
|
+
<Project Sdk="Microsoft.Build.NoTargets">
|
26
|
+
|
27
|
+
<ItemGroup>
|
28
|
+
<ProjectReference Include="src/test-project.csproj" />
|
29
|
+
</ItemGroup>
|
30
|
+
|
31
|
+
</Project>
|
32
|
+
""",
|
33
|
+
additionalFiles: new (string Path, string Content)[]
|
34
|
+
{
|
35
|
+
("src/test-project.csproj",
|
36
|
+
"""
|
37
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
38
|
+
<PropertyGroup>
|
39
|
+
<TargetFramework>netstandard2.0</TargetFramework>
|
40
|
+
</PropertyGroup>
|
41
|
+
|
42
|
+
<ItemGroup>
|
43
|
+
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
|
44
|
+
</ItemGroup>
|
45
|
+
</Project>
|
46
|
+
""")
|
47
|
+
},
|
48
|
+
// expected
|
49
|
+
expectedProjectContents: """
|
50
|
+
<Project Sdk="Microsoft.Build.NoTargets">
|
51
|
+
|
52
|
+
<ItemGroup>
|
53
|
+
<ProjectReference Include="src/test-project.csproj" />
|
54
|
+
</ItemGroup>
|
55
|
+
|
56
|
+
</Project>
|
57
|
+
""",
|
58
|
+
additionalFilesExpected: new (string Path, string Content)[]
|
59
|
+
{
|
60
|
+
("src/test-project.csproj",
|
61
|
+
"""
|
62
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
63
|
+
<PropertyGroup>
|
64
|
+
<TargetFramework>netstandard2.0</TargetFramework>
|
65
|
+
</PropertyGroup>
|
66
|
+
|
67
|
+
<ItemGroup>
|
68
|
+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
69
|
+
</ItemGroup>
|
70
|
+
</Project>
|
71
|
+
""")
|
72
|
+
});
|
73
|
+
}
|
74
|
+
|
75
|
+
[Fact]
|
76
|
+
public async Task Update_MissingFileDoesNotThrow()
|
77
|
+
{
|
78
|
+
await TestUpdateForDirsProj("Newtonsoft.Json", "9.0.1", "13.0.1",
|
79
|
+
projectContents: """
|
80
|
+
<Project Sdk="Microsoft.Build.Traversal">
|
81
|
+
<ItemGroup>
|
82
|
+
<ProjectReference Include="private\dirs.proj" />
|
83
|
+
</ItemGroup>
|
84
|
+
</Project>
|
85
|
+
""",
|
86
|
+
expectedProjectContents: """
|
87
|
+
<Project Sdk="Microsoft.Build.Traversal">
|
88
|
+
<ItemGroup>
|
89
|
+
<ProjectReference Include="private\dirs.proj" />
|
90
|
+
</ItemGroup>
|
91
|
+
</Project>
|
92
|
+
""",
|
93
|
+
additionalFiles: []);
|
94
|
+
}
|
95
|
+
|
96
|
+
[Fact]
|
97
|
+
public async Task UpdateSingleDependencyInNestedDirsProj()
|
98
|
+
{
|
99
|
+
await TestUpdateForDirsProj("Newtonsoft.Json", "9.0.1", "13.0.1",
|
100
|
+
// initial
|
101
|
+
projectContents: """
|
102
|
+
<Project Sdk="Microsoft.Build.NoTargets">
|
103
|
+
|
104
|
+
<ItemGroup>
|
105
|
+
<ProjectReference Include="src/dirs.proj" />
|
106
|
+
</ItemGroup>
|
107
|
+
|
108
|
+
</Project>
|
109
|
+
""",
|
110
|
+
additionalFiles: new (string Path, string Content)[]
|
111
|
+
{
|
112
|
+
("src/dirs.proj",
|
113
|
+
"""
|
114
|
+
<Project Sdk="Microsoft.Build.NoTargets">
|
115
|
+
|
116
|
+
<ItemGroup>
|
117
|
+
<ProjectReference Include="test-project/test-project.csproj" />
|
118
|
+
</ItemGroup>
|
119
|
+
|
120
|
+
</Project>
|
121
|
+
"""),
|
122
|
+
("src/test-project/test-project.csproj",
|
123
|
+
"""
|
124
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
125
|
+
<PropertyGroup>
|
126
|
+
<TargetFramework>netstandard2.0</TargetFramework>
|
127
|
+
</PropertyGroup>
|
128
|
+
|
129
|
+
<ItemGroup>
|
130
|
+
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
|
131
|
+
</ItemGroup>
|
132
|
+
</Project>
|
133
|
+
""")
|
134
|
+
},
|
135
|
+
// expected
|
136
|
+
expectedProjectContents: """
|
137
|
+
<Project Sdk="Microsoft.Build.NoTargets">
|
138
|
+
|
139
|
+
<ItemGroup>
|
140
|
+
<ProjectReference Include="src/dirs.proj" />
|
141
|
+
</ItemGroup>
|
142
|
+
|
143
|
+
</Project>
|
144
|
+
""",
|
145
|
+
additionalFilesExpected: new (string Path, string Content)[]
|
146
|
+
{
|
147
|
+
("src/dirs.proj",
|
148
|
+
"""
|
149
|
+
<Project Sdk="Microsoft.Build.NoTargets">
|
150
|
+
|
151
|
+
<ItemGroup>
|
152
|
+
<ProjectReference Include="test-project/test-project.csproj" />
|
153
|
+
</ItemGroup>
|
154
|
+
|
155
|
+
</Project>
|
156
|
+
"""),
|
157
|
+
("src/test-project/test-project.csproj",
|
158
|
+
"""
|
159
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
160
|
+
<PropertyGroup>
|
161
|
+
<TargetFramework>netstandard2.0</TargetFramework>
|
162
|
+
</PropertyGroup>
|
163
|
+
|
164
|
+
<ItemGroup>
|
165
|
+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
166
|
+
</ItemGroup>
|
167
|
+
</Project>
|
168
|
+
""")
|
169
|
+
});
|
170
|
+
}
|
171
|
+
|
172
|
+
static async Task TestUpdateForDirsProj(
|
173
|
+
string dependencyName,
|
174
|
+
string oldVersion,
|
175
|
+
string newVersion,
|
176
|
+
string projectContents,
|
177
|
+
string expectedProjectContents,
|
178
|
+
bool isTransitive = false,
|
179
|
+
(string Path, string Content)[]? additionalFiles = null,
|
180
|
+
(string Path, string Content)[]? additionalFilesExpected = null)
|
181
|
+
{
|
182
|
+
additionalFiles ??= Array.Empty<(string Path, string Content)>();
|
183
|
+
additionalFilesExpected ??= Array.Empty<(string Path, string Content)>();
|
184
|
+
|
185
|
+
var projectName = "dirs";
|
186
|
+
var projectFileName = $"{projectName}.proj";
|
187
|
+
var testFiles = additionalFiles.Prepend((projectFileName, projectContents)).ToArray();
|
188
|
+
|
189
|
+
var actualResult = await RunUpdate(testFiles, async (temporaryDirectory) =>
|
190
|
+
{
|
191
|
+
var projectPath = Path.Combine(temporaryDirectory, projectFileName);
|
192
|
+
var worker = new UpdaterWorker(new Logger(verbose: true));
|
193
|
+
await worker.RunAsync(temporaryDirectory, projectPath, dependencyName, oldVersion, newVersion, isTransitive);
|
194
|
+
});
|
195
|
+
|
196
|
+
var expectedResult = additionalFilesExpected.Prepend((projectFileName, expectedProjectContents)).ToArray();
|
197
|
+
|
198
|
+
AssertContainsFiles(expectedResult, actualResult);
|
199
|
+
}
|
200
|
+
}
|
201
|
+
}
|