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
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
|
+
}
|
@@ -0,0 +1,147 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Collections.Generic;
|
3
|
+
using System.IO;
|
4
|
+
using System.Linq;
|
5
|
+
using System.Threading.Tasks;
|
6
|
+
|
7
|
+
using Xunit;
|
8
|
+
|
9
|
+
namespace NuGetUpdater.Core.Test.Update;
|
10
|
+
|
11
|
+
public abstract class UpdateWorkerTestBase
|
12
|
+
{
|
13
|
+
protected static Task TestNoChangeforProject(
|
14
|
+
string dependencyName,
|
15
|
+
string oldVersion,
|
16
|
+
string newVersion,
|
17
|
+
string projectContents,
|
18
|
+
bool isTransitive = false,
|
19
|
+
(string Path, string Content)[]? additionalFiles = null,
|
20
|
+
string projectFilePath = "test-project.csproj")
|
21
|
+
=> TestUpdateForProject(dependencyName, oldVersion, newVersion, (projectFilePath, projectContents), expectedProjectContents: projectContents, isTransitive, additionalFiles, additionalFilesExpected: additionalFiles);
|
22
|
+
|
23
|
+
protected static Task TestUpdateForProject(
|
24
|
+
string dependencyName,
|
25
|
+
string oldVersion,
|
26
|
+
string newVersion,
|
27
|
+
string projectContents,
|
28
|
+
string expectedProjectContents,
|
29
|
+
bool isTransitive = false,
|
30
|
+
(string Path, string Content)[]? additionalFiles = null,
|
31
|
+
(string Path, string Content)[]? additionalFilesExpected = null,
|
32
|
+
string projectFilePath = "test-project.csproj")
|
33
|
+
{
|
34
|
+
var projectFile = (Path: projectFilePath, Content: projectContents);
|
35
|
+
return TestUpdateForProject(dependencyName, oldVersion, newVersion, projectFile, expectedProjectContents, isTransitive, additionalFiles, additionalFilesExpected);
|
36
|
+
}
|
37
|
+
|
38
|
+
protected static async Task TestUpdateForProject(
|
39
|
+
string dependencyName,
|
40
|
+
string oldVersion,
|
41
|
+
string newVersion,
|
42
|
+
(string Path, string Content) projectFile,
|
43
|
+
string expectedProjectContents,
|
44
|
+
bool isTransitive = false,
|
45
|
+
(string Path, string Content)[]? additionalFiles = null,
|
46
|
+
(string Path, string Content)[]? additionalFilesExpected = null)
|
47
|
+
{
|
48
|
+
additionalFiles ??= Array.Empty<(string Path, string Content)>();
|
49
|
+
additionalFilesExpected ??= Array.Empty<(string Path, string Content)>();
|
50
|
+
|
51
|
+
var projectFilePath = projectFile.Path;
|
52
|
+
var projectName = Path.GetFileNameWithoutExtension(projectFilePath);
|
53
|
+
var slnName = "test-solution.sln";
|
54
|
+
var slnContent = $$"""
|
55
|
+
Microsoft Visual Studio Solution File, Format Version 12.00
|
56
|
+
# Visual Studio 14
|
57
|
+
VisualStudioVersion = 14.0.22705.0
|
58
|
+
MinimumVisualStudioVersion = 10.0.40219.1
|
59
|
+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "{{projectName}}", "{{projectFilePath}}", "{782E0C0A-10D3-444D-9640-263D03D2B20C}"
|
60
|
+
EndProject
|
61
|
+
Global
|
62
|
+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
63
|
+
Debug|Any CPU = Debug|Any CPU
|
64
|
+
Release|Any CPU = Release|Any CPU
|
65
|
+
EndGlobalSection
|
66
|
+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
67
|
+
{782E0C0A-10D3-444D-9640-263D03D2B20C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
68
|
+
{782E0C0A-10D3-444D-9640-263D03D2B20C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
69
|
+
{782E0C0A-10D3-444D-9640-263D03D2B20C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
70
|
+
{782E0C0A-10D3-444D-9640-263D03D2B20C}.Release|Any CPU.Build.0 = Release|Any CPU
|
71
|
+
EndGlobalSection
|
72
|
+
GlobalSection(SolutionProperties) = preSolution
|
73
|
+
HideSolutionNode = FALSE
|
74
|
+
EndGlobalSection
|
75
|
+
EndGlobal
|
76
|
+
""";
|
77
|
+
var testFiles = new[] { (slnName, slnContent), projectFile }.Concat(additionalFiles).ToArray();
|
78
|
+
|
79
|
+
var actualResult = await RunUpdate(testFiles, async (temporaryDirectory) =>
|
80
|
+
{
|
81
|
+
var slnPath = Path.Combine(temporaryDirectory, slnName);
|
82
|
+
var worker = new UpdaterWorker(new Logger(verbose: true));
|
83
|
+
await worker.RunAsync(temporaryDirectory, slnPath, dependencyName, oldVersion, newVersion, isTransitive);
|
84
|
+
});
|
85
|
+
|
86
|
+
var expectedResult = additionalFilesExpected.Prepend((projectFilePath, expectedProjectContents)).ToArray();
|
87
|
+
|
88
|
+
AssertContainsFiles(expectedResult, actualResult);
|
89
|
+
}
|
90
|
+
|
91
|
+
protected static async Task<(string Path, string Content)[]> RunUpdate((string Path, string Content)[] files, Func<string, Task> action)
|
92
|
+
{
|
93
|
+
// write initial files
|
94
|
+
using var tempDir = new TemporaryDirectory();
|
95
|
+
foreach (var file in files)
|
96
|
+
{
|
97
|
+
var localPath = file.Path.StartsWith("/") ? file.Path[1..] : file.Path; // remove path rooting character
|
98
|
+
var filePath = Path.Combine(tempDir.DirectoryPath, localPath);
|
99
|
+
var directoryPath = Path.GetDirectoryName(filePath);
|
100
|
+
Directory.CreateDirectory(directoryPath!);
|
101
|
+
await File.WriteAllTextAsync(filePath, file.Content);
|
102
|
+
}
|
103
|
+
|
104
|
+
// run update
|
105
|
+
await action(tempDir.DirectoryPath);
|
106
|
+
|
107
|
+
// gather results
|
108
|
+
var expectedFiles = new HashSet<string>(files.Select(f => f.Path));
|
109
|
+
var result = new List<(string Path, string Content)>();
|
110
|
+
foreach (var file in Directory.GetFiles(tempDir.DirectoryPath, "*.*", SearchOption.AllDirectories))
|
111
|
+
{
|
112
|
+
var localPath = file.StartsWith(tempDir.DirectoryPath)
|
113
|
+
? file[tempDir.DirectoryPath.Length..]
|
114
|
+
: file; // how did this happen?
|
115
|
+
localPath = localPath.NormalizePathToUnix();
|
116
|
+
if (localPath.StartsWith('/'))
|
117
|
+
{
|
118
|
+
localPath = localPath[1..];
|
119
|
+
}
|
120
|
+
|
121
|
+
if (expectedFiles.Contains(localPath))
|
122
|
+
{
|
123
|
+
var content = await File.ReadAllTextAsync(file);
|
124
|
+
result.Add((localPath, content));
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
return result.ToArray();
|
129
|
+
}
|
130
|
+
|
131
|
+
protected static void AssertEqualFiles((string Path, string Content)[] expected, (string Path, string Content)[] actual)
|
132
|
+
{
|
133
|
+
Assert.Equal(expected.Length, actual.Length);
|
134
|
+
AssertContainsFiles(expected, actual);
|
135
|
+
}
|
136
|
+
|
137
|
+
protected static void AssertContainsFiles((string Path, string Content)[] expected, (string Path, string Content)[] actual)
|
138
|
+
{
|
139
|
+
var actualContents = actual.ToDictionary(pair => pair.Path, pair => pair.Content);
|
140
|
+
foreach (var expectedPair in expected)
|
141
|
+
{
|
142
|
+
var actualContent = actualContents[expectedPair.Path];
|
143
|
+
var expectedContent = expectedPair.Content;
|
144
|
+
Assert.Equal(expectedContent.Replace("\r", ""), actualContent.Replace("\r", "")); // normalize line endings
|
145
|
+
}
|
146
|
+
}
|
147
|
+
}
|