dependabot-nuget 0.285.0 → 0.287.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/lib/NuGetUpdater/NuGetProjects/Directory.Build.props +5 -1
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.CommandLine/NuGet.CommandLine.csproj +1 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Configuration/NuGet.Configuration.csproj +1 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.LibraryModel/NuGet.LibraryModel.csproj +1 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Packaging/NuGet.Packaging.csproj +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/RunCommand.cs +8 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/UpdateCommand.cs +7 -3
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Update.cs +11 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/AnalyzeWorker.cs +2 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/CompatabilityChecker.cs +24 -5
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/NuGetContext.cs +15 -4
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/VersionFinder.cs +9 -38
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DiscoveryWorker.cs +10 -8
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/ExperimentsManager.cs +52 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/ProjectBuildFile.cs +15 -8
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/IAnalyzeWorker.cs +9 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/IDiscoveryWorker.cs +8 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/IUpdaterWorker.cs +9 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +78 -61
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs +21 -10
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackagesConfigUpdater.cs +37 -5
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +5 -3
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +5 -6
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/PathHelper.cs +51 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/AnalyzeWorkerTests.cs +302 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.cs +269 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs +577 -43
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/SerializationTests.cs +168 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestAnalyzeWorker.cs +37 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestDiscoveryWorker.cs +35 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestUpdaterWorker.cs +39 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackagesConfigUpdaterTests.cs +104 -3
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +51 -13
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DirsProj.cs +4 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackageReference.cs +62 -18
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/PathHelperTests.cs +14 -0
- data/helpers/lib/NuGetUpdater/global.json +1 -1
- data/lib/dependabot/nuget/file_updater.rb +8 -3
- data/lib/dependabot/nuget/native_helpers.rb +11 -12
- metadata +12 -6
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/DependencySolverEnvironment.cs +0 -12
@@ -59,6 +59,162 @@ public class SerializationTests
|
|
59
59
|
Assert.Equal("specific-sdk", jobWrapper.Job.Source.Directory);
|
60
60
|
}
|
61
61
|
|
62
|
+
[Fact]
|
63
|
+
public void DeserializeJob_FieldsNotYetSupported()
|
64
|
+
{
|
65
|
+
// the `source` field is required in the C# model; the remaining fields might exist in the JSON file, but are
|
66
|
+
// not yet supported in the C# model (some keys missing, others deserialize to `object?`; deserialization
|
67
|
+
// should not fail
|
68
|
+
var jobWrapper = RunWorker.Deserialize("""
|
69
|
+
{
|
70
|
+
"job": {
|
71
|
+
"source": {
|
72
|
+
"provider": "github",
|
73
|
+
"repo": "some-org/some-repo",
|
74
|
+
"directory": "specific-sdk",
|
75
|
+
"hostname": null,
|
76
|
+
"api-endpoint": null
|
77
|
+
},
|
78
|
+
"id": "some-id",
|
79
|
+
"allowed-updates": [
|
80
|
+
{
|
81
|
+
"dependency-type": "direct",
|
82
|
+
"update-type": "all"
|
83
|
+
}
|
84
|
+
],
|
85
|
+
"credentials": [
|
86
|
+
{
|
87
|
+
"name": "some-cred",
|
88
|
+
"token": "abc123"
|
89
|
+
}
|
90
|
+
],
|
91
|
+
"existing-pull-requests": [
|
92
|
+
[
|
93
|
+
{
|
94
|
+
"dependency-name": "Some.Package",
|
95
|
+
"dependency-version": "1.2.3"
|
96
|
+
}
|
97
|
+
]
|
98
|
+
],
|
99
|
+
"repo-contents-path": "/path/to/repo",
|
100
|
+
"token": "abc123"
|
101
|
+
}
|
102
|
+
}
|
103
|
+
""");
|
104
|
+
Assert.Equal("github", jobWrapper.Job.Source.Provider);
|
105
|
+
Assert.Equal("some-org/some-repo", jobWrapper.Job.Source.Repo);
|
106
|
+
Assert.Equal("specific-sdk", jobWrapper.Job.Source.Directory);
|
107
|
+
}
|
108
|
+
|
109
|
+
[Fact]
|
110
|
+
public void DeserializeExperimentsManager()
|
111
|
+
{
|
112
|
+
var jobWrapper = RunWorker.Deserialize("""
|
113
|
+
{
|
114
|
+
"job": {
|
115
|
+
"package-manager": "nuget",
|
116
|
+
"allowed-updates": [
|
117
|
+
{
|
118
|
+
"update-type": "all"
|
119
|
+
}
|
120
|
+
],
|
121
|
+
"source": {
|
122
|
+
"provider": "github",
|
123
|
+
"repo": "some-org/some-repo",
|
124
|
+
"directory": "some-dir"
|
125
|
+
},
|
126
|
+
"experiments": {
|
127
|
+
"nuget_legacy_dependency_solver": true,
|
128
|
+
"unexpected_bool": true,
|
129
|
+
"unexpected_number": 42,
|
130
|
+
"unexpected_null": null,
|
131
|
+
"unexpected_string": "abc",
|
132
|
+
"unexpected_array": [1, "two", 3.0],
|
133
|
+
"unexpected_object": {
|
134
|
+
"a": 1,
|
135
|
+
"b": "two"
|
136
|
+
}
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
""");
|
141
|
+
var experimentsManager = ExperimentsManager.GetExperimentsManager(jobWrapper.Job.Experiments);
|
142
|
+
Assert.True(experimentsManager.UseLegacyDependencySolver);
|
143
|
+
}
|
144
|
+
|
145
|
+
[Fact]
|
146
|
+
public void DeserializeExperimentsManager_EmptyExperiments()
|
147
|
+
{
|
148
|
+
var jobWrapper = RunWorker.Deserialize("""
|
149
|
+
{
|
150
|
+
"job": {
|
151
|
+
"package-manager": "nuget",
|
152
|
+
"allowed-updates": [
|
153
|
+
{
|
154
|
+
"update-type": "all"
|
155
|
+
}
|
156
|
+
],
|
157
|
+
"source": {
|
158
|
+
"provider": "github",
|
159
|
+
"repo": "some-org/some-repo",
|
160
|
+
"directory": "some-dir"
|
161
|
+
},
|
162
|
+
"experiments": {
|
163
|
+
}
|
164
|
+
}
|
165
|
+
}
|
166
|
+
""");
|
167
|
+
var experimentsManager = ExperimentsManager.GetExperimentsManager(jobWrapper.Job.Experiments);
|
168
|
+
Assert.False(experimentsManager.UseLegacyDependencySolver);
|
169
|
+
}
|
170
|
+
|
171
|
+
[Fact]
|
172
|
+
public void DeserializeExperimentsManager_NoExperiments()
|
173
|
+
{
|
174
|
+
var jobWrapper = RunWorker.Deserialize("""
|
175
|
+
{
|
176
|
+
"job": {
|
177
|
+
"package-manager": "nuget",
|
178
|
+
"allowed-updates": [
|
179
|
+
{
|
180
|
+
"update-type": "all"
|
181
|
+
}
|
182
|
+
],
|
183
|
+
"source": {
|
184
|
+
"provider": "github",
|
185
|
+
"repo": "some-org/some-repo",
|
186
|
+
"directory": "some-dir"
|
187
|
+
}
|
188
|
+
}
|
189
|
+
}
|
190
|
+
""");
|
191
|
+
var experimentsManager = ExperimentsManager.GetExperimentsManager(jobWrapper.Job.Experiments);
|
192
|
+
Assert.False(experimentsManager.UseLegacyDependencySolver);
|
193
|
+
}
|
194
|
+
|
195
|
+
[Fact]
|
196
|
+
public async Task DeserializeExperimentsManager_UnsupportedJobFileShape_InfoIsReportedAndEmptyExperimentSetIsReturned()
|
197
|
+
{
|
198
|
+
// arrange
|
199
|
+
using var tempDir = new TemporaryDirectory();
|
200
|
+
var jobFilePath = Path.Combine(tempDir.DirectoryPath, "job.json");
|
201
|
+
var jobContent = """
|
202
|
+
{
|
203
|
+
"this-is-not-a-job-and-parsing-will-fail-but-an-empty-experiment-set-should-sill-be-returned": {
|
204
|
+
}
|
205
|
+
}
|
206
|
+
""";
|
207
|
+
await File.WriteAllTextAsync(jobFilePath, jobContent);
|
208
|
+
var capturingTestLogger = new CapturingTestLogger();
|
209
|
+
|
210
|
+
// act - this is the entrypoint the update command uses to parse the job file
|
211
|
+
var experimentsManager = await ExperimentsManager.FromJobFileAsync(jobFilePath, capturingTestLogger);
|
212
|
+
|
213
|
+
// assert
|
214
|
+
Assert.False(experimentsManager.UseLegacyDependencySolver);
|
215
|
+
Assert.Single(capturingTestLogger.Messages.Where(m => m.Contains("Error deserializing job file")));
|
216
|
+
}
|
217
|
+
|
62
218
|
[Fact]
|
63
219
|
public void SerializeError()
|
64
220
|
{
|
@@ -67,4 +223,16 @@ public class SerializationTests
|
|
67
223
|
var expected = """{"data":{"error-type":"job_repo_not_found","error-details":{"message":"some message"}}}""";
|
68
224
|
Assert.Equal(expected, actual);
|
69
225
|
}
|
226
|
+
|
227
|
+
private class CapturingTestLogger : ILogger
|
228
|
+
{
|
229
|
+
private readonly List<string> _messages = new();
|
230
|
+
|
231
|
+
public IReadOnlyList<string> Messages => _messages;
|
232
|
+
|
233
|
+
public void Log(string message)
|
234
|
+
{
|
235
|
+
_messages.Add(message);
|
236
|
+
}
|
237
|
+
}
|
70
238
|
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
using NuGetUpdater.Core.Analyze;
|
2
|
+
using NuGetUpdater.Core.Discover;
|
3
|
+
|
4
|
+
namespace NuGetUpdater.Core.Test;
|
5
|
+
|
6
|
+
internal class TestAnalyzeWorker : IAnalyzeWorker
|
7
|
+
{
|
8
|
+
private readonly Func<(string, WorkspaceDiscoveryResult, DependencyInfo), Task<AnalysisResult>> _getResult;
|
9
|
+
|
10
|
+
public TestAnalyzeWorker(Func<(string, WorkspaceDiscoveryResult, DependencyInfo), Task<AnalysisResult>> getResult)
|
11
|
+
{
|
12
|
+
_getResult = getResult;
|
13
|
+
}
|
14
|
+
|
15
|
+
public Task<AnalysisResult> RunAsync(string repoRoot, WorkspaceDiscoveryResult discovery, DependencyInfo dependencyInfo)
|
16
|
+
{
|
17
|
+
return _getResult((repoRoot, discovery, dependencyInfo));
|
18
|
+
}
|
19
|
+
|
20
|
+
public static TestAnalyzeWorker FromResults(params (string RepoRoot, WorkspaceDiscoveryResult Discovery, DependencyInfo DependencyInfo, AnalysisResult Result)[] results)
|
21
|
+
{
|
22
|
+
return new TestAnalyzeWorker(((string RepoRoot, WorkspaceDiscoveryResult Discovery, DependencyInfo DependencyInfo) input) =>
|
23
|
+
{
|
24
|
+
foreach (var set in results)
|
25
|
+
{
|
26
|
+
if (set.RepoRoot == input.RepoRoot &&
|
27
|
+
set.Discovery == input.Discovery &&
|
28
|
+
set.DependencyInfo == input.DependencyInfo)
|
29
|
+
{
|
30
|
+
return Task.FromResult(set.Result);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
throw new NotImplementedException($"No saved response for {input}");
|
35
|
+
});
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
using NuGetUpdater.Core.Discover;
|
2
|
+
|
3
|
+
namespace NuGetUpdater.Core.Test;
|
4
|
+
|
5
|
+
internal class TestDiscoveryWorker : IDiscoveryWorker
|
6
|
+
{
|
7
|
+
private readonly Func<(string, string), Task<WorkspaceDiscoveryResult>> _getResult;
|
8
|
+
|
9
|
+
public TestDiscoveryWorker(Func<(string, string), Task<WorkspaceDiscoveryResult>> getResult)
|
10
|
+
{
|
11
|
+
_getResult = getResult;
|
12
|
+
}
|
13
|
+
|
14
|
+
public Task<WorkspaceDiscoveryResult> RunAsync(string repoRootPath, string workspacePath)
|
15
|
+
{
|
16
|
+
return _getResult((repoRootPath, workspacePath));
|
17
|
+
}
|
18
|
+
|
19
|
+
public static TestDiscoveryWorker FromResults(params (string RepoRootPath, string WorkspacePath, WorkspaceDiscoveryResult Result)[] results)
|
20
|
+
{
|
21
|
+
return new TestDiscoveryWorker(((string RepoRootPath, string WorkspacePath) input) =>
|
22
|
+
{
|
23
|
+
foreach (var set in results)
|
24
|
+
{
|
25
|
+
if (set.RepoRootPath == input.RepoRootPath &&
|
26
|
+
set.WorkspacePath == input.WorkspacePath)
|
27
|
+
{
|
28
|
+
return Task.FromResult(set.Result);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
throw new NotImplementedException($"No saved response for {input}");
|
33
|
+
});
|
34
|
+
}
|
35
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
using NuGetUpdater.Core.Updater;
|
2
|
+
|
3
|
+
namespace NuGetUpdater.Core.Test;
|
4
|
+
|
5
|
+
internal class TestUpdaterWorker : IUpdaterWorker
|
6
|
+
{
|
7
|
+
private readonly Func<(string, string, string, string, string, bool), Task<UpdateOperationResult>> _getResult;
|
8
|
+
|
9
|
+
public TestUpdaterWorker(Func<(string, string, string, string, string, bool), Task<UpdateOperationResult>> getResult)
|
10
|
+
{
|
11
|
+
_getResult = getResult;
|
12
|
+
}
|
13
|
+
|
14
|
+
public Task<UpdateOperationResult> RunAsync(string repoRootPath, string workspacePath, string dependencyName, string previousDependencyVersion, string newDependencyVersion, bool isTransitive)
|
15
|
+
{
|
16
|
+
return _getResult((repoRootPath, workspacePath, dependencyName, previousDependencyVersion, newDependencyVersion, isTransitive));
|
17
|
+
}
|
18
|
+
|
19
|
+
public static TestUpdaterWorker FromResults(params (string RepoRootPath, string WorkspacePath, string DependencyName, string PreviousDependencyVersion, string NewDependencyVersion, bool IsTransitive, UpdateOperationResult Result)[] results)
|
20
|
+
{
|
21
|
+
return new TestUpdaterWorker(((string RepoRootPath, string WorkspacePath, string DependencyName, string PreviousDependencyVersion, string NewDependencyVersion, bool IsTransitive) input) =>
|
22
|
+
{
|
23
|
+
foreach (var set in results)
|
24
|
+
{
|
25
|
+
if (set.RepoRootPath == input.RepoRootPath &&
|
26
|
+
set.WorkspacePath == input.WorkspacePath &&
|
27
|
+
set.DependencyName == input.DependencyName &&
|
28
|
+
set.PreviousDependencyVersion == input.PreviousDependencyVersion &&
|
29
|
+
set.NewDependencyVersion == input.NewDependencyVersion &&
|
30
|
+
set.IsTransitive == input.IsTransitive)
|
31
|
+
{
|
32
|
+
return Task.FromResult(set.Result);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
throw new NotImplementedException($"No saved response for {input}");
|
37
|
+
});
|
38
|
+
}
|
39
|
+
}
|
@@ -6,18 +6,27 @@ public class PackagesConfigUpdaterTests : TestBase
|
|
6
6
|
{
|
7
7
|
[Theory]
|
8
8
|
[MemberData(nameof(PackagesDirectoryPathTestData))]
|
9
|
-
public
|
9
|
+
public async Task PathToPackagesDirectoryCanBeDetermined(string projectContents, string? packagesConfigContents, string dependencyName, string dependencyVersion, string expectedPackagesDirectoryPath)
|
10
10
|
{
|
11
|
+
using var tempDir = new TemporaryDirectory();
|
12
|
+
string? packagesConfigPath = null;
|
13
|
+
if (packagesConfigContents is not null)
|
14
|
+
{
|
15
|
+
packagesConfigPath = Path.Join(tempDir.DirectoryPath, "packages.config");
|
16
|
+
await File.WriteAllTextAsync(packagesConfigPath, packagesConfigContents);
|
17
|
+
}
|
18
|
+
|
11
19
|
var projectBuildFile = ProjectBuildFile.Parse("/", "project.csproj", projectContents);
|
12
|
-
var actualPackagesDirectorypath = PackagesConfigUpdater.GetPathToPackagesDirectory(projectBuildFile, dependencyName, dependencyVersion,
|
20
|
+
var actualPackagesDirectorypath = PackagesConfigUpdater.GetPathToPackagesDirectory(projectBuildFile, dependencyName, dependencyVersion, packagesConfigPath);
|
13
21
|
Assert.Equal(expectedPackagesDirectoryPath, actualPackagesDirectorypath);
|
14
22
|
}
|
15
23
|
|
16
|
-
public static IEnumerable<object[]> PackagesDirectoryPathTestData()
|
24
|
+
public static IEnumerable<object?[]> PackagesDirectoryPathTestData()
|
17
25
|
{
|
18
26
|
// project with namespace
|
19
27
|
yield return
|
20
28
|
[
|
29
|
+
// project contents
|
21
30
|
"""
|
22
31
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
23
32
|
<ItemGroup>
|
@@ -28,14 +37,20 @@ public class PackagesConfigUpdaterTests : TestBase
|
|
28
37
|
</ItemGroup>
|
29
38
|
</Project>
|
30
39
|
""",
|
40
|
+
// packages.config contents
|
41
|
+
null,
|
42
|
+
// dependency name
|
31
43
|
"Newtonsoft.Json",
|
44
|
+
// dependency version
|
32
45
|
"7.0.1",
|
46
|
+
// expected packages directory path
|
33
47
|
"../packages"
|
34
48
|
];
|
35
49
|
|
36
50
|
// project without namespace
|
37
51
|
yield return
|
38
52
|
[
|
53
|
+
// project contents
|
39
54
|
"""
|
40
55
|
<Project>
|
41
56
|
<ItemGroup>
|
@@ -46,14 +61,20 @@ public class PackagesConfigUpdaterTests : TestBase
|
|
46
61
|
</ItemGroup>
|
47
62
|
</Project>
|
48
63
|
""",
|
64
|
+
// packages.config contents
|
65
|
+
null,
|
66
|
+
// dependency name
|
49
67
|
"Newtonsoft.Json",
|
68
|
+
// dependency version
|
50
69
|
"7.0.1",
|
70
|
+
// expected packages directory path
|
51
71
|
"../packages"
|
52
72
|
];
|
53
73
|
|
54
74
|
// project with non-standard packages path
|
55
75
|
yield return
|
56
76
|
[
|
77
|
+
// project contents
|
57
78
|
"""
|
58
79
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
59
80
|
<ItemGroup>
|
@@ -64,9 +85,89 @@ public class PackagesConfigUpdaterTests : TestBase
|
|
64
85
|
</ItemGroup>
|
65
86
|
</Project>
|
66
87
|
""",
|
88
|
+
// packages.config contents
|
89
|
+
null,
|
90
|
+
// dependency name
|
67
91
|
"Newtonsoft.Json",
|
92
|
+
// dependency version
|
68
93
|
"7.0.1",
|
94
|
+
// expected packages directory path
|
69
95
|
"../not-a-path-you-would-expect"
|
70
96
|
];
|
97
|
+
|
98
|
+
// project without expected packages path, but has others
|
99
|
+
yield return
|
100
|
+
[
|
101
|
+
// project contents
|
102
|
+
"""
|
103
|
+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
104
|
+
<ItemGroup>
|
105
|
+
<Reference Include="Some.Other.Package, Version=1.2.3.4, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
|
106
|
+
<HintPath>..\..\..\still-a-usable-path\Some.Other.Package.1.2.3\lib\net45\Some.Other.Package.dll</HintPath>
|
107
|
+
<Private>True</Private>
|
108
|
+
</Reference>
|
109
|
+
</ItemGroup>
|
110
|
+
</Project>
|
111
|
+
""",
|
112
|
+
// packages.config contents
|
113
|
+
"""
|
114
|
+
<packages>
|
115
|
+
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
|
116
|
+
</packages>
|
117
|
+
""",
|
118
|
+
// dependency name
|
119
|
+
"Newtonsoft.Json",
|
120
|
+
// dependency version
|
121
|
+
"7.0.1",
|
122
|
+
// expected packages directory path
|
123
|
+
"../../../still-a-usable-path"
|
124
|
+
];
|
125
|
+
|
126
|
+
// project without expected package, but exists in packages.config, default is returned
|
127
|
+
yield return
|
128
|
+
[
|
129
|
+
// project contents
|
130
|
+
"""
|
131
|
+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
132
|
+
<ItemGroup>
|
133
|
+
</ItemGroup>
|
134
|
+
</Project>
|
135
|
+
""",
|
136
|
+
// packages.config contents
|
137
|
+
"""
|
138
|
+
<packages>
|
139
|
+
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
|
140
|
+
</packages>
|
141
|
+
""",
|
142
|
+
// dependency name
|
143
|
+
"Newtonsoft.Json",
|
144
|
+
// dependency version
|
145
|
+
"7.0.1",
|
146
|
+
// expected packages directory path
|
147
|
+
"../packages"
|
148
|
+
];
|
149
|
+
|
150
|
+
// project without expected package and not in packages.config
|
151
|
+
yield return
|
152
|
+
[
|
153
|
+
// project contents
|
154
|
+
"""
|
155
|
+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
156
|
+
<ItemGroup>
|
157
|
+
</ItemGroup>
|
158
|
+
</Project>
|
159
|
+
""",
|
160
|
+
// packages.config contents
|
161
|
+
"""
|
162
|
+
<packages>
|
163
|
+
</packages>
|
164
|
+
""",
|
165
|
+
// dependency name
|
166
|
+
"Newtonsoft.Json",
|
167
|
+
// dependency version
|
168
|
+
"7.0.1",
|
169
|
+
// expected packages directory path
|
170
|
+
null
|
171
|
+
];
|
71
172
|
}
|
72
173
|
}
|
@@ -1,3 +1,7 @@
|
|
1
|
+
using System.Text.Json;
|
2
|
+
|
3
|
+
using NuGetUpdater.Core.Run;
|
4
|
+
using NuGetUpdater.Core.Run.ApiModel;
|
1
5
|
using NuGetUpdater.Core.Test.Updater;
|
2
6
|
using NuGetUpdater.Core.Updater;
|
3
7
|
|
@@ -19,11 +23,12 @@ public abstract class UpdateWorkerTestBase : TestBase
|
|
19
23
|
bool isTransitive = false,
|
20
24
|
TestFile[]? additionalFiles = null,
|
21
25
|
MockNuGetPackage[]? packages = null,
|
26
|
+
ExperimentsManager? experimentsManager = null,
|
22
27
|
string projectFilePath = "test-project.csproj")
|
23
28
|
{
|
24
29
|
return useSolution
|
25
|
-
? TestNoChangeforSolution(dependencyName, oldVersion, newVersion, projectFiles: [(projectFilePath, projectContents)], isTransitive, additionalFiles, packages)
|
26
|
-
: TestNoChangeforProject(dependencyName, oldVersion, newVersion, projectContents, isTransitive, additionalFiles, packages, projectFilePath);
|
30
|
+
? TestNoChangeforSolution(dependencyName, oldVersion, newVersion, projectFiles: [(projectFilePath, projectContents)], isTransitive, additionalFiles, packages, experimentsManager)
|
31
|
+
: TestNoChangeforProject(dependencyName, oldVersion, newVersion, projectContents, isTransitive, additionalFiles, packages, experimentsManager, projectFilePath);
|
27
32
|
}
|
28
33
|
|
29
34
|
protected static Task TestUpdate(
|
@@ -37,11 +42,12 @@ public abstract class UpdateWorkerTestBase : TestBase
|
|
37
42
|
TestFile[]? additionalFiles = null,
|
38
43
|
TestFile[]? additionalFilesExpected = null,
|
39
44
|
MockNuGetPackage[]? packages = null,
|
45
|
+
ExperimentsManager? experimentsManager = null,
|
40
46
|
string projectFilePath = "test-project.csproj")
|
41
47
|
{
|
42
48
|
return useSolution
|
43
|
-
? TestUpdateForSolution(dependencyName, oldVersion, newVersion, projectFiles: [(projectFilePath, projectContents)], projectFilesExpected: [(projectFilePath, expectedProjectContents)], isTransitive, additionalFiles, additionalFilesExpected, packages)
|
44
|
-
: TestUpdateForProject(dependencyName, oldVersion, newVersion, projectFile: (projectFilePath, projectContents), expectedProjectContents, isTransitive, additionalFiles, additionalFilesExpected, packages);
|
49
|
+
? TestUpdateForSolution(dependencyName, oldVersion, newVersion, projectFiles: [(projectFilePath, projectContents)], projectFilesExpected: [(projectFilePath, expectedProjectContents)], isTransitive, additionalFiles, additionalFilesExpected, packages, experimentsManager)
|
50
|
+
: TestUpdateForProject(dependencyName, oldVersion, newVersion, projectFile: (projectFilePath, projectContents), expectedProjectContents, isTransitive, additionalFiles, additionalFilesExpected, packages, experimentsManager);
|
45
51
|
}
|
46
52
|
|
47
53
|
protected static Task TestUpdate(
|
@@ -54,11 +60,12 @@ public abstract class UpdateWorkerTestBase : TestBase
|
|
54
60
|
bool isTransitive = false,
|
55
61
|
TestFile[]? additionalFiles = null,
|
56
62
|
TestFile[]? additionalFilesExpected = null,
|
57
|
-
MockNuGetPackage[]? packages = null
|
63
|
+
MockNuGetPackage[]? packages = null,
|
64
|
+
ExperimentsManager? experimentsManager = null)
|
58
65
|
{
|
59
66
|
return useSolution
|
60
|
-
? TestUpdateForSolution(dependencyName, oldVersion, newVersion, projectFiles: [projectFile], projectFilesExpected: [(projectFile.Path, expectedProjectContents)], isTransitive, additionalFiles, additionalFilesExpected, packages)
|
61
|
-
: TestUpdateForProject(dependencyName, oldVersion, newVersion, projectFile, expectedProjectContents, isTransitive, additionalFiles, additionalFilesExpected, packages);
|
67
|
+
? TestUpdateForSolution(dependencyName, oldVersion, newVersion, projectFiles: [projectFile], projectFilesExpected: [(projectFile.Path, expectedProjectContents)], isTransitive, additionalFiles, additionalFilesExpected, packages, experimentsManager)
|
68
|
+
: TestUpdateForProject(dependencyName, oldVersion, newVersion, projectFile, expectedProjectContents, isTransitive, additionalFiles, additionalFilesExpected, packages, experimentsManager);
|
62
69
|
}
|
63
70
|
|
64
71
|
protected static Task TestNoChangeforProject(
|
@@ -69,6 +76,7 @@ public abstract class UpdateWorkerTestBase : TestBase
|
|
69
76
|
bool isTransitive = false,
|
70
77
|
TestFile[]? additionalFiles = null,
|
71
78
|
MockNuGetPackage[]? packages = null,
|
79
|
+
ExperimentsManager? experimentsManager = null,
|
72
80
|
string projectFilePath = "test-project.csproj")
|
73
81
|
=> TestUpdateForProject(
|
74
82
|
dependencyName,
|
@@ -79,7 +87,8 @@ public abstract class UpdateWorkerTestBase : TestBase
|
|
79
87
|
isTransitive,
|
80
88
|
additionalFiles,
|
81
89
|
additionalFilesExpected: additionalFiles,
|
82
|
-
packages: packages
|
90
|
+
packages: packages,
|
91
|
+
experimentsManager: experimentsManager);
|
83
92
|
|
84
93
|
protected static Task TestUpdateForProject(
|
85
94
|
string dependencyName,
|
@@ -91,6 +100,7 @@ public abstract class UpdateWorkerTestBase : TestBase
|
|
91
100
|
TestFile[]? additionalFiles = null,
|
92
101
|
TestFile[]? additionalFilesExpected = null,
|
93
102
|
MockNuGetPackage[]? packages = null,
|
103
|
+
ExperimentsManager? experimentsManager = null,
|
94
104
|
string projectFilePath = "test-project.csproj",
|
95
105
|
ExpectedUpdateOperationResult? expectedResult = null)
|
96
106
|
=> TestUpdateForProject(
|
@@ -103,6 +113,7 @@ public abstract class UpdateWorkerTestBase : TestBase
|
|
103
113
|
additionalFiles,
|
104
114
|
additionalFilesExpected,
|
105
115
|
packages,
|
116
|
+
experimentsManager,
|
106
117
|
expectedResult);
|
107
118
|
|
108
119
|
protected static async Task TestUpdateForProject(
|
@@ -115,6 +126,7 @@ public abstract class UpdateWorkerTestBase : TestBase
|
|
115
126
|
TestFile[]? additionalFiles = null,
|
116
127
|
TestFile[]? additionalFilesExpected = null,
|
117
128
|
MockNuGetPackage[]? packages = null,
|
129
|
+
ExperimentsManager? experimentsManager = null,
|
118
130
|
ExpectedUpdateOperationResult? expectedResult = null)
|
119
131
|
{
|
120
132
|
additionalFiles ??= [];
|
@@ -134,7 +146,8 @@ public abstract class UpdateWorkerTestBase : TestBase
|
|
134
146
|
await MockNuGetPackagesInDirectory(packages, temporaryDirectory);
|
135
147
|
|
136
148
|
// run update
|
137
|
-
|
149
|
+
experimentsManager ??= new ExperimentsManager();
|
150
|
+
var worker = new UpdaterWorker(experimentsManager, new TestLogger());
|
138
151
|
var projectPath = placeFilesInSrc ? $"src/{projectFilePath}" : projectFilePath;
|
139
152
|
var actualResult = await worker.RunWithErrorHandlingAsync(temporaryDirectory, projectPath, dependencyName, oldVersion, newVersion, isTransitive);
|
140
153
|
if (expectedResult is { })
|
@@ -172,7 +185,8 @@ public abstract class UpdateWorkerTestBase : TestBase
|
|
172
185
|
TestFile[] projectFiles,
|
173
186
|
bool isTransitive = false,
|
174
187
|
TestFile[]? additionalFiles = null,
|
175
|
-
MockNuGetPackage[]? packages = null
|
188
|
+
MockNuGetPackage[]? packages = null,
|
189
|
+
ExperimentsManager? experimentsManager = null)
|
176
190
|
=> TestUpdateForSolution(
|
177
191
|
dependencyName,
|
178
192
|
oldVersion,
|
@@ -182,7 +196,8 @@ public abstract class UpdateWorkerTestBase : TestBase
|
|
182
196
|
isTransitive,
|
183
197
|
additionalFiles,
|
184
198
|
additionalFilesExpected: additionalFiles,
|
185
|
-
packages: packages
|
199
|
+
packages: packages,
|
200
|
+
experimentsManager: experimentsManager);
|
186
201
|
|
187
202
|
protected static async Task TestUpdateForSolution(
|
188
203
|
string dependencyName,
|
@@ -193,7 +208,8 @@ public abstract class UpdateWorkerTestBase : TestBase
|
|
193
208
|
bool isTransitive = false,
|
194
209
|
TestFile[]? additionalFiles = null,
|
195
210
|
TestFile[]? additionalFilesExpected = null,
|
196
|
-
MockNuGetPackage[]? packages = null
|
211
|
+
MockNuGetPackage[]? packages = null,
|
212
|
+
ExperimentsManager? experimentsManager = null)
|
197
213
|
{
|
198
214
|
additionalFiles ??= [];
|
199
215
|
additionalFilesExpected ??= [];
|
@@ -236,8 +252,9 @@ public abstract class UpdateWorkerTestBase : TestBase
|
|
236
252
|
{
|
237
253
|
await MockNuGetPackagesInDirectory(packages, temporaryDirectory);
|
238
254
|
|
255
|
+
experimentsManager ??= new ExperimentsManager();
|
239
256
|
var slnPath = Path.Combine(temporaryDirectory, slnName);
|
240
|
-
var worker = new UpdaterWorker(new TestLogger());
|
257
|
+
var worker = new UpdaterWorker(experimentsManager, new TestLogger());
|
241
258
|
await worker.RunAsync(temporaryDirectory, slnPath, dependencyName, oldVersion, newVersion, isTransitive);
|
242
259
|
});
|
243
260
|
|
@@ -246,6 +263,27 @@ public abstract class UpdateWorkerTestBase : TestBase
|
|
246
263
|
AssertContainsFiles(expectedResult, actualResult);
|
247
264
|
}
|
248
265
|
|
266
|
+
public static async Task MockJobFileInDirectory(string temporaryDirectory)
|
267
|
+
{
|
268
|
+
var jobFile = new JobFile()
|
269
|
+
{
|
270
|
+
Job = new()
|
271
|
+
{
|
272
|
+
AllowedUpdates =
|
273
|
+
[
|
274
|
+
new() { UpdateType = "all" }
|
275
|
+
],
|
276
|
+
Source = new()
|
277
|
+
{
|
278
|
+
Provider = "github",
|
279
|
+
Repo = "test/repo",
|
280
|
+
Directory = "/",
|
281
|
+
}
|
282
|
+
}
|
283
|
+
};
|
284
|
+
await File.WriteAllTextAsync(Path.Join(temporaryDirectory, "job.json"), JsonSerializer.Serialize(jobFile, RunWorker.SerializerOptions));
|
285
|
+
}
|
286
|
+
|
249
287
|
public static async Task MockNuGetPackagesInDirectory(MockNuGetPackage[]? packages, string temporaryDirectory)
|
250
288
|
{
|
251
289
|
if (packages is not null)
|
@@ -350,7 +350,8 @@ public partial class UpdateWorkerTests
|
|
350
350
|
bool isTransitive = false,
|
351
351
|
(string Path, string Content)[]? additionalFiles = null,
|
352
352
|
(string Path, string Content)[]? additionalFilesExpected = null,
|
353
|
-
MockNuGetPackage[]? packages = null
|
353
|
+
MockNuGetPackage[]? packages = null,
|
354
|
+
ExperimentsManager? experimentsManager = null)
|
354
355
|
{
|
355
356
|
additionalFiles ??= [];
|
356
357
|
additionalFilesExpected ??= [];
|
@@ -363,8 +364,9 @@ public partial class UpdateWorkerTests
|
|
363
364
|
{
|
364
365
|
await MockNuGetPackagesInDirectory(packages, temporaryDirectory);
|
365
366
|
|
367
|
+
experimentsManager ??= new ExperimentsManager();
|
366
368
|
var projectPath = Path.Combine(temporaryDirectory, projectFileName);
|
367
|
-
var worker = new UpdaterWorker(new TestLogger());
|
369
|
+
var worker = new UpdaterWorker(experimentsManager, new TestLogger());
|
368
370
|
await worker.RunAsync(temporaryDirectory, projectPath, dependencyName, oldVersion, newVersion, isTransitive);
|
369
371
|
});
|
370
372
|
|