dependabot-nuget 0.321.3 → 0.322.1
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/Directory.Packages.props +22 -22
- data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation.Cli/Program.cs +21 -7
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/AnalyzeCommand.cs +19 -11
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/CloneCommand.cs +19 -9
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/DiscoverCommand.cs +21 -14
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/FrameworkCheckCommand.cs +8 -5
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/RunCommand.cs +29 -16
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/UpdateCommand.cs +20 -19
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Program.cs +2 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Analyze.cs +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Discover.cs +10 -23
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Run.cs +9 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Update.cs +15 -232
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs +1 -154
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/ExperimentsManager.cs +3 -12
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/GlobalJsonBuildFile.cs +5 -13
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/PrivateSourceTimedOutException.cs +12 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/JobErrorBase.cs +4 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/PrivateSourceTimedOut.cs +10 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/AzurePackageDetailFinder.cs +30 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/DetailedPullRequestBodyGenerator.cs +237 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/GitHubPackageDetailFinder.cs +101 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/GitLabPackageDetailFinder.cs +107 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/HttpFetcher.cs +32 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/IHttpFetcher.cs +30 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/IPackageDetailFinder.cs +47 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/IPullRequestBodyGenerator.cs +11 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/SimplePullRequestBodyGenerator.cs +15 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestTextGenerator.cs +7 -3
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +3 -525
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/CreateSecurityUpdatePullRequestHandler.cs +2 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/GroupUpdateAllVersionsHandler.cs +4 -4
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshGroupUpdatePullRequestHandler.cs +2 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandler.cs +2 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandler.cs +2 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/FileWriters/FileWriterWorker.cs +85 -35
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/FileWriters/XmlFileWriter.cs +27 -8
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs +1 -856
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdateOperationBase.cs +18 -7
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +16 -200
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +21 -556
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/AnalyzeWorkerTests.cs +9 -73
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Clone/CloneWorkerTests.cs +2 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/DependencySolver/MSBuildDependencySolverTests.cs +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTestBase.cs +1 -20
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.GlobalJson.cs +0 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.PackagesConfig.cs +3 -62
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.Project.cs +13 -563
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.cs +20 -269
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/SdkProjectDiscoveryTests.cs +2 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/GlobalJsonBuildFileTests.cs +0 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/EndToEndTests.cs +131 -131
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/HttpApiHandlerTests.cs +1 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/JobErrorBaseTests.cs +7 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/MessageReportTests.cs +11 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/MiscellaneousTests.cs +0 -203
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestBodyGenerator/DetailedPullRequestBodyGeneratorTests.cs +871 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestBodyGenerator/IPackageDetailFinderTests.cs +28 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestBodyGenerator/TestHttpFetcher.cs +23 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestTextTests.cs +24 -24
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/SerializationTests.cs +14 -12
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/CreateSecurityUpdatePullRequestHandlerTests.cs +6 -6
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/GroupUpdateAllVersionsHandlerTests.cs +18 -18
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshGroupUpdatePullRequestHandlerTests.cs +15 -15
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandlerTests.cs +21 -21
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandlerTests.cs +15 -15
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/UpdateHandlersTestsBase.cs +1 -8
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/FileWriterWorkerTests.cs +2 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/FileWriterWorkerTests_MiscellaneousTests.cs +45 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/XmlFileWriterTests.cs +111 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackageReferenceUpdaterTests.cs +1 -159
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +26 -660
- data/helpers/lib/NuGetUpdater/global.json +1 -1
- metadata +18 -10
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunResult.cs +0 -13
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestMessageTests.cs +0 -296
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs +0 -3592
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdatePermittedAndMessageTests.cs +0 -457
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DirsProj.cs +0 -378
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterHelperTests.cs +0 -175
@@ -1,3592 +0,0 @@
|
|
1
|
-
using System.Net;
|
2
|
-
using System.Text;
|
3
|
-
using System.Text.Json;
|
4
|
-
using System.Xml.Linq;
|
5
|
-
|
6
|
-
using NuGet.Versioning;
|
7
|
-
|
8
|
-
using NuGetUpdater.Core.Analyze;
|
9
|
-
using NuGetUpdater.Core.Discover;
|
10
|
-
using NuGetUpdater.Core.Run;
|
11
|
-
using NuGetUpdater.Core.Run.ApiModel;
|
12
|
-
using NuGetUpdater.Core.Test.Update;
|
13
|
-
using NuGetUpdater.Core.Updater;
|
14
|
-
|
15
|
-
using Xunit;
|
16
|
-
|
17
|
-
namespace NuGetUpdater.Core.Test.Run;
|
18
|
-
|
19
|
-
using TestFile = (string Path, string Content);
|
20
|
-
using RawTestFile = (string Path, byte[] Content);
|
21
|
-
|
22
|
-
public class RunWorkerTests
|
23
|
-
{
|
24
|
-
public const string TestPullRequestCommitMessage = "test-pull-request-commit-message";
|
25
|
-
public const string TestPullRequestTitle = "test-pull-request-title";
|
26
|
-
public const string TestPullRequestBody = "test-pull-request-body";
|
27
|
-
|
28
|
-
[Fact]
|
29
|
-
public async Task UpdateSinglePackageProducedExpectedAPIMessages()
|
30
|
-
{
|
31
|
-
await RunAsync(
|
32
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
33
|
-
packages: [],
|
34
|
-
job: new Job()
|
35
|
-
{
|
36
|
-
Source = new()
|
37
|
-
{
|
38
|
-
Provider = "github",
|
39
|
-
Repo = "test/repo",
|
40
|
-
Directory = "some-dir",
|
41
|
-
}
|
42
|
-
},
|
43
|
-
files:
|
44
|
-
[
|
45
|
-
("some-dir/project.csproj", """
|
46
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
47
|
-
<PropertyGroup>
|
48
|
-
<TargetFramework>net8.0</TargetFramework>
|
49
|
-
</PropertyGroup>
|
50
|
-
<ItemGroup>
|
51
|
-
<PackageReference Include="Some.Package" Version="1.0.0" />
|
52
|
-
</ItemGroup>
|
53
|
-
</Project>
|
54
|
-
""")
|
55
|
-
],
|
56
|
-
discoveryWorker: new TestDiscoveryWorker(_input =>
|
57
|
-
{
|
58
|
-
return Task.FromResult(new WorkspaceDiscoveryResult()
|
59
|
-
{
|
60
|
-
Path = "some-dir",
|
61
|
-
Projects =
|
62
|
-
[
|
63
|
-
new()
|
64
|
-
{
|
65
|
-
FilePath = "project.csproj",
|
66
|
-
TargetFrameworks = ["net8.0"],
|
67
|
-
Dependencies =
|
68
|
-
[
|
69
|
-
new("Some.Package", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net8.0"]),
|
70
|
-
],
|
71
|
-
ReferencedProjectPaths = [],
|
72
|
-
ImportedFiles = [],
|
73
|
-
AdditionalFiles = [],
|
74
|
-
}
|
75
|
-
]
|
76
|
-
});
|
77
|
-
}),
|
78
|
-
analyzeWorker: new TestAnalyzeWorker(input =>
|
79
|
-
{
|
80
|
-
return Task.FromResult(new AnalysisResult()
|
81
|
-
{
|
82
|
-
UpdatedVersion = "1.0.1",
|
83
|
-
CanUpdate = true,
|
84
|
-
UpdatedDependencies =
|
85
|
-
[
|
86
|
-
new("Some.Package", "1.0.1", DependencyType.Unknown, TargetFrameworks: ["net8.0"], InfoUrl: "https://nuget.example.com/some-package"),
|
87
|
-
]
|
88
|
-
});
|
89
|
-
}),
|
90
|
-
updaterWorker: new TestUpdaterWorker(async input =>
|
91
|
-
{
|
92
|
-
Assert.Equal("Some.Package", input.Item3);
|
93
|
-
Assert.Equal("1.0.0", input.Item4);
|
94
|
-
Assert.Equal("1.0.1", input.Item5);
|
95
|
-
var projectPath = input.Item1 + input.Item2;
|
96
|
-
await File.WriteAllTextAsync(projectPath, """
|
97
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
98
|
-
<PropertyGroup>
|
99
|
-
<TargetFramework>net8.0</TargetFramework>
|
100
|
-
</PropertyGroup>
|
101
|
-
<ItemGroup>
|
102
|
-
<PackageReference Include="Some.Package" Version="1.0.1" />
|
103
|
-
</ItemGroup>
|
104
|
-
</Project>
|
105
|
-
""");
|
106
|
-
return new UpdateOperationResult()
|
107
|
-
{
|
108
|
-
UpdateOperations = [
|
109
|
-
new DirectUpdate()
|
110
|
-
{
|
111
|
-
DependencyName = "Some.Package",
|
112
|
-
NewVersion = NuGetVersion.Parse("1.0.1"),
|
113
|
-
UpdatedFiles = ["/some-dir/project.csproj"]
|
114
|
-
}
|
115
|
-
],
|
116
|
-
};
|
117
|
-
}),
|
118
|
-
expectedResult: new RunResult()
|
119
|
-
{
|
120
|
-
Base64DependencyFiles =
|
121
|
-
[
|
122
|
-
new DependencyFile()
|
123
|
-
{
|
124
|
-
Directory = "/some-dir",
|
125
|
-
Name = "project.csproj",
|
126
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("""
|
127
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
128
|
-
<PropertyGroup>
|
129
|
-
<TargetFramework>net8.0</TargetFramework>
|
130
|
-
</PropertyGroup>
|
131
|
-
<ItemGroup>
|
132
|
-
<PackageReference Include="Some.Package" Version="1.0.0" />
|
133
|
-
</ItemGroup>
|
134
|
-
</Project>
|
135
|
-
""")),
|
136
|
-
ContentEncoding = "base64"
|
137
|
-
}
|
138
|
-
],
|
139
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
140
|
-
},
|
141
|
-
expectedApiMessages:
|
142
|
-
[
|
143
|
-
new UpdatedDependencyList()
|
144
|
-
{
|
145
|
-
Dependencies =
|
146
|
-
[
|
147
|
-
new ReportedDependency()
|
148
|
-
{
|
149
|
-
Name = "Some.Package",
|
150
|
-
Version = "1.0.0",
|
151
|
-
Requirements =
|
152
|
-
[
|
153
|
-
new ReportedRequirement()
|
154
|
-
{
|
155
|
-
Requirement = "1.0.0",
|
156
|
-
File = "/some-dir/project.csproj",
|
157
|
-
Groups = ["dependencies"],
|
158
|
-
}
|
159
|
-
]
|
160
|
-
}
|
161
|
-
],
|
162
|
-
DependencyFiles = ["/some-dir/project.csproj"],
|
163
|
-
},
|
164
|
-
new IncrementMetric()
|
165
|
-
{
|
166
|
-
Metric = "updater.started",
|
167
|
-
Tags = new()
|
168
|
-
{
|
169
|
-
["operation"] = "group_update_all_versions"
|
170
|
-
}
|
171
|
-
},
|
172
|
-
new CreatePullRequest()
|
173
|
-
{
|
174
|
-
Dependencies =
|
175
|
-
[
|
176
|
-
new ReportedDependency()
|
177
|
-
{
|
178
|
-
Name = "Some.Package",
|
179
|
-
Version = "1.0.1",
|
180
|
-
Requirements =
|
181
|
-
[
|
182
|
-
new ReportedRequirement()
|
183
|
-
{
|
184
|
-
Requirement = "1.0.1",
|
185
|
-
File = "/some-dir/project.csproj",
|
186
|
-
Groups = ["dependencies"],
|
187
|
-
Source = new()
|
188
|
-
{
|
189
|
-
SourceUrl = "https://nuget.example.com/some-package",
|
190
|
-
Type = "nuget_repo",
|
191
|
-
}
|
192
|
-
}
|
193
|
-
],
|
194
|
-
PreviousVersion = "1.0.0",
|
195
|
-
PreviousRequirements =
|
196
|
-
[
|
197
|
-
new ReportedRequirement()
|
198
|
-
{
|
199
|
-
Requirement = "1.0.0",
|
200
|
-
File = "/some-dir/project.csproj",
|
201
|
-
Groups = ["dependencies"],
|
202
|
-
}
|
203
|
-
],
|
204
|
-
}
|
205
|
-
],
|
206
|
-
UpdatedDependencyFiles =
|
207
|
-
[
|
208
|
-
new DependencyFile()
|
209
|
-
{
|
210
|
-
Name = "project.csproj",
|
211
|
-
Directory = "/some-dir",
|
212
|
-
Content = """
|
213
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
214
|
-
<PropertyGroup>
|
215
|
-
<TargetFramework>net8.0</TargetFramework>
|
216
|
-
</PropertyGroup>
|
217
|
-
<ItemGroup>
|
218
|
-
<PackageReference Include="Some.Package" Version="1.0.1" />
|
219
|
-
</ItemGroup>
|
220
|
-
</Project>
|
221
|
-
""",
|
222
|
-
},
|
223
|
-
],
|
224
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
225
|
-
CommitMessage = TestPullRequestCommitMessage,
|
226
|
-
PrTitle = TestPullRequestTitle,
|
227
|
-
PrBody = TestPullRequestBody,
|
228
|
-
DependencyGroup = null,
|
229
|
-
},
|
230
|
-
new MarkAsProcessed("TEST-COMMIT-SHA")
|
231
|
-
]
|
232
|
-
);
|
233
|
-
}
|
234
|
-
|
235
|
-
[Fact]
|
236
|
-
public async Task UpdateHandlesSemicolonsInPackageReference()
|
237
|
-
{
|
238
|
-
var repoMetadata = XElement.Parse("""<repository type="git" url="https://nuget.example.com/some-package" />""");
|
239
|
-
var repoMetadata2 = XElement.Parse("""<repository type="git" url="https://nuget.example.com/some-package2" />""");
|
240
|
-
await RunAsync(
|
241
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
242
|
-
packages:
|
243
|
-
[
|
244
|
-
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0", additionalMetadata: [repoMetadata]),
|
245
|
-
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.1", "net8.0", additionalMetadata: [repoMetadata]),
|
246
|
-
MockNuGetPackage.CreateSimplePackage("Some.Package2", "1.0.0", "net8.0", additionalMetadata: [repoMetadata2]),
|
247
|
-
MockNuGetPackage.CreateSimplePackage("Some.Package2", "1.0.1", "net8.0", additionalMetadata: [repoMetadata2]),
|
248
|
-
],
|
249
|
-
job: new Job()
|
250
|
-
{
|
251
|
-
PackageManager = "nuget",
|
252
|
-
Source = new()
|
253
|
-
{
|
254
|
-
Provider = "github",
|
255
|
-
Repo = "test/repo",
|
256
|
-
Directory = "some-dir",
|
257
|
-
}
|
258
|
-
},
|
259
|
-
files:
|
260
|
-
[
|
261
|
-
("some-dir/project.csproj", """
|
262
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
263
|
-
<PropertyGroup>
|
264
|
-
<TargetFramework>net8.0</TargetFramework>
|
265
|
-
</PropertyGroup>
|
266
|
-
<ItemGroup>
|
267
|
-
<PackageReference Include="Some.Package;Some.Package2" Version="1.0.0" />
|
268
|
-
</ItemGroup>
|
269
|
-
</Project>
|
270
|
-
""")
|
271
|
-
],
|
272
|
-
discoveryWorker: new TestDiscoveryWorker(_input =>
|
273
|
-
{
|
274
|
-
return Task.FromResult(new WorkspaceDiscoveryResult()
|
275
|
-
{
|
276
|
-
Path = "some-dir",
|
277
|
-
Projects =
|
278
|
-
[
|
279
|
-
new()
|
280
|
-
{
|
281
|
-
FilePath = "project.csproj",
|
282
|
-
TargetFrameworks = ["net8.0"],
|
283
|
-
Dependencies =
|
284
|
-
[
|
285
|
-
new("Some.Package", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net8.0"]),
|
286
|
-
new("Some.Package2", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net8.0"]),
|
287
|
-
],
|
288
|
-
ReferencedProjectPaths = [],
|
289
|
-
ImportedFiles = [],
|
290
|
-
AdditionalFiles = [],
|
291
|
-
}
|
292
|
-
]
|
293
|
-
});
|
294
|
-
}),
|
295
|
-
analyzeWorker: new TestAnalyzeWorker(input =>
|
296
|
-
{
|
297
|
-
return Task.FromResult(new AnalysisResult()
|
298
|
-
{
|
299
|
-
UpdatedVersion = "1.0.1",
|
300
|
-
CanUpdate = true,
|
301
|
-
UpdatedDependencies =
|
302
|
-
[
|
303
|
-
new("Some.Package", "1.0.1", DependencyType.Unknown, TargetFrameworks: ["net8.0"], InfoUrl: "https://nuget.example.com/some-package"),
|
304
|
-
new("Some.Package2", "1.0.1", DependencyType.Unknown, TargetFrameworks: ["net8.0"], InfoUrl: "https://nuget.example.com/some-package2"),
|
305
|
-
]
|
306
|
-
});
|
307
|
-
}),
|
308
|
-
updaterWorker: new TestUpdaterWorker(async input =>
|
309
|
-
{
|
310
|
-
Assert.Contains(input.Item3, new List<string> { "Some.Package", "Some.Package2" });
|
311
|
-
Assert.Equal("1.0.0", input.Item4);
|
312
|
-
Assert.Equal("1.0.1", input.Item5);
|
313
|
-
var projectPath = input.Item1 + input.Item2;
|
314
|
-
await File.WriteAllTextAsync(projectPath, """
|
315
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
316
|
-
<PropertyGroup>
|
317
|
-
<TargetFramework>net8.0</TargetFramework>
|
318
|
-
</PropertyGroup>
|
319
|
-
<ItemGroup>
|
320
|
-
<PackageReference Include="Some.Package;Some.Package2" Version="1.0.1" />
|
321
|
-
</ItemGroup>
|
322
|
-
</Project>
|
323
|
-
""");
|
324
|
-
return new UpdateOperationResult()
|
325
|
-
{
|
326
|
-
UpdateOperations = [
|
327
|
-
new DirectUpdate()
|
328
|
-
{
|
329
|
-
DependencyName = "Some.Package",
|
330
|
-
NewVersion = NuGetVersion.Parse("1.0.1"),
|
331
|
-
UpdatedFiles = ["/some-dir/project.csproj"]
|
332
|
-
},
|
333
|
-
new DirectUpdate()
|
334
|
-
{
|
335
|
-
DependencyName = "Some.Package2",
|
336
|
-
NewVersion = NuGetVersion.Parse("1.0.1"),
|
337
|
-
UpdatedFiles = ["/some-dir/project.csproj"]
|
338
|
-
}
|
339
|
-
],
|
340
|
-
};
|
341
|
-
}),
|
342
|
-
expectedResult: new RunResult()
|
343
|
-
{
|
344
|
-
Base64DependencyFiles =
|
345
|
-
[
|
346
|
-
new DependencyFile()
|
347
|
-
{
|
348
|
-
Directory = "/some-dir",
|
349
|
-
Name = "project.csproj",
|
350
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("""
|
351
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
352
|
-
<PropertyGroup>
|
353
|
-
<TargetFramework>net8.0</TargetFramework>
|
354
|
-
</PropertyGroup>
|
355
|
-
<ItemGroup>
|
356
|
-
<PackageReference Include="Some.Package;Some.Package2" Version="1.0.0" />
|
357
|
-
</ItemGroup>
|
358
|
-
</Project>
|
359
|
-
""")),
|
360
|
-
ContentEncoding = "base64"
|
361
|
-
}
|
362
|
-
],
|
363
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
364
|
-
},
|
365
|
-
expectedApiMessages:
|
366
|
-
[
|
367
|
-
new UpdatedDependencyList()
|
368
|
-
{
|
369
|
-
Dependencies =
|
370
|
-
[
|
371
|
-
new ReportedDependency()
|
372
|
-
{
|
373
|
-
Name = "Some.Package",
|
374
|
-
Version = "1.0.0",
|
375
|
-
Requirements =
|
376
|
-
[
|
377
|
-
new ReportedRequirement()
|
378
|
-
{
|
379
|
-
Requirement = "1.0.0",
|
380
|
-
File = "/some-dir/project.csproj",
|
381
|
-
Groups = ["dependencies"],
|
382
|
-
}
|
383
|
-
]
|
384
|
-
},
|
385
|
-
new ReportedDependency()
|
386
|
-
{
|
387
|
-
Name = "Some.Package2",
|
388
|
-
Version = "1.0.0",
|
389
|
-
Requirements =
|
390
|
-
[
|
391
|
-
new ReportedRequirement()
|
392
|
-
{
|
393
|
-
Requirement = "1.0.0",
|
394
|
-
File = "/some-dir/project.csproj",
|
395
|
-
Groups = ["dependencies"],
|
396
|
-
}
|
397
|
-
]
|
398
|
-
},
|
399
|
-
],
|
400
|
-
DependencyFiles = ["/some-dir/project.csproj"],
|
401
|
-
},
|
402
|
-
new IncrementMetric()
|
403
|
-
{
|
404
|
-
Metric = "updater.started",
|
405
|
-
Tags = new()
|
406
|
-
{
|
407
|
-
["operation"] = "group_update_all_versions"
|
408
|
-
}
|
409
|
-
},
|
410
|
-
new CreatePullRequest()
|
411
|
-
{
|
412
|
-
Dependencies =
|
413
|
-
[
|
414
|
-
new ReportedDependency()
|
415
|
-
{
|
416
|
-
Name = "Some.Package",
|
417
|
-
Version = "1.0.1",
|
418
|
-
Requirements =
|
419
|
-
[
|
420
|
-
new ReportedRequirement()
|
421
|
-
{
|
422
|
-
Requirement = "1.0.1",
|
423
|
-
File = "/some-dir/project.csproj",
|
424
|
-
Groups = ["dependencies"],
|
425
|
-
Source = new()
|
426
|
-
{
|
427
|
-
SourceUrl = "https://nuget.example.com/some-package",
|
428
|
-
Type = "nuget_repo",
|
429
|
-
}
|
430
|
-
}
|
431
|
-
],
|
432
|
-
PreviousVersion = "1.0.0",
|
433
|
-
PreviousRequirements =
|
434
|
-
[
|
435
|
-
new ReportedRequirement()
|
436
|
-
{
|
437
|
-
Requirement = "1.0.0",
|
438
|
-
File = "/some-dir/project.csproj",
|
439
|
-
Groups = ["dependencies"],
|
440
|
-
}
|
441
|
-
],
|
442
|
-
},
|
443
|
-
new ReportedDependency()
|
444
|
-
{
|
445
|
-
Name = "Some.Package2",
|
446
|
-
Version = "1.0.1",
|
447
|
-
Requirements =
|
448
|
-
[
|
449
|
-
new ReportedRequirement()
|
450
|
-
{
|
451
|
-
Requirement = "1.0.1",
|
452
|
-
File = "/some-dir/project.csproj",
|
453
|
-
Groups = ["dependencies"],
|
454
|
-
Source = new()
|
455
|
-
{
|
456
|
-
SourceUrl = "https://nuget.example.com/some-package2",
|
457
|
-
Type = "nuget_repo",
|
458
|
-
}
|
459
|
-
}
|
460
|
-
],
|
461
|
-
PreviousVersion = "1.0.0",
|
462
|
-
PreviousRequirements =
|
463
|
-
[
|
464
|
-
new ReportedRequirement()
|
465
|
-
{
|
466
|
-
Requirement = "1.0.0",
|
467
|
-
File = "/some-dir/project.csproj",
|
468
|
-
Groups = ["dependencies"],
|
469
|
-
}
|
470
|
-
],
|
471
|
-
},
|
472
|
-
],
|
473
|
-
UpdatedDependencyFiles =
|
474
|
-
[
|
475
|
-
new DependencyFile()
|
476
|
-
{
|
477
|
-
Name = "project.csproj",
|
478
|
-
Directory = "/some-dir",
|
479
|
-
Content = """
|
480
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
481
|
-
<PropertyGroup>
|
482
|
-
<TargetFramework>net8.0</TargetFramework>
|
483
|
-
</PropertyGroup>
|
484
|
-
<ItemGroup>
|
485
|
-
<PackageReference Include="Some.Package;Some.Package2" Version="1.0.1" />
|
486
|
-
</ItemGroup>
|
487
|
-
</Project>
|
488
|
-
""",
|
489
|
-
}
|
490
|
-
|
491
|
-
],
|
492
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
493
|
-
CommitMessage = TestPullRequestCommitMessage,
|
494
|
-
PrTitle = TestPullRequestTitle,
|
495
|
-
PrBody = TestPullRequestBody,
|
496
|
-
DependencyGroup = null,
|
497
|
-
},
|
498
|
-
new MarkAsProcessed("TEST-COMMIT-SHA")
|
499
|
-
]
|
500
|
-
);
|
501
|
-
}
|
502
|
-
|
503
|
-
[Fact]
|
504
|
-
public async Task ErrorsThrownFromDiscoveryWorkerAreForwaredToApiHandler()
|
505
|
-
{
|
506
|
-
await RunAsync(
|
507
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
508
|
-
packages:
|
509
|
-
[
|
510
|
-
],
|
511
|
-
job: new Job()
|
512
|
-
{
|
513
|
-
Source = new()
|
514
|
-
{
|
515
|
-
Provider = "github",
|
516
|
-
Repo = "test/repo",
|
517
|
-
Directory = "/",
|
518
|
-
}
|
519
|
-
},
|
520
|
-
files:
|
521
|
-
[
|
522
|
-
("NuGet.Config", """
|
523
|
-
<configuration>
|
524
|
-
<packageSources>
|
525
|
-
<clear />
|
526
|
-
<add key="private_feed" value="http://example.com/nuget/index.json" allowInsecureConnections="true" />
|
527
|
-
</packageSources>
|
528
|
-
</configuration>
|
529
|
-
"""),
|
530
|
-
("project.csproj", """
|
531
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
532
|
-
<PropertyGroup>
|
533
|
-
<TargetFramework>net8.0</TargetFramework>
|
534
|
-
</PropertyGroup>
|
535
|
-
<ItemGroup>
|
536
|
-
<PackageReference Include="Some.Package" Version="1.0.0" />
|
537
|
-
</ItemGroup>
|
538
|
-
</Project>
|
539
|
-
""")
|
540
|
-
],
|
541
|
-
discoveryWorker: new TestDiscoveryWorker((_input) =>
|
542
|
-
{
|
543
|
-
throw new HttpRequestException(message: null, inner: null, statusCode: HttpStatusCode.Unauthorized);
|
544
|
-
}),
|
545
|
-
analyzeWorker: new TestAnalyzeWorker((_input) => throw new NotImplementedException("shouldn't get this far")),
|
546
|
-
updaterWorker: new TestUpdaterWorker((_input) => throw new NotImplementedException("shouldn't get this far")),
|
547
|
-
expectedResult: new RunResult()
|
548
|
-
{
|
549
|
-
Base64DependencyFiles = [],
|
550
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
551
|
-
},
|
552
|
-
expectedApiMessages:
|
553
|
-
[
|
554
|
-
new PrivateSourceAuthenticationFailure(["http://example.com/nuget/index.json"]),
|
555
|
-
new MarkAsProcessed("TEST-COMMIT-SHA")
|
556
|
-
]
|
557
|
-
);
|
558
|
-
}
|
559
|
-
|
560
|
-
[Fact]
|
561
|
-
public async Task ErrorsReturnedFromDiscoveryWorkerAreForwaredToApiHandler()
|
562
|
-
{
|
563
|
-
await RunAsync(
|
564
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
565
|
-
packages: [],
|
566
|
-
job: new Job()
|
567
|
-
{
|
568
|
-
Source = new()
|
569
|
-
{
|
570
|
-
Provider = "github",
|
571
|
-
Repo = "test/repo",
|
572
|
-
Directory = "/",
|
573
|
-
}
|
574
|
-
},
|
575
|
-
files: [],
|
576
|
-
discoveryWorker: new TestDiscoveryWorker((_input) =>
|
577
|
-
{
|
578
|
-
return Task.FromResult(new WorkspaceDiscoveryResult()
|
579
|
-
{
|
580
|
-
Path = "/",
|
581
|
-
IsSuccess = false,
|
582
|
-
Projects = [],
|
583
|
-
Error = new PrivateSourceAuthenticationFailure(["http://example.com/nuget/index.json"]),
|
584
|
-
});
|
585
|
-
}),
|
586
|
-
analyzeWorker: new TestAnalyzeWorker((_input) => throw new NotImplementedException("shouldn't get this far")),
|
587
|
-
updaterWorker: new TestUpdaterWorker((_input) => throw new NotImplementedException("shouldn't get this far")),
|
588
|
-
expectedResult: new RunResult()
|
589
|
-
{
|
590
|
-
Base64DependencyFiles = [],
|
591
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
592
|
-
},
|
593
|
-
expectedApiMessages:
|
594
|
-
[
|
595
|
-
new PrivateSourceAuthenticationFailure(["http://example.com/nuget/index.json"]),
|
596
|
-
new MarkAsProcessed("TEST-COMMIT-SHA")
|
597
|
-
]
|
598
|
-
);
|
599
|
-
}
|
600
|
-
|
601
|
-
[Fact]
|
602
|
-
public async Task ErrorsThrownFromAnalyzeWorkerAreForwaredToApiHandler()
|
603
|
-
{
|
604
|
-
await RunAsync(
|
605
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
606
|
-
packages: [],
|
607
|
-
job: new Job()
|
608
|
-
{
|
609
|
-
Source = new()
|
610
|
-
{
|
611
|
-
Provider = "github",
|
612
|
-
Repo = "test/repo",
|
613
|
-
Directory = "/",
|
614
|
-
}
|
615
|
-
},
|
616
|
-
files:
|
617
|
-
[
|
618
|
-
("NuGet.Config", """
|
619
|
-
<configuration>
|
620
|
-
<packageSources>
|
621
|
-
<clear />
|
622
|
-
<add key="private_feed" value="http://example.com/nuget/index.json" allowInsecureConnections="true" />
|
623
|
-
</packageSources>
|
624
|
-
</configuration>
|
625
|
-
"""),
|
626
|
-
("project.csproj", """
|
627
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
628
|
-
<PropertyGroup>
|
629
|
-
<TargetFramework>net8.0</TargetFramework>
|
630
|
-
</PropertyGroup>
|
631
|
-
<ItemGroup>
|
632
|
-
<PackageReference Include="Some.Package" Version="1.0.0" />
|
633
|
-
</ItemGroup>
|
634
|
-
</Project>
|
635
|
-
""")
|
636
|
-
],
|
637
|
-
discoveryWorker: new TestDiscoveryWorker((_input) =>
|
638
|
-
{
|
639
|
-
return Task.FromResult(new WorkspaceDiscoveryResult()
|
640
|
-
{
|
641
|
-
Path = "",
|
642
|
-
Projects = [
|
643
|
-
new()
|
644
|
-
{
|
645
|
-
FilePath = "project.csproj",
|
646
|
-
Dependencies = [new("Some.Package", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net8.0"])],
|
647
|
-
ImportedFiles = [],
|
648
|
-
AdditionalFiles = [],
|
649
|
-
}
|
650
|
-
]
|
651
|
-
});
|
652
|
-
}),
|
653
|
-
analyzeWorker: new TestAnalyzeWorker((_input) =>
|
654
|
-
{
|
655
|
-
throw new HttpRequestException(message: null, inner: null, statusCode: HttpStatusCode.Unauthorized);
|
656
|
-
}),
|
657
|
-
updaterWorker: new TestUpdaterWorker((_input) => throw new NotImplementedException("shouldn't get this far")),
|
658
|
-
expectedResult: new RunResult()
|
659
|
-
{
|
660
|
-
Base64DependencyFiles = [],
|
661
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
662
|
-
},
|
663
|
-
expectedApiMessages:
|
664
|
-
[
|
665
|
-
new UpdatedDependencyList()
|
666
|
-
{
|
667
|
-
Dependencies =
|
668
|
-
[
|
669
|
-
new ReportedDependency()
|
670
|
-
{
|
671
|
-
Name = "Some.Package",
|
672
|
-
Version = "1.0.0",
|
673
|
-
Requirements =
|
674
|
-
[
|
675
|
-
new ReportedRequirement()
|
676
|
-
{
|
677
|
-
Requirement = "1.0.0",
|
678
|
-
File = "/project.csproj",
|
679
|
-
Groups = ["dependencies"],
|
680
|
-
}
|
681
|
-
]
|
682
|
-
}
|
683
|
-
],
|
684
|
-
DependencyFiles = ["/project.csproj"],
|
685
|
-
},
|
686
|
-
new IncrementMetric()
|
687
|
-
{
|
688
|
-
Metric = "updater.started",
|
689
|
-
Tags = new()
|
690
|
-
{
|
691
|
-
["operation"] = "group_update_all_versions"
|
692
|
-
}
|
693
|
-
},
|
694
|
-
new PrivateSourceAuthenticationFailure(["http://example.com/nuget/index.json"]),
|
695
|
-
new MarkAsProcessed("TEST-COMMIT-SHA")
|
696
|
-
]
|
697
|
-
);
|
698
|
-
}
|
699
|
-
|
700
|
-
[Fact]
|
701
|
-
public async Task ErrorsReturnedFromAnalyzeWorkerAreForwaredToApiHandler()
|
702
|
-
{
|
703
|
-
await RunAsync(
|
704
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
705
|
-
packages: [],
|
706
|
-
job: new Job()
|
707
|
-
{
|
708
|
-
Source = new()
|
709
|
-
{
|
710
|
-
Provider = "github",
|
711
|
-
Repo = "test/repo",
|
712
|
-
Directory = "/",
|
713
|
-
}
|
714
|
-
},
|
715
|
-
files: [
|
716
|
-
("project.csproj", """
|
717
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
718
|
-
<PropertyGroup>
|
719
|
-
<TargetFramework>net8.0</TargetFramework>
|
720
|
-
</PropertyGroup>
|
721
|
-
<ItemGroup>
|
722
|
-
<PackageReference Include="Some.Package" Version="1.0.0" />
|
723
|
-
</ItemGroup>
|
724
|
-
</Project>
|
725
|
-
""")
|
726
|
-
],
|
727
|
-
discoveryWorker: new TestDiscoveryWorker((_input) =>
|
728
|
-
{
|
729
|
-
return Task.FromResult(new WorkspaceDiscoveryResult()
|
730
|
-
{
|
731
|
-
Path = "",
|
732
|
-
Projects = [
|
733
|
-
new()
|
734
|
-
{
|
735
|
-
FilePath = "project.csproj",
|
736
|
-
Dependencies = [new("Some.Package", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net8.0"])],
|
737
|
-
ImportedFiles = [],
|
738
|
-
AdditionalFiles = [],
|
739
|
-
}
|
740
|
-
]
|
741
|
-
});
|
742
|
-
}),
|
743
|
-
analyzeWorker: new TestAnalyzeWorker((_input) =>
|
744
|
-
{
|
745
|
-
return Task.FromResult(new AnalysisResult()
|
746
|
-
{
|
747
|
-
UpdatedVersion = "",
|
748
|
-
CanUpdate = false,
|
749
|
-
VersionComesFromMultiDependencyProperty = false,
|
750
|
-
UpdatedDependencies = [],
|
751
|
-
Error = new PrivateSourceAuthenticationFailure(["http://example.com/nuget/index.json"]),
|
752
|
-
});
|
753
|
-
}),
|
754
|
-
updaterWorker: new TestUpdaterWorker((_input) => throw new NotImplementedException("shouldn't get this far")),
|
755
|
-
expectedResult: new RunResult()
|
756
|
-
{
|
757
|
-
Base64DependencyFiles = [
|
758
|
-
new()
|
759
|
-
{
|
760
|
-
Directory = "/",
|
761
|
-
Name = "project.csproj",
|
762
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("""
|
763
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
764
|
-
<PropertyGroup>
|
765
|
-
<TargetFramework>net8.0</TargetFramework>
|
766
|
-
</PropertyGroup>
|
767
|
-
<ItemGroup>
|
768
|
-
<PackageReference Include="Some.Package" Version="1.0.0" />
|
769
|
-
</ItemGroup>
|
770
|
-
</Project>
|
771
|
-
""")),
|
772
|
-
ContentEncoding = "base64"
|
773
|
-
}
|
774
|
-
],
|
775
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
776
|
-
},
|
777
|
-
expectedApiMessages:
|
778
|
-
[
|
779
|
-
new UpdatedDependencyList()
|
780
|
-
{
|
781
|
-
Dependencies =
|
782
|
-
[
|
783
|
-
new ReportedDependency()
|
784
|
-
{
|
785
|
-
Name = "Some.Package",
|
786
|
-
Version = "1.0.0",
|
787
|
-
Requirements =
|
788
|
-
[
|
789
|
-
new ReportedRequirement()
|
790
|
-
{
|
791
|
-
Requirement = "1.0.0",
|
792
|
-
File = "/project.csproj",
|
793
|
-
Groups = ["dependencies"],
|
794
|
-
}
|
795
|
-
]
|
796
|
-
}
|
797
|
-
],
|
798
|
-
DependencyFiles = ["/project.csproj"],
|
799
|
-
},
|
800
|
-
new IncrementMetric()
|
801
|
-
{
|
802
|
-
Metric = "updater.started",
|
803
|
-
Tags = new()
|
804
|
-
{
|
805
|
-
["operation"] = "group_update_all_versions"
|
806
|
-
}
|
807
|
-
},
|
808
|
-
new PrivateSourceAuthenticationFailure(["http://example.com/nuget/index.json"]),
|
809
|
-
new MarkAsProcessed("TEST-COMMIT-SHA")
|
810
|
-
]
|
811
|
-
);
|
812
|
-
}
|
813
|
-
|
814
|
-
[Fact]
|
815
|
-
public async Task ErrorsThrownFromUpdaterWorkerAreForwaredToApiHandler()
|
816
|
-
{
|
817
|
-
await RunAsync(
|
818
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
819
|
-
packages: [],
|
820
|
-
job: new Job()
|
821
|
-
{
|
822
|
-
Source = new()
|
823
|
-
{
|
824
|
-
Provider = "github",
|
825
|
-
Repo = "test/repo",
|
826
|
-
Directory = "/",
|
827
|
-
}
|
828
|
-
},
|
829
|
-
files:
|
830
|
-
[
|
831
|
-
("NuGet.Config", """
|
832
|
-
<configuration>
|
833
|
-
<packageSources>
|
834
|
-
<clear />
|
835
|
-
<add key="private_feed" value="http://example.com/nuget/index.json" allowInsecureConnections="true" />
|
836
|
-
</packageSources>
|
837
|
-
</configuration>
|
838
|
-
"""),
|
839
|
-
("project.csproj", """
|
840
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
841
|
-
<PropertyGroup>
|
842
|
-
<TargetFramework>net8.0</TargetFramework>
|
843
|
-
</PropertyGroup>
|
844
|
-
<ItemGroup>
|
845
|
-
<PackageReference Include="Some.Package" Version="1.0.0" />
|
846
|
-
</ItemGroup>
|
847
|
-
</Project>
|
848
|
-
""")
|
849
|
-
],
|
850
|
-
discoveryWorker: new TestDiscoveryWorker((_input) =>
|
851
|
-
{
|
852
|
-
return Task.FromResult(new WorkspaceDiscoveryResult()
|
853
|
-
{
|
854
|
-
Path = "",
|
855
|
-
Projects = [
|
856
|
-
new()
|
857
|
-
{
|
858
|
-
FilePath = "project.csproj",
|
859
|
-
Dependencies = [new("Some.Package", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net8.0"])],
|
860
|
-
ImportedFiles = [],
|
861
|
-
AdditionalFiles = [],
|
862
|
-
}
|
863
|
-
]
|
864
|
-
});
|
865
|
-
}),
|
866
|
-
analyzeWorker: new TestAnalyzeWorker((_input) =>
|
867
|
-
{
|
868
|
-
return Task.FromResult(new AnalysisResult()
|
869
|
-
{
|
870
|
-
UpdatedVersion = "1.0.1",
|
871
|
-
CanUpdate = true,
|
872
|
-
UpdatedDependencies =
|
873
|
-
[
|
874
|
-
new("Some.Package", "1.0.1", DependencyType.Unknown, TargetFrameworks: ["net8.0"], InfoUrl: "https://nuget.example.com/some-package"),
|
875
|
-
]
|
876
|
-
});
|
877
|
-
}),
|
878
|
-
updaterWorker: new TestUpdaterWorker((_input) =>
|
879
|
-
{
|
880
|
-
throw new HttpRequestException(message: null, inner: null, statusCode: HttpStatusCode.Unauthorized);
|
881
|
-
}),
|
882
|
-
expectedResult: new RunResult()
|
883
|
-
{
|
884
|
-
Base64DependencyFiles = [],
|
885
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
886
|
-
},
|
887
|
-
expectedApiMessages:
|
888
|
-
[
|
889
|
-
new UpdatedDependencyList()
|
890
|
-
{
|
891
|
-
Dependencies =
|
892
|
-
[
|
893
|
-
new ReportedDependency()
|
894
|
-
{
|
895
|
-
Name = "Some.Package",
|
896
|
-
Version = "1.0.0",
|
897
|
-
Requirements =
|
898
|
-
[
|
899
|
-
new ReportedRequirement()
|
900
|
-
{
|
901
|
-
Requirement = "1.0.0",
|
902
|
-
File = "/project.csproj",
|
903
|
-
Groups = ["dependencies"],
|
904
|
-
}
|
905
|
-
]
|
906
|
-
}
|
907
|
-
],
|
908
|
-
DependencyFiles = ["/project.csproj"],
|
909
|
-
},
|
910
|
-
new IncrementMetric()
|
911
|
-
{
|
912
|
-
Metric = "updater.started",
|
913
|
-
Tags = new()
|
914
|
-
{
|
915
|
-
["operation"] = "group_update_all_versions"
|
916
|
-
}
|
917
|
-
},
|
918
|
-
new PrivateSourceAuthenticationFailure(["http://example.com/nuget/index.json"]),
|
919
|
-
new MarkAsProcessed("TEST-COMMIT-SHA")
|
920
|
-
]
|
921
|
-
);
|
922
|
-
}
|
923
|
-
|
924
|
-
[Fact]
|
925
|
-
public async Task ErrorsReturnedFromUpdaterWorkerAreForwaredToApiHandler()
|
926
|
-
{
|
927
|
-
await RunAsync(
|
928
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
929
|
-
packages: [],
|
930
|
-
job: new Job()
|
931
|
-
{
|
932
|
-
Source = new()
|
933
|
-
{
|
934
|
-
Provider = "github",
|
935
|
-
Repo = "test/repo",
|
936
|
-
Directory = "/",
|
937
|
-
}
|
938
|
-
},
|
939
|
-
files:
|
940
|
-
[
|
941
|
-
("project.csproj", """
|
942
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
943
|
-
<PropertyGroup>
|
944
|
-
<TargetFramework>net8.0</TargetFramework>
|
945
|
-
</PropertyGroup>
|
946
|
-
<ItemGroup>
|
947
|
-
<PackageReference Include="Some.Package" Version="1.0.0" />
|
948
|
-
</ItemGroup>
|
949
|
-
</Project>
|
950
|
-
""")
|
951
|
-
],
|
952
|
-
discoveryWorker: new TestDiscoveryWorker((_input) =>
|
953
|
-
{
|
954
|
-
return Task.FromResult(new WorkspaceDiscoveryResult()
|
955
|
-
{
|
956
|
-
Path = "",
|
957
|
-
Projects = [
|
958
|
-
new()
|
959
|
-
{
|
960
|
-
FilePath = "project.csproj",
|
961
|
-
Dependencies = [new("Some.Package", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net8.0"])],
|
962
|
-
ImportedFiles = [],
|
963
|
-
AdditionalFiles = [],
|
964
|
-
}
|
965
|
-
]
|
966
|
-
});
|
967
|
-
}),
|
968
|
-
analyzeWorker: new TestAnalyzeWorker((_input) =>
|
969
|
-
{
|
970
|
-
return Task.FromResult(new AnalysisResult()
|
971
|
-
{
|
972
|
-
UpdatedVersion = "1.0.1",
|
973
|
-
CanUpdate = true,
|
974
|
-
UpdatedDependencies =
|
975
|
-
[
|
976
|
-
new("Some.Package", "1.0.1", DependencyType.Unknown, TargetFrameworks: ["net8.0"], InfoUrl: "https://nuget.example.com/some-package"),
|
977
|
-
]
|
978
|
-
});
|
979
|
-
}),
|
980
|
-
updaterWorker: new TestUpdaterWorker((_input) =>
|
981
|
-
{
|
982
|
-
return Task.FromResult(new UpdateOperationResult()
|
983
|
-
{
|
984
|
-
UpdateOperations = [],
|
985
|
-
Error = new PrivateSourceAuthenticationFailure(["http://example.com/nuget/index.json"]),
|
986
|
-
});
|
987
|
-
}),
|
988
|
-
expectedResult: new RunResult()
|
989
|
-
{
|
990
|
-
Base64DependencyFiles = [
|
991
|
-
new()
|
992
|
-
{
|
993
|
-
Directory = "/",
|
994
|
-
Name = "project.csproj",
|
995
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("""
|
996
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
997
|
-
<PropertyGroup>
|
998
|
-
<TargetFramework>net8.0</TargetFramework>
|
999
|
-
</PropertyGroup>
|
1000
|
-
<ItemGroup>
|
1001
|
-
<PackageReference Include="Some.Package" Version="1.0.0" />
|
1002
|
-
</ItemGroup>
|
1003
|
-
</Project>
|
1004
|
-
""")),
|
1005
|
-
ContentEncoding = "base64"
|
1006
|
-
}
|
1007
|
-
],
|
1008
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
1009
|
-
},
|
1010
|
-
expectedApiMessages:
|
1011
|
-
[
|
1012
|
-
new UpdatedDependencyList()
|
1013
|
-
{
|
1014
|
-
Dependencies =
|
1015
|
-
[
|
1016
|
-
new ReportedDependency()
|
1017
|
-
{
|
1018
|
-
Name = "Some.Package",
|
1019
|
-
Version = "1.0.0",
|
1020
|
-
Requirements =
|
1021
|
-
[
|
1022
|
-
new ReportedRequirement()
|
1023
|
-
{
|
1024
|
-
Requirement = "1.0.0",
|
1025
|
-
File = "/project.csproj",
|
1026
|
-
Groups = ["dependencies"],
|
1027
|
-
}
|
1028
|
-
]
|
1029
|
-
}
|
1030
|
-
],
|
1031
|
-
DependencyFiles = ["/project.csproj"],
|
1032
|
-
},
|
1033
|
-
new IncrementMetric()
|
1034
|
-
{
|
1035
|
-
Metric = "updater.started",
|
1036
|
-
Tags = new()
|
1037
|
-
{
|
1038
|
-
["operation"] = "group_update_all_versions"
|
1039
|
-
}
|
1040
|
-
},
|
1041
|
-
new PrivateSourceAuthenticationFailure(["http://example.com/nuget/index.json"]),
|
1042
|
-
new MarkAsProcessed("TEST-COMMIT-SHA")
|
1043
|
-
]
|
1044
|
-
);
|
1045
|
-
}
|
1046
|
-
|
1047
|
-
[Fact]
|
1048
|
-
public async Task UpdateHandlesPackagesConfigFiles()
|
1049
|
-
{
|
1050
|
-
var repoMetadata = XElement.Parse("""<repository type="git" url="https://nuget.example.com/some-package" />""");
|
1051
|
-
var repoMetadata2 = XElement.Parse("""<repository type="git" url="https://nuget.example.com/some-package2" />""");
|
1052
|
-
await RunAsync(
|
1053
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
1054
|
-
packages:
|
1055
|
-
[
|
1056
|
-
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0", additionalMetadata: [repoMetadata]),
|
1057
|
-
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.1", "net8.0", additionalMetadata: [repoMetadata]),
|
1058
|
-
MockNuGetPackage.CreateSimplePackage("Some.Package2", "2.0.0", "net8.0", additionalMetadata: [repoMetadata2]),
|
1059
|
-
MockNuGetPackage.CreateSimplePackage("Some.Package2", "2.0.1", "net8.0", additionalMetadata: [repoMetadata2]),
|
1060
|
-
],
|
1061
|
-
job: new Job()
|
1062
|
-
{
|
1063
|
-
PackageManager = "nuget",
|
1064
|
-
Source = new()
|
1065
|
-
{
|
1066
|
-
Provider = "github",
|
1067
|
-
Repo = "test/repo",
|
1068
|
-
Directory = "some-dir",
|
1069
|
-
}
|
1070
|
-
},
|
1071
|
-
files:
|
1072
|
-
[
|
1073
|
-
("some-dir/project.csproj", """
|
1074
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
1075
|
-
<PropertyGroup>
|
1076
|
-
<TargetFramework>net8.0</TargetFramework>
|
1077
|
-
</PropertyGroup>
|
1078
|
-
<ItemGroup>
|
1079
|
-
<PackageReference Include="Some.Package" Version="1.0.0" />
|
1080
|
-
</ItemGroup>
|
1081
|
-
</Project>
|
1082
|
-
"""),
|
1083
|
-
("some-dir/packages.config", """
|
1084
|
-
<?xml version="1.0" encoding="utf-8"?>
|
1085
|
-
<packages>
|
1086
|
-
<package id="Some.Package2" version="2.0.0" targetFramework="net8.0" />
|
1087
|
-
</packages>
|
1088
|
-
"""),
|
1089
|
-
],
|
1090
|
-
discoveryWorker: new TestDiscoveryWorker(_input =>
|
1091
|
-
{
|
1092
|
-
return Task.FromResult(new WorkspaceDiscoveryResult()
|
1093
|
-
{
|
1094
|
-
Path = "some-dir",
|
1095
|
-
Projects =
|
1096
|
-
[
|
1097
|
-
new()
|
1098
|
-
{
|
1099
|
-
FilePath = "project.csproj",
|
1100
|
-
TargetFrameworks = ["net8.0"],
|
1101
|
-
Dependencies =
|
1102
|
-
[
|
1103
|
-
new("Some.Package", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net8.0"]),
|
1104
|
-
new("Some.Package2", "2.0.0", DependencyType.PackagesConfig, TargetFrameworks: ["net8.0"]),
|
1105
|
-
],
|
1106
|
-
ReferencedProjectPaths = [],
|
1107
|
-
ImportedFiles = [],
|
1108
|
-
AdditionalFiles = ["packages.config"],
|
1109
|
-
}
|
1110
|
-
]
|
1111
|
-
});
|
1112
|
-
}),
|
1113
|
-
analyzeWorker: new TestAnalyzeWorker(input =>
|
1114
|
-
{
|
1115
|
-
var result = input.Item3.Name switch
|
1116
|
-
{
|
1117
|
-
"Some.Package" => new AnalysisResult()
|
1118
|
-
{
|
1119
|
-
CanUpdate = true,
|
1120
|
-
UpdatedVersion = "1.0.1",
|
1121
|
-
UpdatedDependencies =
|
1122
|
-
[
|
1123
|
-
new("Some.Package", "1.0.1", DependencyType.Unknown, TargetFrameworks: ["net8.0"], InfoUrl: "https://nuget.example.com/some-package"),
|
1124
|
-
]
|
1125
|
-
},
|
1126
|
-
"Some.Package2" => new AnalysisResult()
|
1127
|
-
{
|
1128
|
-
CanUpdate = true,
|
1129
|
-
UpdatedVersion = "2.0.1",
|
1130
|
-
UpdatedDependencies =
|
1131
|
-
[
|
1132
|
-
new("Some.Package2", "2.0.1", DependencyType.Unknown, TargetFrameworks: ["net8.0"], InfoUrl: "https://nuget.example.com/some-package2"),
|
1133
|
-
]
|
1134
|
-
},
|
1135
|
-
_ => throw new NotSupportedException(),
|
1136
|
-
};
|
1137
|
-
return Task.FromResult(result);
|
1138
|
-
}),
|
1139
|
-
updaterWorker: new TestUpdaterWorker(async input =>
|
1140
|
-
{
|
1141
|
-
var repoRootPath = input.Item1;
|
1142
|
-
var filePath = input.Item2;
|
1143
|
-
var packageName = input.Item3;
|
1144
|
-
var previousVersion = input.Item4;
|
1145
|
-
var newVersion = input.Item5;
|
1146
|
-
var _isTransitive = input.Item6;
|
1147
|
-
|
1148
|
-
var projectPath = Path.Join(repoRootPath, filePath);
|
1149
|
-
switch (packageName)
|
1150
|
-
{
|
1151
|
-
case "Some.Package":
|
1152
|
-
await File.WriteAllTextAsync(projectPath, """
|
1153
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
1154
|
-
<PropertyGroup>
|
1155
|
-
<TargetFramework>net8.0</TargetFramework>
|
1156
|
-
</PropertyGroup>
|
1157
|
-
<ItemGroup>
|
1158
|
-
<PackageReference Include="Some.Package" Version="1.0.1" />
|
1159
|
-
</ItemGroup>
|
1160
|
-
</Project>
|
1161
|
-
""");
|
1162
|
-
break;
|
1163
|
-
case "Some.Package2":
|
1164
|
-
await File.WriteAllTextAsync(projectPath, """
|
1165
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
1166
|
-
<PropertyGroup>
|
1167
|
-
<TargetFramework>net8.0</TargetFramework>
|
1168
|
-
</PropertyGroup>
|
1169
|
-
<ItemGroup>
|
1170
|
-
<PackageReference Include="Some.Package" Version="1.0.1" />
|
1171
|
-
</ItemGroup>
|
1172
|
-
<ItemGroup>
|
1173
|
-
<Reference Include="Some.Package2">
|
1174
|
-
<HintPath>..\packages\Some.Package2.2.0.1\lib\net8.0\Some.Package2.dll</HintPath>
|
1175
|
-
<Private>True</Private>
|
1176
|
-
</Reference>
|
1177
|
-
</ItemGroup>
|
1178
|
-
</Project>
|
1179
|
-
""");
|
1180
|
-
var packagesConfigPath = Path.Join(Path.GetDirectoryName(projectPath)!, "packages.config");
|
1181
|
-
await File.WriteAllTextAsync(packagesConfigPath, """
|
1182
|
-
<?xml version="1.0" encoding="utf-8"?>
|
1183
|
-
<packages>
|
1184
|
-
<package id="Some.Package2" version="2.0.1" targetFramework="net8.0" />
|
1185
|
-
</packages>
|
1186
|
-
""");
|
1187
|
-
break;
|
1188
|
-
default:
|
1189
|
-
throw new NotSupportedException();
|
1190
|
-
}
|
1191
|
-
|
1192
|
-
return new UpdateOperationResult()
|
1193
|
-
{
|
1194
|
-
UpdateOperations = [
|
1195
|
-
new DirectUpdate()
|
1196
|
-
{
|
1197
|
-
DependencyName = packageName,
|
1198
|
-
NewVersion = NuGetVersion.Parse(newVersion),
|
1199
|
-
UpdatedFiles = [filePath]
|
1200
|
-
}
|
1201
|
-
],
|
1202
|
-
};
|
1203
|
-
}),
|
1204
|
-
expectedResult: new RunResult()
|
1205
|
-
{
|
1206
|
-
Base64DependencyFiles =
|
1207
|
-
[
|
1208
|
-
new DependencyFile()
|
1209
|
-
{
|
1210
|
-
Directory = "/some-dir",
|
1211
|
-
Name = "packages.config",
|
1212
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("""
|
1213
|
-
<?xml version="1.0" encoding="utf-8"?>
|
1214
|
-
<packages>
|
1215
|
-
<package id="Some.Package2" version="2.0.0" targetFramework="net8.0" />
|
1216
|
-
</packages>
|
1217
|
-
""")),
|
1218
|
-
ContentEncoding = "base64"
|
1219
|
-
},
|
1220
|
-
new DependencyFile()
|
1221
|
-
{
|
1222
|
-
Directory = "/some-dir",
|
1223
|
-
Name = "project.csproj",
|
1224
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("""
|
1225
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
1226
|
-
<PropertyGroup>
|
1227
|
-
<TargetFramework>net8.0</TargetFramework>
|
1228
|
-
</PropertyGroup>
|
1229
|
-
<ItemGroup>
|
1230
|
-
<PackageReference Include="Some.Package" Version="1.0.0" />
|
1231
|
-
</ItemGroup>
|
1232
|
-
</Project>
|
1233
|
-
""")),
|
1234
|
-
ContentEncoding = "base64"
|
1235
|
-
},
|
1236
|
-
],
|
1237
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
1238
|
-
},
|
1239
|
-
expectedApiMessages:
|
1240
|
-
[
|
1241
|
-
new UpdatedDependencyList()
|
1242
|
-
{
|
1243
|
-
Dependencies =
|
1244
|
-
[
|
1245
|
-
new ReportedDependency()
|
1246
|
-
{
|
1247
|
-
Name = "Some.Package",
|
1248
|
-
Version = "1.0.0",
|
1249
|
-
Requirements =
|
1250
|
-
[
|
1251
|
-
new ReportedRequirement()
|
1252
|
-
{
|
1253
|
-
Requirement = "1.0.0",
|
1254
|
-
File = "/some-dir/project.csproj",
|
1255
|
-
Groups = ["dependencies"],
|
1256
|
-
}
|
1257
|
-
]
|
1258
|
-
},
|
1259
|
-
new ReportedDependency()
|
1260
|
-
{
|
1261
|
-
Name = "Some.Package2",
|
1262
|
-
Version = "2.0.0",
|
1263
|
-
Requirements =
|
1264
|
-
[
|
1265
|
-
new ReportedRequirement()
|
1266
|
-
{
|
1267
|
-
Requirement = "2.0.0",
|
1268
|
-
File = "/some-dir/project.csproj",
|
1269
|
-
Groups = ["dependencies"],
|
1270
|
-
}
|
1271
|
-
]
|
1272
|
-
}
|
1273
|
-
],
|
1274
|
-
DependencyFiles = ["/some-dir/packages.config", "/some-dir/project.csproj"],
|
1275
|
-
},
|
1276
|
-
new IncrementMetric()
|
1277
|
-
{
|
1278
|
-
Metric = "updater.started",
|
1279
|
-
Tags = new()
|
1280
|
-
{
|
1281
|
-
["operation"] = "group_update_all_versions"
|
1282
|
-
}
|
1283
|
-
},
|
1284
|
-
new CreatePullRequest()
|
1285
|
-
{
|
1286
|
-
Dependencies =
|
1287
|
-
[
|
1288
|
-
new ReportedDependency()
|
1289
|
-
{
|
1290
|
-
Name = "Some.Package",
|
1291
|
-
Version = "1.0.1",
|
1292
|
-
Requirements =
|
1293
|
-
[
|
1294
|
-
new ReportedRequirement()
|
1295
|
-
{
|
1296
|
-
Requirement = "1.0.1",
|
1297
|
-
File = "/some-dir/project.csproj",
|
1298
|
-
Groups = ["dependencies"],
|
1299
|
-
Source = new()
|
1300
|
-
{
|
1301
|
-
SourceUrl = "https://nuget.example.com/some-package",
|
1302
|
-
Type = "nuget_repo",
|
1303
|
-
}
|
1304
|
-
}
|
1305
|
-
],
|
1306
|
-
PreviousVersion = "1.0.0",
|
1307
|
-
PreviousRequirements =
|
1308
|
-
[
|
1309
|
-
new ReportedRequirement()
|
1310
|
-
{
|
1311
|
-
Requirement = "1.0.0",
|
1312
|
-
File = "/some-dir/project.csproj",
|
1313
|
-
Groups = ["dependencies"],
|
1314
|
-
}
|
1315
|
-
],
|
1316
|
-
},
|
1317
|
-
new ReportedDependency()
|
1318
|
-
{
|
1319
|
-
Name = "Some.Package2",
|
1320
|
-
Version = "2.0.1",
|
1321
|
-
Requirements =
|
1322
|
-
[
|
1323
|
-
new ReportedRequirement()
|
1324
|
-
{
|
1325
|
-
Requirement = "2.0.1",
|
1326
|
-
File = "/some-dir/project.csproj",
|
1327
|
-
Groups = ["dependencies"],
|
1328
|
-
Source = new()
|
1329
|
-
{
|
1330
|
-
SourceUrl = "https://nuget.example.com/some-package2",
|
1331
|
-
Type = "nuget_repo",
|
1332
|
-
}
|
1333
|
-
}
|
1334
|
-
],
|
1335
|
-
PreviousVersion = "2.0.0",
|
1336
|
-
PreviousRequirements =
|
1337
|
-
[
|
1338
|
-
new ReportedRequirement()
|
1339
|
-
{
|
1340
|
-
Requirement = "2.0.0",
|
1341
|
-
File = "/some-dir/project.csproj",
|
1342
|
-
Groups = ["dependencies"],
|
1343
|
-
}
|
1344
|
-
],
|
1345
|
-
},
|
1346
|
-
],
|
1347
|
-
UpdatedDependencyFiles =
|
1348
|
-
[
|
1349
|
-
new DependencyFile()
|
1350
|
-
{
|
1351
|
-
Name = "packages.config",
|
1352
|
-
Directory = "/some-dir",
|
1353
|
-
Content = """
|
1354
|
-
<?xml version="1.0" encoding="utf-8"?>
|
1355
|
-
<packages>
|
1356
|
-
<package id="Some.Package2" version="2.0.1" targetFramework="net8.0" />
|
1357
|
-
</packages>
|
1358
|
-
""",
|
1359
|
-
},
|
1360
|
-
new DependencyFile()
|
1361
|
-
{
|
1362
|
-
Name = "project.csproj",
|
1363
|
-
Directory = "/some-dir",
|
1364
|
-
Content = """
|
1365
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
1366
|
-
<PropertyGroup>
|
1367
|
-
<TargetFramework>net8.0</TargetFramework>
|
1368
|
-
</PropertyGroup>
|
1369
|
-
<ItemGroup>
|
1370
|
-
<PackageReference Include="Some.Package" Version="1.0.1" />
|
1371
|
-
</ItemGroup>
|
1372
|
-
<ItemGroup>
|
1373
|
-
<Reference Include="Some.Package2">
|
1374
|
-
<HintPath>..\packages\Some.Package2.2.0.1\lib\net8.0\Some.Package2.dll</HintPath>
|
1375
|
-
<Private>True</Private>
|
1376
|
-
</Reference>
|
1377
|
-
</ItemGroup>
|
1378
|
-
</Project>
|
1379
|
-
""",
|
1380
|
-
},
|
1381
|
-
],
|
1382
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
1383
|
-
CommitMessage = TestPullRequestCommitMessage,
|
1384
|
-
PrTitle = TestPullRequestTitle,
|
1385
|
-
PrBody = TestPullRequestBody,
|
1386
|
-
DependencyGroup = null,
|
1387
|
-
},
|
1388
|
-
new MarkAsProcessed("TEST-COMMIT-SHA")
|
1389
|
-
]
|
1390
|
-
);
|
1391
|
-
}
|
1392
|
-
|
1393
|
-
[Fact]
|
1394
|
-
public async Task UpdateHandlesPackagesConfigFromReferencedCsprojFiles()
|
1395
|
-
{
|
1396
|
-
var repoMetadata = XElement.Parse("""<repository type="git" url="https://nuget.example.com/some-package" />""");
|
1397
|
-
var repoMetadata2 = XElement.Parse("""<repository type="git" url="https://nuget.example.com/some-package2" />""");
|
1398
|
-
await RunAsync(
|
1399
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
1400
|
-
packages:
|
1401
|
-
[
|
1402
|
-
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0", additionalMetadata: [repoMetadata]),
|
1403
|
-
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.1", "net8.0", additionalMetadata: [repoMetadata]),
|
1404
|
-
MockNuGetPackage.CreateSimplePackage("Some.Package2", "2.0.0", "net8.0", additionalMetadata: [repoMetadata2]),
|
1405
|
-
MockNuGetPackage.CreateSimplePackage("Some.Package2", "2.0.1", "net8.0", additionalMetadata: [repoMetadata2]),
|
1406
|
-
],
|
1407
|
-
job: new Job()
|
1408
|
-
{
|
1409
|
-
PackageManager = "nuget",
|
1410
|
-
Source = new()
|
1411
|
-
{
|
1412
|
-
Provider = "github",
|
1413
|
-
Repo = "test/repo",
|
1414
|
-
Directory = "some-dir/ProjectA",
|
1415
|
-
}
|
1416
|
-
},
|
1417
|
-
files:
|
1418
|
-
[
|
1419
|
-
("some-dir/ProjectA/ProjectA.csproj", """
|
1420
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
1421
|
-
<PropertyGroup>
|
1422
|
-
<TargetFramework>net8.0</TargetFramework>
|
1423
|
-
</PropertyGroup>
|
1424
|
-
<ItemGroup>
|
1425
|
-
<PackageReference Include="Some.Package" Version="1.0.0" />
|
1426
|
-
</ItemGroup>
|
1427
|
-
<ItemGroup>
|
1428
|
-
<ProjectReference Include="../ProjectB/ProjectB.csproj" />
|
1429
|
-
</ItemGroup>
|
1430
|
-
</Project>
|
1431
|
-
"""),
|
1432
|
-
("some-dir/ProjectA/packages.config", """
|
1433
|
-
<?xml version="1.0" encoding="utf-8"?>
|
1434
|
-
<packages>
|
1435
|
-
<package id="Some.Package2" version="2.0.0" targetFramework="net8.0" />
|
1436
|
-
</packages>
|
1437
|
-
"""),
|
1438
|
-
("some-dir/ProjectB/ProjectB.csproj", """
|
1439
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
1440
|
-
<PropertyGroup>
|
1441
|
-
<TargetFramework>net8.0</TargetFramework>
|
1442
|
-
</PropertyGroup>
|
1443
|
-
<ItemGroup>
|
1444
|
-
<PackageReference Include="Some.Package" Version="1.0.0" />
|
1445
|
-
</ItemGroup>
|
1446
|
-
</Project>
|
1447
|
-
"""),
|
1448
|
-
("some-dir/ProjectB/packages.config", """
|
1449
|
-
<?xml version="1.0" encoding="utf-8"?>
|
1450
|
-
<packages>
|
1451
|
-
<package id="Some.Package2" version="2.0.0" targetFramework="net8.0" />
|
1452
|
-
</packages>
|
1453
|
-
"""),
|
1454
|
-
],
|
1455
|
-
discoveryWorker: new TestDiscoveryWorker(_input =>
|
1456
|
-
{
|
1457
|
-
return Task.FromResult(new WorkspaceDiscoveryResult()
|
1458
|
-
{
|
1459
|
-
Path = "some-dir/ProjectA",
|
1460
|
-
Projects =
|
1461
|
-
[
|
1462
|
-
new()
|
1463
|
-
{
|
1464
|
-
FilePath = "../ProjectB/ProjectB.csproj",
|
1465
|
-
TargetFrameworks = ["net8.0"],
|
1466
|
-
Dependencies =
|
1467
|
-
[
|
1468
|
-
new("Some.Package", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net8.0"]),
|
1469
|
-
new("Some.Package2", "2.0.0", DependencyType.PackagesConfig, TargetFrameworks: ["net8.0"]),
|
1470
|
-
],
|
1471
|
-
ReferencedProjectPaths = [],
|
1472
|
-
ImportedFiles = [],
|
1473
|
-
AdditionalFiles = ["packages.config"],
|
1474
|
-
},
|
1475
|
-
new()
|
1476
|
-
{
|
1477
|
-
FilePath = "ProjectA.csproj",
|
1478
|
-
TargetFrameworks = ["net8.0"],
|
1479
|
-
Dependencies =
|
1480
|
-
[
|
1481
|
-
new("Some.Package", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net8.0"]),
|
1482
|
-
new("Some.Package2", "2.0.0", DependencyType.PackagesConfig, TargetFrameworks: ["net8.0"]),
|
1483
|
-
],
|
1484
|
-
ReferencedProjectPaths = [],
|
1485
|
-
ImportedFiles = [],
|
1486
|
-
AdditionalFiles = ["packages.config"],
|
1487
|
-
}
|
1488
|
-
]
|
1489
|
-
});
|
1490
|
-
}),
|
1491
|
-
analyzeWorker: new TestAnalyzeWorker(input =>
|
1492
|
-
{
|
1493
|
-
var result = input.Item3.Name switch
|
1494
|
-
{
|
1495
|
-
"Some.Package" => new AnalysisResult()
|
1496
|
-
{
|
1497
|
-
CanUpdate = true,
|
1498
|
-
UpdatedVersion = "1.0.1",
|
1499
|
-
UpdatedDependencies =
|
1500
|
-
[
|
1501
|
-
new("Some.Package", "1.0.1", DependencyType.Unknown, TargetFrameworks: ["net8.0"], InfoUrl: "https://nuget.example.com/some-package"),
|
1502
|
-
]
|
1503
|
-
},
|
1504
|
-
"Some.Package2" => new AnalysisResult()
|
1505
|
-
{
|
1506
|
-
CanUpdate = true,
|
1507
|
-
UpdatedVersion = "2.0.1",
|
1508
|
-
UpdatedDependencies =
|
1509
|
-
[
|
1510
|
-
new("Some.Package2", "2.0.1", DependencyType.Unknown, TargetFrameworks: ["net8.0"], InfoUrl: "https://nuget.example.com/some-package2"),
|
1511
|
-
]
|
1512
|
-
},
|
1513
|
-
_ => throw new NotSupportedException(),
|
1514
|
-
};
|
1515
|
-
return Task.FromResult(result);
|
1516
|
-
}),
|
1517
|
-
updaterWorker: new TestUpdaterWorker(async input =>
|
1518
|
-
{
|
1519
|
-
var repoRootPath = input.Item1;
|
1520
|
-
var filePath = input.Item2;
|
1521
|
-
var packageName = input.Item3;
|
1522
|
-
var previousVersion = input.Item4;
|
1523
|
-
var newVersion = input.Item5;
|
1524
|
-
var _isTransitive = input.Item6;
|
1525
|
-
|
1526
|
-
var projectPath = Path.Join(repoRootPath, filePath);
|
1527
|
-
var projectName = Path.GetFileName(projectPath);
|
1528
|
-
var packagesConfigPath = Path.Join(Path.GetDirectoryName(projectPath)!, "packages.config");
|
1529
|
-
switch ((projectName, packageName))
|
1530
|
-
{
|
1531
|
-
case ("ProjectA.csproj", "Some.Package"):
|
1532
|
-
await File.WriteAllTextAsync(projectPath, """
|
1533
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
1534
|
-
<PropertyGroup>
|
1535
|
-
<TargetFramework>net8.0</TargetFramework>
|
1536
|
-
</PropertyGroup>
|
1537
|
-
<ItemGroup>
|
1538
|
-
<PackageReference Include="Some.Package" Version="1.0.1" />
|
1539
|
-
</ItemGroup>
|
1540
|
-
<ItemGroup>
|
1541
|
-
<ProjectReference Include="../ProjectB/ProjectB.csproj" />
|
1542
|
-
</ItemGroup>
|
1543
|
-
</Project>
|
1544
|
-
""");
|
1545
|
-
break;
|
1546
|
-
case ("ProjectA.csproj", "Some.Package2"):
|
1547
|
-
await File.WriteAllTextAsync(projectPath, """
|
1548
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
1549
|
-
<PropertyGroup>
|
1550
|
-
<TargetFramework>net8.0</TargetFramework>
|
1551
|
-
</PropertyGroup>
|
1552
|
-
<ItemGroup>
|
1553
|
-
<PackageReference Include="Some.Package" Version="1.0.1" />
|
1554
|
-
</ItemGroup>
|
1555
|
-
<ItemGroup>
|
1556
|
-
<ProjectReference Include="../ProjectB/ProjectB.csproj" />
|
1557
|
-
</ItemGroup>
|
1558
|
-
<ItemGroup>
|
1559
|
-
<Reference Include="Some.Package2">
|
1560
|
-
<HintPath>..\packages\Some.Package2.2.0.1\lib\net8.0\Some.Package2.dll</HintPath>
|
1561
|
-
<Private>True</Private>
|
1562
|
-
</Reference>
|
1563
|
-
</ItemGroup>
|
1564
|
-
</Project>
|
1565
|
-
""");
|
1566
|
-
await File.WriteAllTextAsync(packagesConfigPath, """
|
1567
|
-
<?xml version="1.0" encoding="utf-8"?>
|
1568
|
-
<packages>
|
1569
|
-
<package id="Some.Package2" version="2.0.1" targetFramework="net8.0" />
|
1570
|
-
</packages>
|
1571
|
-
""");
|
1572
|
-
break;
|
1573
|
-
case ("ProjectB.csproj", "Some.Package"):
|
1574
|
-
await File.WriteAllTextAsync(projectPath, """
|
1575
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
1576
|
-
<PropertyGroup>
|
1577
|
-
<TargetFramework>net8.0</TargetFramework>
|
1578
|
-
</PropertyGroup>
|
1579
|
-
<ItemGroup>
|
1580
|
-
<PackageReference Include="Some.Package" Version="1.0.1" />
|
1581
|
-
</ItemGroup>
|
1582
|
-
</Project>
|
1583
|
-
""");
|
1584
|
-
break;
|
1585
|
-
case ("ProjectB.csproj", "Some.Package2"):
|
1586
|
-
await File.WriteAllTextAsync(projectPath, """
|
1587
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
1588
|
-
<PropertyGroup>
|
1589
|
-
<TargetFramework>net8.0</TargetFramework>
|
1590
|
-
</PropertyGroup>
|
1591
|
-
<ItemGroup>
|
1592
|
-
<PackageReference Include="Some.Package" Version="1.0.1" />
|
1593
|
-
</ItemGroup>
|
1594
|
-
<ItemGroup>
|
1595
|
-
<Reference Include="Some.Package2">
|
1596
|
-
<HintPath>..\packages\Some.Package2.2.0.1\lib\net8.0\Some.Package2.dll</HintPath>
|
1597
|
-
<Private>True</Private>
|
1598
|
-
</Reference>
|
1599
|
-
</ItemGroup>
|
1600
|
-
</Project>
|
1601
|
-
""");
|
1602
|
-
await File.WriteAllTextAsync(packagesConfigPath, """
|
1603
|
-
<?xml version="1.0" encoding="utf-8"?>
|
1604
|
-
<packages>
|
1605
|
-
<package id="Some.Package2" version="2.0.1" targetFramework="net8.0" />
|
1606
|
-
</packages>
|
1607
|
-
""");
|
1608
|
-
break;
|
1609
|
-
default:
|
1610
|
-
throw new NotSupportedException();
|
1611
|
-
}
|
1612
|
-
|
1613
|
-
return new UpdateOperationResult()
|
1614
|
-
{
|
1615
|
-
UpdateOperations = [
|
1616
|
-
new DirectUpdate()
|
1617
|
-
{
|
1618
|
-
DependencyName = packageName,
|
1619
|
-
NewVersion = NuGetVersion.Parse(newVersion),
|
1620
|
-
UpdatedFiles = [filePath]
|
1621
|
-
}
|
1622
|
-
],
|
1623
|
-
};
|
1624
|
-
}),
|
1625
|
-
expectedResult: new RunResult()
|
1626
|
-
{
|
1627
|
-
Base64DependencyFiles =
|
1628
|
-
[
|
1629
|
-
new DependencyFile()
|
1630
|
-
{
|
1631
|
-
Directory = "/some-dir/ProjectA",
|
1632
|
-
Name = "packages.config",
|
1633
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("""
|
1634
|
-
<?xml version="1.0" encoding="utf-8"?>
|
1635
|
-
<packages>
|
1636
|
-
<package id="Some.Package2" version="2.0.0" targetFramework="net8.0" />
|
1637
|
-
</packages>
|
1638
|
-
""")),
|
1639
|
-
ContentEncoding = "base64"
|
1640
|
-
},
|
1641
|
-
new DependencyFile()
|
1642
|
-
{
|
1643
|
-
Directory = "/some-dir/ProjectA",
|
1644
|
-
Name = "ProjectA.csproj",
|
1645
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("""
|
1646
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
1647
|
-
<PropertyGroup>
|
1648
|
-
<TargetFramework>net8.0</TargetFramework>
|
1649
|
-
</PropertyGroup>
|
1650
|
-
<ItemGroup>
|
1651
|
-
<PackageReference Include="Some.Package" Version="1.0.0" />
|
1652
|
-
</ItemGroup>
|
1653
|
-
<ItemGroup>
|
1654
|
-
<ProjectReference Include="../ProjectB/ProjectB.csproj" />
|
1655
|
-
</ItemGroup>
|
1656
|
-
</Project>
|
1657
|
-
""")),
|
1658
|
-
ContentEncoding = "base64"
|
1659
|
-
},
|
1660
|
-
new DependencyFile()
|
1661
|
-
{
|
1662
|
-
Directory = "/some-dir/ProjectB",
|
1663
|
-
Name = "packages.config",
|
1664
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("""
|
1665
|
-
<?xml version="1.0" encoding="utf-8"?>
|
1666
|
-
<packages>
|
1667
|
-
<package id="Some.Package2" version="2.0.0" targetFramework="net8.0" />
|
1668
|
-
</packages>
|
1669
|
-
""")),
|
1670
|
-
ContentEncoding = "base64"
|
1671
|
-
},
|
1672
|
-
new DependencyFile()
|
1673
|
-
{
|
1674
|
-
Directory = "/some-dir/ProjectB",
|
1675
|
-
Name = "ProjectB.csproj",
|
1676
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("""
|
1677
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
1678
|
-
<PropertyGroup>
|
1679
|
-
<TargetFramework>net8.0</TargetFramework>
|
1680
|
-
</PropertyGroup>
|
1681
|
-
<ItemGroup>
|
1682
|
-
<PackageReference Include="Some.Package" Version="1.0.0" />
|
1683
|
-
</ItemGroup>
|
1684
|
-
</Project>
|
1685
|
-
""")),
|
1686
|
-
ContentEncoding = "base64"
|
1687
|
-
},
|
1688
|
-
],
|
1689
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
1690
|
-
},
|
1691
|
-
expectedApiMessages:
|
1692
|
-
[
|
1693
|
-
new UpdatedDependencyList()
|
1694
|
-
{
|
1695
|
-
Dependencies =
|
1696
|
-
[
|
1697
|
-
new ReportedDependency()
|
1698
|
-
{
|
1699
|
-
Name = "Some.Package",
|
1700
|
-
Version = "1.0.0",
|
1701
|
-
Requirements =
|
1702
|
-
[
|
1703
|
-
new ReportedRequirement()
|
1704
|
-
{
|
1705
|
-
Requirement = "1.0.0",
|
1706
|
-
File = "/some-dir/ProjectA/ProjectA.csproj",
|
1707
|
-
Groups = ["dependencies"],
|
1708
|
-
}
|
1709
|
-
]
|
1710
|
-
},
|
1711
|
-
new ReportedDependency()
|
1712
|
-
{
|
1713
|
-
Name = "Some.Package2",
|
1714
|
-
Version = "2.0.0",
|
1715
|
-
Requirements =
|
1716
|
-
[
|
1717
|
-
new ReportedRequirement()
|
1718
|
-
{
|
1719
|
-
Requirement = "2.0.0",
|
1720
|
-
File = "/some-dir/ProjectA/ProjectA.csproj",
|
1721
|
-
Groups = ["dependencies"],
|
1722
|
-
}
|
1723
|
-
]
|
1724
|
-
},
|
1725
|
-
new ReportedDependency()
|
1726
|
-
{
|
1727
|
-
Name = "Some.Package",
|
1728
|
-
Version = "1.0.0",
|
1729
|
-
Requirements =
|
1730
|
-
[
|
1731
|
-
new ReportedRequirement()
|
1732
|
-
{
|
1733
|
-
Requirement = "1.0.0",
|
1734
|
-
File = "/some-dir/ProjectB/ProjectB.csproj",
|
1735
|
-
Groups = ["dependencies"],
|
1736
|
-
}
|
1737
|
-
]
|
1738
|
-
},
|
1739
|
-
new ReportedDependency()
|
1740
|
-
{
|
1741
|
-
Name = "Some.Package2",
|
1742
|
-
Version = "2.0.0",
|
1743
|
-
Requirements =
|
1744
|
-
[
|
1745
|
-
new ReportedRequirement()
|
1746
|
-
{
|
1747
|
-
Requirement = "2.0.0",
|
1748
|
-
File = "/some-dir/ProjectB/ProjectB.csproj",
|
1749
|
-
Groups = ["dependencies"],
|
1750
|
-
}
|
1751
|
-
]
|
1752
|
-
},
|
1753
|
-
],
|
1754
|
-
DependencyFiles = ["/some-dir/ProjectA/packages.config", "/some-dir/ProjectA/ProjectA.csproj", "/some-dir/ProjectB/packages.config", "/some-dir/ProjectB/ProjectB.csproj"],
|
1755
|
-
},
|
1756
|
-
new IncrementMetric()
|
1757
|
-
{
|
1758
|
-
Metric = "updater.started",
|
1759
|
-
Tags = new()
|
1760
|
-
{
|
1761
|
-
["operation"] = "group_update_all_versions"
|
1762
|
-
}
|
1763
|
-
},
|
1764
|
-
new CreatePullRequest()
|
1765
|
-
{
|
1766
|
-
Dependencies =
|
1767
|
-
[
|
1768
|
-
new ReportedDependency()
|
1769
|
-
{
|
1770
|
-
Name = "Some.Package",
|
1771
|
-
Version = "1.0.1",
|
1772
|
-
Requirements =
|
1773
|
-
[
|
1774
|
-
new ReportedRequirement()
|
1775
|
-
{
|
1776
|
-
Requirement = "1.0.1",
|
1777
|
-
File = "/some-dir/ProjectA/ProjectA.csproj",
|
1778
|
-
Groups = ["dependencies"],
|
1779
|
-
Source = new()
|
1780
|
-
{
|
1781
|
-
SourceUrl = "https://nuget.example.com/some-package",
|
1782
|
-
Type = "nuget_repo",
|
1783
|
-
}
|
1784
|
-
}
|
1785
|
-
],
|
1786
|
-
PreviousVersion = "1.0.0",
|
1787
|
-
PreviousRequirements =
|
1788
|
-
[
|
1789
|
-
new ReportedRequirement()
|
1790
|
-
{
|
1791
|
-
Requirement = "1.0.0",
|
1792
|
-
File = "/some-dir/ProjectA/ProjectA.csproj",
|
1793
|
-
Groups = ["dependencies"],
|
1794
|
-
}
|
1795
|
-
],
|
1796
|
-
},
|
1797
|
-
new ReportedDependency()
|
1798
|
-
{
|
1799
|
-
Name = "Some.Package",
|
1800
|
-
Version = "1.0.1",
|
1801
|
-
Requirements =
|
1802
|
-
[
|
1803
|
-
new ReportedRequirement()
|
1804
|
-
{
|
1805
|
-
Requirement = "1.0.1",
|
1806
|
-
File = "/some-dir/ProjectB/ProjectB.csproj",
|
1807
|
-
Groups = ["dependencies"],
|
1808
|
-
Source = new()
|
1809
|
-
{
|
1810
|
-
SourceUrl = "https://nuget.example.com/some-package",
|
1811
|
-
Type = "nuget_repo",
|
1812
|
-
}
|
1813
|
-
}
|
1814
|
-
],
|
1815
|
-
PreviousVersion = "1.0.0",
|
1816
|
-
PreviousRequirements =
|
1817
|
-
[
|
1818
|
-
new ReportedRequirement()
|
1819
|
-
{
|
1820
|
-
Requirement = "1.0.0",
|
1821
|
-
File = "/some-dir/ProjectB/ProjectB.csproj",
|
1822
|
-
Groups = ["dependencies"],
|
1823
|
-
}
|
1824
|
-
],
|
1825
|
-
},
|
1826
|
-
new ReportedDependency()
|
1827
|
-
{
|
1828
|
-
Name = "Some.Package2",
|
1829
|
-
Version = "2.0.1",
|
1830
|
-
Requirements =
|
1831
|
-
[
|
1832
|
-
new ReportedRequirement()
|
1833
|
-
{
|
1834
|
-
Requirement = "2.0.1",
|
1835
|
-
File = "/some-dir/ProjectA/ProjectA.csproj",
|
1836
|
-
Groups = ["dependencies"],
|
1837
|
-
Source = new()
|
1838
|
-
{
|
1839
|
-
SourceUrl = "https://nuget.example.com/some-package2",
|
1840
|
-
Type = "nuget_repo",
|
1841
|
-
}
|
1842
|
-
}
|
1843
|
-
],
|
1844
|
-
PreviousVersion = "2.0.0",
|
1845
|
-
PreviousRequirements =
|
1846
|
-
[
|
1847
|
-
new ReportedRequirement()
|
1848
|
-
{
|
1849
|
-
Requirement = "2.0.0",
|
1850
|
-
File = "/some-dir/ProjectA/ProjectA.csproj",
|
1851
|
-
Groups = ["dependencies"],
|
1852
|
-
}
|
1853
|
-
],
|
1854
|
-
},
|
1855
|
-
new ReportedDependency()
|
1856
|
-
{
|
1857
|
-
Name = "Some.Package2",
|
1858
|
-
Version = "2.0.1",
|
1859
|
-
Requirements =
|
1860
|
-
[
|
1861
|
-
new ReportedRequirement()
|
1862
|
-
{
|
1863
|
-
Requirement = "2.0.1",
|
1864
|
-
File = "/some-dir/ProjectB/ProjectB.csproj",
|
1865
|
-
Groups = ["dependencies"],
|
1866
|
-
Source = new()
|
1867
|
-
{
|
1868
|
-
SourceUrl = "https://nuget.example.com/some-package2",
|
1869
|
-
Type = "nuget_repo",
|
1870
|
-
}
|
1871
|
-
}
|
1872
|
-
],
|
1873
|
-
PreviousVersion = "2.0.0",
|
1874
|
-
PreviousRequirements =
|
1875
|
-
[
|
1876
|
-
new ReportedRequirement()
|
1877
|
-
{
|
1878
|
-
Requirement = "2.0.0",
|
1879
|
-
File = "/some-dir/ProjectB/ProjectB.csproj",
|
1880
|
-
Groups = ["dependencies"],
|
1881
|
-
}
|
1882
|
-
],
|
1883
|
-
},
|
1884
|
-
],
|
1885
|
-
UpdatedDependencyFiles =
|
1886
|
-
[
|
1887
|
-
new DependencyFile()
|
1888
|
-
{
|
1889
|
-
Name = "packages.config",
|
1890
|
-
Directory = "/some-dir/ProjectA",
|
1891
|
-
Content = """
|
1892
|
-
<?xml version="1.0" encoding="utf-8"?>
|
1893
|
-
<packages>
|
1894
|
-
<package id="Some.Package2" version="2.0.1" targetFramework="net8.0" />
|
1895
|
-
</packages>
|
1896
|
-
""",
|
1897
|
-
},
|
1898
|
-
new DependencyFile()
|
1899
|
-
{
|
1900
|
-
Name = "ProjectA.csproj",
|
1901
|
-
Directory = "/some-dir/ProjectA",
|
1902
|
-
Content = """
|
1903
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
1904
|
-
<PropertyGroup>
|
1905
|
-
<TargetFramework>net8.0</TargetFramework>
|
1906
|
-
</PropertyGroup>
|
1907
|
-
<ItemGroup>
|
1908
|
-
<PackageReference Include="Some.Package" Version="1.0.1" />
|
1909
|
-
</ItemGroup>
|
1910
|
-
<ItemGroup>
|
1911
|
-
<ProjectReference Include="../ProjectB/ProjectB.csproj" />
|
1912
|
-
</ItemGroup>
|
1913
|
-
<ItemGroup>
|
1914
|
-
<Reference Include="Some.Package2">
|
1915
|
-
<HintPath>..\packages\Some.Package2.2.0.1\lib\net8.0\Some.Package2.dll</HintPath>
|
1916
|
-
<Private>True</Private>
|
1917
|
-
</Reference>
|
1918
|
-
</ItemGroup>
|
1919
|
-
</Project>
|
1920
|
-
""",
|
1921
|
-
},
|
1922
|
-
new DependencyFile()
|
1923
|
-
{
|
1924
|
-
Name = "packages.config",
|
1925
|
-
Directory = "/some-dir/ProjectB",
|
1926
|
-
Content = """
|
1927
|
-
<?xml version="1.0" encoding="utf-8"?>
|
1928
|
-
<packages>
|
1929
|
-
<package id="Some.Package2" version="2.0.1" targetFramework="net8.0" />
|
1930
|
-
</packages>
|
1931
|
-
""",
|
1932
|
-
},
|
1933
|
-
new DependencyFile()
|
1934
|
-
{
|
1935
|
-
Name = "ProjectB.csproj",
|
1936
|
-
Directory = "/some-dir/ProjectB",
|
1937
|
-
Content = """
|
1938
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
1939
|
-
<PropertyGroup>
|
1940
|
-
<TargetFramework>net8.0</TargetFramework>
|
1941
|
-
</PropertyGroup>
|
1942
|
-
<ItemGroup>
|
1943
|
-
<PackageReference Include="Some.Package" Version="1.0.1" />
|
1944
|
-
</ItemGroup>
|
1945
|
-
<ItemGroup>
|
1946
|
-
<Reference Include="Some.Package2">
|
1947
|
-
<HintPath>..\packages\Some.Package2.2.0.1\lib\net8.0\Some.Package2.dll</HintPath>
|
1948
|
-
<Private>True</Private>
|
1949
|
-
</Reference>
|
1950
|
-
</ItemGroup>
|
1951
|
-
</Project>
|
1952
|
-
""",
|
1953
|
-
},
|
1954
|
-
],
|
1955
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
1956
|
-
CommitMessage = TestPullRequestCommitMessage,
|
1957
|
-
PrTitle = TestPullRequestTitle,
|
1958
|
-
PrBody = TestPullRequestBody,
|
1959
|
-
DependencyGroup = null,
|
1960
|
-
},
|
1961
|
-
new MarkAsProcessed("TEST-COMMIT-SHA")
|
1962
|
-
]
|
1963
|
-
);
|
1964
|
-
}
|
1965
|
-
|
1966
|
-
[Fact]
|
1967
|
-
public async Task UpdatedFilesAreOnlyReportedOnce()
|
1968
|
-
{
|
1969
|
-
await RunAsync(
|
1970
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
1971
|
-
job: new()
|
1972
|
-
{
|
1973
|
-
PackageManager = "nuget",
|
1974
|
-
Source = new()
|
1975
|
-
{
|
1976
|
-
Provider = "github",
|
1977
|
-
Repo = "test/repo",
|
1978
|
-
Directory = "/",
|
1979
|
-
}
|
1980
|
-
},
|
1981
|
-
packages:
|
1982
|
-
[
|
1983
|
-
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0"),
|
1984
|
-
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.1.0", "net8.0"),
|
1985
|
-
],
|
1986
|
-
files:
|
1987
|
-
[
|
1988
|
-
("dirs.proj", """
|
1989
|
-
<Project>
|
1990
|
-
<ItemGroup>
|
1991
|
-
<ProjectFile Include="project1/project1.csproj" />
|
1992
|
-
<ProjectFile Include="project2/project2.csproj" />
|
1993
|
-
</ItemGroup>
|
1994
|
-
</Project>
|
1995
|
-
"""),
|
1996
|
-
("Directory.Build.props", """
|
1997
|
-
<Project>
|
1998
|
-
<PropertyGroup>
|
1999
|
-
<SomePackageVersion>1.0.0</SomePackageVersion>
|
2000
|
-
</PropertyGroup>
|
2001
|
-
</Project>
|
2002
|
-
"""),
|
2003
|
-
("project1/project1.csproj", """
|
2004
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
2005
|
-
<PropertyGroup>
|
2006
|
-
<TargetFramework>net8.0</TargetFramework>
|
2007
|
-
</PropertyGroup>
|
2008
|
-
<ItemGroup>
|
2009
|
-
<PackageReference Include="Some.Package" Version="$(SomePackageVersion)" />
|
2010
|
-
</ItemGroup>
|
2011
|
-
</Project>
|
2012
|
-
"""),
|
2013
|
-
("project2/project2.csproj", """
|
2014
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
2015
|
-
<PropertyGroup>
|
2016
|
-
<TargetFramework>net8.0</TargetFramework>
|
2017
|
-
</PropertyGroup>
|
2018
|
-
<ItemGroup>
|
2019
|
-
<PackageReference Include="Some.Package" Version="$(SomePackageVersion)" />
|
2020
|
-
</ItemGroup>
|
2021
|
-
</Project>
|
2022
|
-
""")
|
2023
|
-
],
|
2024
|
-
discoveryWorker: new TestDiscoveryWorker(_input =>
|
2025
|
-
{
|
2026
|
-
return Task.FromResult(new WorkspaceDiscoveryResult()
|
2027
|
-
{
|
2028
|
-
Path = "",
|
2029
|
-
Projects = [
|
2030
|
-
new()
|
2031
|
-
{
|
2032
|
-
FilePath = "project1/project1.csproj",
|
2033
|
-
TargetFrameworks = ["net8.0"],
|
2034
|
-
Dependencies = [
|
2035
|
-
new("Some.Package", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net8.0"]),
|
2036
|
-
],
|
2037
|
-
ReferencedProjectPaths = [],
|
2038
|
-
ImportedFiles = [
|
2039
|
-
"../Directory.Build.props",
|
2040
|
-
],
|
2041
|
-
AdditionalFiles = [],
|
2042
|
-
},
|
2043
|
-
new()
|
2044
|
-
{
|
2045
|
-
FilePath = "project2/project2.csproj",
|
2046
|
-
TargetFrameworks = ["net8.0"],
|
2047
|
-
Dependencies = [
|
2048
|
-
new("Some.Package", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net8.0"]),
|
2049
|
-
],
|
2050
|
-
ReferencedProjectPaths = [],
|
2051
|
-
ImportedFiles = [
|
2052
|
-
"../Directory.Build.props",
|
2053
|
-
],
|
2054
|
-
AdditionalFiles = [],
|
2055
|
-
},
|
2056
|
-
]
|
2057
|
-
});
|
2058
|
-
}),
|
2059
|
-
analyzeWorker: new TestAnalyzeWorker(_input =>
|
2060
|
-
{
|
2061
|
-
return Task.FromResult(new AnalysisResult()
|
2062
|
-
{
|
2063
|
-
CanUpdate = true,
|
2064
|
-
UpdatedVersion = "1.1.0",
|
2065
|
-
UpdatedDependencies =
|
2066
|
-
[
|
2067
|
-
new("Some.Package", "1.1.0", DependencyType.Unknown, TargetFrameworks: ["net8.0"]),
|
2068
|
-
]
|
2069
|
-
});
|
2070
|
-
}),
|
2071
|
-
updaterWorker: new TestUpdaterWorker(async input =>
|
2072
|
-
{
|
2073
|
-
var repoRootPath = input.Item1;
|
2074
|
-
var filePath = input.Item2;
|
2075
|
-
var packageName = input.Item3;
|
2076
|
-
var previousVersion = input.Item4;
|
2077
|
-
var newVersion = input.Item5;
|
2078
|
-
var _isTransitive = input.Item6;
|
2079
|
-
|
2080
|
-
var directoryBuildPropsPath = Path.Join(repoRootPath, "Directory.Build.props");
|
2081
|
-
await File.WriteAllTextAsync(directoryBuildPropsPath, """
|
2082
|
-
<Project>
|
2083
|
-
<PropertyGroup>
|
2084
|
-
<SomePackageVersion>1.1.0</SomePackageVersion>
|
2085
|
-
</PropertyGroup>
|
2086
|
-
</Project>
|
2087
|
-
""");
|
2088
|
-
return new UpdateOperationResult()
|
2089
|
-
{
|
2090
|
-
UpdateOperations = [
|
2091
|
-
new DirectUpdate()
|
2092
|
-
{
|
2093
|
-
DependencyName = packageName,
|
2094
|
-
NewVersion = NuGetVersion.Parse(newVersion),
|
2095
|
-
UpdatedFiles = [filePath]
|
2096
|
-
}
|
2097
|
-
],
|
2098
|
-
};
|
2099
|
-
}),
|
2100
|
-
expectedResult: new RunResult()
|
2101
|
-
{
|
2102
|
-
Base64DependencyFiles =
|
2103
|
-
[
|
2104
|
-
new DependencyFile()
|
2105
|
-
{
|
2106
|
-
Directory = "/",
|
2107
|
-
Name = "Directory.Build.props",
|
2108
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("""
|
2109
|
-
<Project>
|
2110
|
-
<PropertyGroup>
|
2111
|
-
<SomePackageVersion>1.0.0</SomePackageVersion>
|
2112
|
-
</PropertyGroup>
|
2113
|
-
</Project>
|
2114
|
-
""")),
|
2115
|
-
ContentEncoding = "base64"
|
2116
|
-
},
|
2117
|
-
new DependencyFile()
|
2118
|
-
{
|
2119
|
-
Directory = "/project1",
|
2120
|
-
Name = "project1.csproj",
|
2121
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("""
|
2122
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
2123
|
-
<PropertyGroup>
|
2124
|
-
<TargetFramework>net8.0</TargetFramework>
|
2125
|
-
</PropertyGroup>
|
2126
|
-
<ItemGroup>
|
2127
|
-
<PackageReference Include="Some.Package" Version="$(SomePackageVersion)" />
|
2128
|
-
</ItemGroup>
|
2129
|
-
</Project>
|
2130
|
-
""")),
|
2131
|
-
ContentEncoding = "base64"
|
2132
|
-
},
|
2133
|
-
new DependencyFile()
|
2134
|
-
{
|
2135
|
-
Directory = "/project2",
|
2136
|
-
Name = "project2.csproj",
|
2137
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("""
|
2138
|
-
<Project Sdk="Microsoft.NET.Sdk">
|
2139
|
-
<PropertyGroup>
|
2140
|
-
<TargetFramework>net8.0</TargetFramework>
|
2141
|
-
</PropertyGroup>
|
2142
|
-
<ItemGroup>
|
2143
|
-
<PackageReference Include="Some.Package" Version="$(SomePackageVersion)" />
|
2144
|
-
</ItemGroup>
|
2145
|
-
</Project>
|
2146
|
-
""")),
|
2147
|
-
ContentEncoding = "base64"
|
2148
|
-
},
|
2149
|
-
],
|
2150
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
2151
|
-
},
|
2152
|
-
expectedApiMessages:
|
2153
|
-
[
|
2154
|
-
new UpdatedDependencyList()
|
2155
|
-
{
|
2156
|
-
Dependencies =
|
2157
|
-
[
|
2158
|
-
new ReportedDependency()
|
2159
|
-
{
|
2160
|
-
Name = "Some.Package",
|
2161
|
-
Version = "1.0.0",
|
2162
|
-
Requirements =
|
2163
|
-
[
|
2164
|
-
new ReportedRequirement()
|
2165
|
-
{
|
2166
|
-
Requirement = "1.0.0",
|
2167
|
-
File = "/project1/project1.csproj",
|
2168
|
-
Groups = ["dependencies"],
|
2169
|
-
}
|
2170
|
-
]
|
2171
|
-
},
|
2172
|
-
new ReportedDependency()
|
2173
|
-
{
|
2174
|
-
Name = "Some.Package",
|
2175
|
-
Version = "1.0.0",
|
2176
|
-
Requirements =
|
2177
|
-
[
|
2178
|
-
new ReportedRequirement()
|
2179
|
-
{
|
2180
|
-
Requirement = "1.0.0",
|
2181
|
-
File = "/project2/project2.csproj",
|
2182
|
-
Groups = ["dependencies"],
|
2183
|
-
}
|
2184
|
-
]
|
2185
|
-
}
|
2186
|
-
],
|
2187
|
-
DependencyFiles = ["/Directory.Build.props", "/project1/project1.csproj", "/project2/project2.csproj"],
|
2188
|
-
},
|
2189
|
-
new IncrementMetric()
|
2190
|
-
{
|
2191
|
-
Metric = "updater.started",
|
2192
|
-
Tags = new()
|
2193
|
-
{
|
2194
|
-
["operation"] = "group_update_all_versions"
|
2195
|
-
}
|
2196
|
-
},
|
2197
|
-
new CreatePullRequest()
|
2198
|
-
{
|
2199
|
-
Dependencies =
|
2200
|
-
[
|
2201
|
-
new ReportedDependency()
|
2202
|
-
{
|
2203
|
-
Name = "Some.Package",
|
2204
|
-
Version = "1.1.0",
|
2205
|
-
Requirements =
|
2206
|
-
[
|
2207
|
-
new ReportedRequirement()
|
2208
|
-
{
|
2209
|
-
Requirement = "1.1.0",
|
2210
|
-
File = "/project1/project1.csproj",
|
2211
|
-
Groups = ["dependencies"],
|
2212
|
-
Source = new()
|
2213
|
-
{
|
2214
|
-
SourceUrl = null,
|
2215
|
-
Type = "nuget_repo",
|
2216
|
-
}
|
2217
|
-
}
|
2218
|
-
],
|
2219
|
-
PreviousVersion = "1.0.0",
|
2220
|
-
PreviousRequirements =
|
2221
|
-
[
|
2222
|
-
new ReportedRequirement()
|
2223
|
-
{
|
2224
|
-
Requirement = "1.0.0",
|
2225
|
-
File = "/project1/project1.csproj",
|
2226
|
-
Groups = ["dependencies"],
|
2227
|
-
}
|
2228
|
-
],
|
2229
|
-
},
|
2230
|
-
new ReportedDependency()
|
2231
|
-
{
|
2232
|
-
Name = "Some.Package",
|
2233
|
-
Version = "1.1.0",
|
2234
|
-
Requirements =
|
2235
|
-
[
|
2236
|
-
new ReportedRequirement()
|
2237
|
-
{
|
2238
|
-
Requirement = "1.1.0",
|
2239
|
-
File = "/project2/project2.csproj",
|
2240
|
-
Groups = ["dependencies"],
|
2241
|
-
Source = new()
|
2242
|
-
{
|
2243
|
-
SourceUrl = null,
|
2244
|
-
Type = "nuget_repo",
|
2245
|
-
}
|
2246
|
-
}
|
2247
|
-
],
|
2248
|
-
PreviousVersion = "1.0.0",
|
2249
|
-
PreviousRequirements =
|
2250
|
-
[
|
2251
|
-
new ReportedRequirement()
|
2252
|
-
{
|
2253
|
-
Requirement = "1.0.0",
|
2254
|
-
File = "/project2/project2.csproj",
|
2255
|
-
Groups = ["dependencies"],
|
2256
|
-
}
|
2257
|
-
],
|
2258
|
-
},
|
2259
|
-
],
|
2260
|
-
UpdatedDependencyFiles =
|
2261
|
-
[
|
2262
|
-
new DependencyFile()
|
2263
|
-
{
|
2264
|
-
Name = "Directory.Build.props",
|
2265
|
-
Directory = "/",
|
2266
|
-
Content = """
|
2267
|
-
<Project>
|
2268
|
-
<PropertyGroup>
|
2269
|
-
<SomePackageVersion>1.1.0</SomePackageVersion>
|
2270
|
-
</PropertyGroup>
|
2271
|
-
</Project>
|
2272
|
-
""",
|
2273
|
-
}
|
2274
|
-
],
|
2275
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
2276
|
-
CommitMessage = TestPullRequestCommitMessage,
|
2277
|
-
PrTitle = TestPullRequestTitle,
|
2278
|
-
PrBody = TestPullRequestBody,
|
2279
|
-
DependencyGroup = null,
|
2280
|
-
},
|
2281
|
-
new MarkAsProcessed("TEST-COMMIT-SHA")
|
2282
|
-
]
|
2283
|
-
);
|
2284
|
-
}
|
2285
|
-
|
2286
|
-
[Fact]
|
2287
|
-
public async Task PackageListedInSecurityAdvisoriesSectionIsNotVulnerable()
|
2288
|
-
{
|
2289
|
-
await RunAsync(
|
2290
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
2291
|
-
job: new()
|
2292
|
-
{
|
2293
|
-
Source = new()
|
2294
|
-
{
|
2295
|
-
Provider = "github",
|
2296
|
-
Repo = "test/repo",
|
2297
|
-
},
|
2298
|
-
SecurityUpdatesOnly = true,
|
2299
|
-
SecurityAdvisories = [
|
2300
|
-
new()
|
2301
|
-
{
|
2302
|
-
DependencyName = "Package.Is.Not.Vulnerable",
|
2303
|
-
AffectedVersions = [Requirement.Parse("< 1.0.0")]
|
2304
|
-
}
|
2305
|
-
]
|
2306
|
-
},
|
2307
|
-
files: [
|
2308
|
-
("project.csproj", "contents irrelevant")
|
2309
|
-
],
|
2310
|
-
discoveryWorker: new TestDiscoveryWorker(_input =>
|
2311
|
-
{
|
2312
|
-
return Task.FromResult(new WorkspaceDiscoveryResult()
|
2313
|
-
{
|
2314
|
-
Path = "",
|
2315
|
-
Projects = [
|
2316
|
-
new()
|
2317
|
-
{
|
2318
|
-
FilePath = "project.csproj",
|
2319
|
-
Dependencies = [
|
2320
|
-
new("Package.Is.Not.Vulnerable", "1.0.1", DependencyType.PackageReference)
|
2321
|
-
],
|
2322
|
-
ImportedFiles = [],
|
2323
|
-
AdditionalFiles = [],
|
2324
|
-
}
|
2325
|
-
]
|
2326
|
-
});
|
2327
|
-
}),
|
2328
|
-
analyzeWorker: new TestAnalyzeWorker(_input => throw new NotImplementedException("test shouldn't get this far")),
|
2329
|
-
updaterWorker: new TestUpdaterWorker(_input => throw new NotImplementedException("test shouldn't get this far")),
|
2330
|
-
expectedResult: new()
|
2331
|
-
{
|
2332
|
-
Base64DependencyFiles = [
|
2333
|
-
new()
|
2334
|
-
{
|
2335
|
-
Directory = "/",
|
2336
|
-
Name = "project.csproj",
|
2337
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("contents irrelevant")),
|
2338
|
-
ContentEncoding = "base64"
|
2339
|
-
}
|
2340
|
-
],
|
2341
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
2342
|
-
},
|
2343
|
-
expectedApiMessages: [
|
2344
|
-
new UpdatedDependencyList()
|
2345
|
-
{
|
2346
|
-
Dependencies = [
|
2347
|
-
new()
|
2348
|
-
{
|
2349
|
-
Name = "Package.Is.Not.Vulnerable",
|
2350
|
-
Version = "1.0.1",
|
2351
|
-
Requirements = [
|
2352
|
-
new()
|
2353
|
-
{
|
2354
|
-
Requirement = "1.0.1",
|
2355
|
-
File = "/project.csproj",
|
2356
|
-
Groups = ["dependencies"],
|
2357
|
-
}
|
2358
|
-
]
|
2359
|
-
}
|
2360
|
-
],
|
2361
|
-
DependencyFiles = ["/project.csproj"]
|
2362
|
-
},
|
2363
|
-
new IncrementMetric()
|
2364
|
-
{
|
2365
|
-
Metric = "updater.started",
|
2366
|
-
Tags = new()
|
2367
|
-
{
|
2368
|
-
["operation"] = "create_security_pr"
|
2369
|
-
}
|
2370
|
-
},
|
2371
|
-
new SecurityUpdateNotNeeded("Package.Is.Not.Vulnerable"),
|
2372
|
-
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
2373
|
-
]
|
2374
|
-
);
|
2375
|
-
}
|
2376
|
-
|
2377
|
-
[Fact]
|
2378
|
-
public async Task PackageListedInSecurityAdvisoriesSectionIsNotPresent()
|
2379
|
-
{
|
2380
|
-
await RunAsync(
|
2381
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
2382
|
-
job: new()
|
2383
|
-
{
|
2384
|
-
Source = new()
|
2385
|
-
{
|
2386
|
-
Provider = "github",
|
2387
|
-
Repo = "test/repo",
|
2388
|
-
},
|
2389
|
-
SecurityUpdatesOnly = true,
|
2390
|
-
SecurityAdvisories = [
|
2391
|
-
new()
|
2392
|
-
{
|
2393
|
-
DependencyName = "Package.Is.Not.Vulnerable",
|
2394
|
-
AffectedVersions = [Requirement.Parse("< 1.0.0")]
|
2395
|
-
}
|
2396
|
-
]
|
2397
|
-
},
|
2398
|
-
files: [
|
2399
|
-
("project.csproj", "contents irrelevant")
|
2400
|
-
],
|
2401
|
-
discoveryWorker: new TestDiscoveryWorker(_input =>
|
2402
|
-
{
|
2403
|
-
return Task.FromResult(new WorkspaceDiscoveryResult()
|
2404
|
-
{
|
2405
|
-
Path = "",
|
2406
|
-
Projects = [
|
2407
|
-
new()
|
2408
|
-
{
|
2409
|
-
FilePath = "project.csproj",
|
2410
|
-
Dependencies = [
|
2411
|
-
new("Unrelated.Package", "0.1.0", DependencyType.PackageReference)
|
2412
|
-
],
|
2413
|
-
ImportedFiles = [],
|
2414
|
-
AdditionalFiles = [],
|
2415
|
-
}
|
2416
|
-
]
|
2417
|
-
});
|
2418
|
-
}),
|
2419
|
-
analyzeWorker: new TestAnalyzeWorker(_input => throw new NotImplementedException("test shouldn't get this far")),
|
2420
|
-
updaterWorker: new TestUpdaterWorker(_input => throw new NotImplementedException("test shouldn't get this far")),
|
2421
|
-
expectedResult: new()
|
2422
|
-
{
|
2423
|
-
Base64DependencyFiles = [
|
2424
|
-
new()
|
2425
|
-
{
|
2426
|
-
Directory = "/",
|
2427
|
-
Name = "project.csproj",
|
2428
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("contents irrelevant")),
|
2429
|
-
ContentEncoding = "base64"
|
2430
|
-
}
|
2431
|
-
],
|
2432
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
2433
|
-
},
|
2434
|
-
expectedApiMessages: [
|
2435
|
-
new UpdatedDependencyList()
|
2436
|
-
{
|
2437
|
-
Dependencies = [
|
2438
|
-
new()
|
2439
|
-
{
|
2440
|
-
Name = "Unrelated.Package",
|
2441
|
-
Version = "0.1.0",
|
2442
|
-
Requirements = [
|
2443
|
-
new()
|
2444
|
-
{
|
2445
|
-
Requirement = "0.1.0",
|
2446
|
-
File = "/project.csproj",
|
2447
|
-
Groups = ["dependencies"],
|
2448
|
-
}
|
2449
|
-
]
|
2450
|
-
}
|
2451
|
-
],
|
2452
|
-
DependencyFiles = ["/project.csproj"]
|
2453
|
-
},
|
2454
|
-
new IncrementMetric()
|
2455
|
-
{
|
2456
|
-
Metric = "updater.started",
|
2457
|
-
Tags = new()
|
2458
|
-
{
|
2459
|
-
["operation"] = "create_security_pr"
|
2460
|
-
}
|
2461
|
-
},
|
2462
|
-
new SecurityUpdateNotNeeded("Package.Is.Not.Vulnerable"),
|
2463
|
-
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
2464
|
-
]
|
2465
|
-
);
|
2466
|
-
}
|
2467
|
-
|
2468
|
-
[Fact]
|
2469
|
-
public async Task NonProjectFilesAreIncludedInPullRequest()
|
2470
|
-
{
|
2471
|
-
await RunAsync(
|
2472
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
2473
|
-
job: new()
|
2474
|
-
{
|
2475
|
-
Source = new()
|
2476
|
-
{
|
2477
|
-
Provider = "github",
|
2478
|
-
Repo = "test/repo",
|
2479
|
-
},
|
2480
|
-
},
|
2481
|
-
files: [
|
2482
|
-
(".config/dotnet-tools.json", "dotnet-tools.json content old"),
|
2483
|
-
("global.json", "global.json content old")
|
2484
|
-
],
|
2485
|
-
discoveryWorker: new TestDiscoveryWorker(input =>
|
2486
|
-
{
|
2487
|
-
return Task.FromResult(new WorkspaceDiscoveryResult()
|
2488
|
-
{
|
2489
|
-
Path = "",
|
2490
|
-
Projects = [],
|
2491
|
-
DotNetToolsJson = new()
|
2492
|
-
{
|
2493
|
-
FilePath = ".config/dotnet-tools.json",
|
2494
|
-
Dependencies = [
|
2495
|
-
new("some-tool", "2.0.0", DependencyType.DotNetTool),
|
2496
|
-
]
|
2497
|
-
},
|
2498
|
-
GlobalJson = new()
|
2499
|
-
{
|
2500
|
-
FilePath = "global.json",
|
2501
|
-
Dependencies = [
|
2502
|
-
new("Some.MSBuild.Sdk", "1.0.0", DependencyType.MSBuildSdk),
|
2503
|
-
],
|
2504
|
-
},
|
2505
|
-
});
|
2506
|
-
}),
|
2507
|
-
analyzeWorker: new TestAnalyzeWorker(input =>
|
2508
|
-
{
|
2509
|
-
var (_repoRoot, _discoveryResult, dependencyInfo) = input;
|
2510
|
-
var result = dependencyInfo.Name switch
|
2511
|
-
{
|
2512
|
-
"some-tool" => new AnalysisResult() { CanUpdate = true, UpdatedVersion = "2.0.1", UpdatedDependencies = [new("some-tool", "2.0.1", DependencyType.DotNetTool)] },
|
2513
|
-
"Some.MSBuild.Sdk" => new AnalysisResult() { CanUpdate = true, UpdatedVersion = "1.0.1", UpdatedDependencies = [new("Some.MSBuild.Sdk", "1.0.1", DependencyType.MSBuildSdk)] },
|
2514
|
-
_ => throw new NotImplementedException("unreachable")
|
2515
|
-
};
|
2516
|
-
return Task.FromResult(result);
|
2517
|
-
}),
|
2518
|
-
updaterWorker: new TestUpdaterWorker(async input =>
|
2519
|
-
{
|
2520
|
-
var (repoRoot, filePath, dependencyName, _previousVersion, newVersion, _isTransitive) = input;
|
2521
|
-
var dependencyFilePath = Path.Join(repoRoot, filePath);
|
2522
|
-
var updatedContent = dependencyName switch
|
2523
|
-
{
|
2524
|
-
"some-tool" => "dotnet-tools.json content UPDATED",
|
2525
|
-
"Some.MSBuild.Sdk" => "global.json content UPDATED",
|
2526
|
-
_ => throw new NotImplementedException("unreachable")
|
2527
|
-
};
|
2528
|
-
await File.WriteAllTextAsync(dependencyFilePath, updatedContent);
|
2529
|
-
return new UpdateOperationResult()
|
2530
|
-
{
|
2531
|
-
UpdateOperations = [
|
2532
|
-
new DirectUpdate()
|
2533
|
-
{
|
2534
|
-
DependencyName = dependencyName,
|
2535
|
-
NewVersion = NuGetVersion.Parse(newVersion),
|
2536
|
-
UpdatedFiles = [filePath]
|
2537
|
-
}
|
2538
|
-
],
|
2539
|
-
};
|
2540
|
-
}),
|
2541
|
-
expectedResult: new()
|
2542
|
-
{
|
2543
|
-
Base64DependencyFiles = [
|
2544
|
-
new()
|
2545
|
-
{
|
2546
|
-
Directory = "/.config",
|
2547
|
-
Name = "dotnet-tools.json",
|
2548
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("dotnet-tools.json content old")),
|
2549
|
-
ContentEncoding = "base64"
|
2550
|
-
},
|
2551
|
-
new()
|
2552
|
-
{
|
2553
|
-
Directory = "/",
|
2554
|
-
Name = "global.json",
|
2555
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("global.json content old")),
|
2556
|
-
ContentEncoding = "base64"
|
2557
|
-
},
|
2558
|
-
],
|
2559
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
2560
|
-
},
|
2561
|
-
expectedApiMessages: [
|
2562
|
-
new UpdatedDependencyList()
|
2563
|
-
{
|
2564
|
-
Dependencies = [
|
2565
|
-
new()
|
2566
|
-
{
|
2567
|
-
Name = "some-tool",
|
2568
|
-
Version = "2.0.0",
|
2569
|
-
Requirements = [
|
2570
|
-
new()
|
2571
|
-
{
|
2572
|
-
Requirement = "2.0.0",
|
2573
|
-
File = "/.config/dotnet-tools.json",
|
2574
|
-
Groups = ["dependencies"],
|
2575
|
-
}
|
2576
|
-
]
|
2577
|
-
},
|
2578
|
-
new()
|
2579
|
-
{
|
2580
|
-
Name = "Some.MSBuild.Sdk",
|
2581
|
-
Version = "1.0.0",
|
2582
|
-
Requirements = [
|
2583
|
-
new()
|
2584
|
-
{
|
2585
|
-
Requirement = "1.0.0",
|
2586
|
-
File = "/global.json",
|
2587
|
-
Groups = ["dependencies"],
|
2588
|
-
}
|
2589
|
-
]
|
2590
|
-
},
|
2591
|
-
],
|
2592
|
-
DependencyFiles = ["/.config/dotnet-tools.json", "/global.json"]
|
2593
|
-
},
|
2594
|
-
new IncrementMetric()
|
2595
|
-
{
|
2596
|
-
Metric = "updater.started",
|
2597
|
-
Tags = new()
|
2598
|
-
{
|
2599
|
-
["operation"] = "group_update_all_versions"
|
2600
|
-
}
|
2601
|
-
},
|
2602
|
-
new CreatePullRequest()
|
2603
|
-
{
|
2604
|
-
Dependencies =
|
2605
|
-
[
|
2606
|
-
new ReportedDependency()
|
2607
|
-
{
|
2608
|
-
Name = "some-tool",
|
2609
|
-
Version = "2.0.1",
|
2610
|
-
Requirements =
|
2611
|
-
[
|
2612
|
-
new ReportedRequirement()
|
2613
|
-
{
|
2614
|
-
Requirement = "2.0.1",
|
2615
|
-
File = "/.config/dotnet-tools.json",
|
2616
|
-
Groups = ["dependencies"],
|
2617
|
-
Source = new()
|
2618
|
-
{
|
2619
|
-
SourceUrl = null,
|
2620
|
-
}
|
2621
|
-
}
|
2622
|
-
],
|
2623
|
-
PreviousVersion = "2.0.0",
|
2624
|
-
PreviousRequirements =
|
2625
|
-
[
|
2626
|
-
new ReportedRequirement()
|
2627
|
-
{
|
2628
|
-
Requirement = "2.0.0",
|
2629
|
-
File = "/.config/dotnet-tools.json",
|
2630
|
-
Groups = ["dependencies"],
|
2631
|
-
}
|
2632
|
-
],
|
2633
|
-
},
|
2634
|
-
new ReportedDependency()
|
2635
|
-
{
|
2636
|
-
Name = "Some.MSBuild.Sdk",
|
2637
|
-
Version = "1.0.1",
|
2638
|
-
Requirements =
|
2639
|
-
[
|
2640
|
-
new ReportedRequirement()
|
2641
|
-
{
|
2642
|
-
Requirement = "1.0.1",
|
2643
|
-
File = "/global.json",
|
2644
|
-
Groups = ["dependencies"],
|
2645
|
-
Source = new()
|
2646
|
-
{
|
2647
|
-
SourceUrl = null,
|
2648
|
-
}
|
2649
|
-
}
|
2650
|
-
],
|
2651
|
-
PreviousVersion = "1.0.0",
|
2652
|
-
PreviousRequirements =
|
2653
|
-
[
|
2654
|
-
new ReportedRequirement()
|
2655
|
-
{
|
2656
|
-
Requirement = "1.0.0",
|
2657
|
-
File = "/global.json",
|
2658
|
-
Groups = ["dependencies"],
|
2659
|
-
}
|
2660
|
-
],
|
2661
|
-
},
|
2662
|
-
],
|
2663
|
-
UpdatedDependencyFiles =
|
2664
|
-
[
|
2665
|
-
new DependencyFile()
|
2666
|
-
{
|
2667
|
-
Name = "dotnet-tools.json",
|
2668
|
-
Directory = "/.config",
|
2669
|
-
Content = "dotnet-tools.json content UPDATED",
|
2670
|
-
},
|
2671
|
-
new DependencyFile()
|
2672
|
-
{
|
2673
|
-
Name = "global.json",
|
2674
|
-
Directory = "/",
|
2675
|
-
Content = "global.json content UPDATED",
|
2676
|
-
},
|
2677
|
-
],
|
2678
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
2679
|
-
CommitMessage = TestPullRequestCommitMessage,
|
2680
|
-
PrTitle = TestPullRequestTitle,
|
2681
|
-
PrBody = TestPullRequestBody,
|
2682
|
-
DependencyGroup = null,
|
2683
|
-
},
|
2684
|
-
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
2685
|
-
]
|
2686
|
-
);
|
2687
|
-
}
|
2688
|
-
|
2689
|
-
[Fact]
|
2690
|
-
public async Task PullRequestAlreadyExistsForLatestVersion()
|
2691
|
-
{
|
2692
|
-
await RunAsync(
|
2693
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
2694
|
-
job: new()
|
2695
|
-
{
|
2696
|
-
Source = new()
|
2697
|
-
{
|
2698
|
-
Provider = "github",
|
2699
|
-
Repo = "test/repo",
|
2700
|
-
},
|
2701
|
-
Dependencies = [
|
2702
|
-
"Some.Package"
|
2703
|
-
],
|
2704
|
-
ExistingPullRequests = [
|
2705
|
-
new PullRequest()
|
2706
|
-
{
|
2707
|
-
Dependencies = [new() { DependencyName = "Some.Package", DependencyVersion = NuGetVersion.Parse("1.2.0") }]
|
2708
|
-
}
|
2709
|
-
],
|
2710
|
-
SecurityAdvisories = [
|
2711
|
-
new Advisory() { DependencyName = "Some.Package", AffectedVersions = [Requirement.Parse("= 1.1.0")] }
|
2712
|
-
],
|
2713
|
-
SecurityUpdatesOnly = true,
|
2714
|
-
UpdatingAPullRequest = false
|
2715
|
-
},
|
2716
|
-
files: [
|
2717
|
-
("project.csproj", "contents irrelevant")
|
2718
|
-
],
|
2719
|
-
discoveryWorker: new TestDiscoveryWorker(_input =>
|
2720
|
-
{
|
2721
|
-
return Task.FromResult(new WorkspaceDiscoveryResult()
|
2722
|
-
{
|
2723
|
-
Path = "",
|
2724
|
-
Projects = [
|
2725
|
-
new()
|
2726
|
-
{
|
2727
|
-
FilePath = "project.csproj",
|
2728
|
-
Dependencies = [
|
2729
|
-
new("Some.Package", "1.1.0", DependencyType.PackageReference)
|
2730
|
-
],
|
2731
|
-
ImportedFiles = [],
|
2732
|
-
AdditionalFiles = [],
|
2733
|
-
}
|
2734
|
-
]
|
2735
|
-
});
|
2736
|
-
}),
|
2737
|
-
analyzeWorker: new TestAnalyzeWorker(_input =>
|
2738
|
-
{
|
2739
|
-
return Task.FromResult(new AnalysisResult()
|
2740
|
-
{
|
2741
|
-
CanUpdate = true,
|
2742
|
-
UpdatedVersion = "1.2.0",
|
2743
|
-
UpdatedDependencies = [
|
2744
|
-
new("Some.Package", "1.2.0", DependencyType.PackageReference)
|
2745
|
-
]
|
2746
|
-
});
|
2747
|
-
}),
|
2748
|
-
updaterWorker: new TestUpdaterWorker(input =>
|
2749
|
-
{
|
2750
|
-
throw new NotImplementedException("test should never get here");
|
2751
|
-
}),
|
2752
|
-
expectedResult: new()
|
2753
|
-
{
|
2754
|
-
Base64DependencyFiles = [
|
2755
|
-
new()
|
2756
|
-
{
|
2757
|
-
Directory = "/",
|
2758
|
-
Name = "project.csproj",
|
2759
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("contents irrelevant")),
|
2760
|
-
ContentEncoding = "base64"
|
2761
|
-
}
|
2762
|
-
],
|
2763
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
2764
|
-
},
|
2765
|
-
expectedApiMessages: [
|
2766
|
-
new UpdatedDependencyList()
|
2767
|
-
{
|
2768
|
-
Dependencies = [
|
2769
|
-
new()
|
2770
|
-
{
|
2771
|
-
Name = "Some.Package",
|
2772
|
-
Version = "1.1.0",
|
2773
|
-
Requirements = [
|
2774
|
-
new()
|
2775
|
-
{
|
2776
|
-
Requirement = "1.1.0",
|
2777
|
-
File = "/project.csproj",
|
2778
|
-
Groups = ["dependencies"],
|
2779
|
-
}
|
2780
|
-
]
|
2781
|
-
}
|
2782
|
-
],
|
2783
|
-
DependencyFiles = ["/project.csproj"]
|
2784
|
-
},
|
2785
|
-
new IncrementMetric()
|
2786
|
-
{
|
2787
|
-
Metric = "updater.started",
|
2788
|
-
Tags = new()
|
2789
|
-
{
|
2790
|
-
["operation"] = "create_security_pr"
|
2791
|
-
}
|
2792
|
-
},
|
2793
|
-
new PullRequestExistsForLatestVersion("Some.Package", "1.2.0"),
|
2794
|
-
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
2795
|
-
]
|
2796
|
-
);
|
2797
|
-
}
|
2798
|
-
|
2799
|
-
[Fact]
|
2800
|
-
public async Task AnalysisResultWithoutUpdatedDependenciesDoesNotCauseError()
|
2801
|
-
{
|
2802
|
-
await RunAsync(
|
2803
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
2804
|
-
job: new()
|
2805
|
-
{
|
2806
|
-
Source = new()
|
2807
|
-
{
|
2808
|
-
Provider = "github",
|
2809
|
-
Repo = "test/repo",
|
2810
|
-
},
|
2811
|
-
Dependencies = [
|
2812
|
-
"Some.Package"
|
2813
|
-
],
|
2814
|
-
},
|
2815
|
-
files: [
|
2816
|
-
("project.csproj", "contents irrelevant")
|
2817
|
-
],
|
2818
|
-
discoveryWorker: new TestDiscoveryWorker(_input =>
|
2819
|
-
{
|
2820
|
-
return Task.FromResult(new WorkspaceDiscoveryResult()
|
2821
|
-
{
|
2822
|
-
Path = "",
|
2823
|
-
Projects = [
|
2824
|
-
new()
|
2825
|
-
{
|
2826
|
-
FilePath = "project.csproj",
|
2827
|
-
Dependencies = [
|
2828
|
-
new("Some.Package", "1.0.0", DependencyType.PackageReference)
|
2829
|
-
],
|
2830
|
-
ImportedFiles = [],
|
2831
|
-
AdditionalFiles = [],
|
2832
|
-
}
|
2833
|
-
]
|
2834
|
-
});
|
2835
|
-
}),
|
2836
|
-
analyzeWorker: new TestAnalyzeWorker(_input =>
|
2837
|
-
{
|
2838
|
-
return Task.FromResult(new AnalysisResult()
|
2839
|
-
{
|
2840
|
-
CanUpdate = true,
|
2841
|
-
UpdatedVersion = "1.1.0",
|
2842
|
-
UpdatedDependencies = [], // this is what was causing the problem
|
2843
|
-
});
|
2844
|
-
}),
|
2845
|
-
updaterWorker: new TestUpdaterWorker(async input =>
|
2846
|
-
{
|
2847
|
-
var repoRootPath = input.Item1;
|
2848
|
-
var filePath = input.Item2;
|
2849
|
-
await File.WriteAllTextAsync(Path.Join(repoRootPath, filePath), "updated contents irrelevant");
|
2850
|
-
return new UpdateOperationResult()
|
2851
|
-
{
|
2852
|
-
UpdateOperations = [
|
2853
|
-
new DirectUpdate()
|
2854
|
-
{
|
2855
|
-
DependencyName = "Some.Package",
|
2856
|
-
NewVersion = NuGetVersion.Parse("1.1.0"),
|
2857
|
-
UpdatedFiles = ["project.csproj"]
|
2858
|
-
}
|
2859
|
-
]
|
2860
|
-
};
|
2861
|
-
}),
|
2862
|
-
expectedResult: new()
|
2863
|
-
{
|
2864
|
-
Base64DependencyFiles = [
|
2865
|
-
new()
|
2866
|
-
{
|
2867
|
-
Directory = "/",
|
2868
|
-
Name = "project.csproj",
|
2869
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("contents irrelevant")),
|
2870
|
-
ContentEncoding = "base64"
|
2871
|
-
}
|
2872
|
-
],
|
2873
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
2874
|
-
},
|
2875
|
-
expectedApiMessages: [
|
2876
|
-
new UpdatedDependencyList()
|
2877
|
-
{
|
2878
|
-
Dependencies = [
|
2879
|
-
new()
|
2880
|
-
{
|
2881
|
-
Name = "Some.Package",
|
2882
|
-
Version = "1.0.0",
|
2883
|
-
Requirements = [
|
2884
|
-
new()
|
2885
|
-
{
|
2886
|
-
Requirement = "1.0.0",
|
2887
|
-
File = "/project.csproj",
|
2888
|
-
Groups = ["dependencies"],
|
2889
|
-
}
|
2890
|
-
]
|
2891
|
-
}
|
2892
|
-
],
|
2893
|
-
DependencyFiles = ["/project.csproj"]
|
2894
|
-
},
|
2895
|
-
new IncrementMetric()
|
2896
|
-
{
|
2897
|
-
Metric = "updater.started",
|
2898
|
-
Tags = new()
|
2899
|
-
{
|
2900
|
-
["operation"] = "group_update_all_versions"
|
2901
|
-
}
|
2902
|
-
},
|
2903
|
-
new CreatePullRequest()
|
2904
|
-
{
|
2905
|
-
Dependencies =
|
2906
|
-
[
|
2907
|
-
new ReportedDependency()
|
2908
|
-
{
|
2909
|
-
Name = "Some.Package",
|
2910
|
-
Version = "1.1.0",
|
2911
|
-
Requirements =
|
2912
|
-
[
|
2913
|
-
new ReportedRequirement()
|
2914
|
-
{
|
2915
|
-
Requirement = "1.1.0",
|
2916
|
-
File = "/project.csproj",
|
2917
|
-
Groups = ["dependencies"],
|
2918
|
-
Source = new()
|
2919
|
-
{
|
2920
|
-
SourceUrl = null,
|
2921
|
-
Type = "nuget_repo",
|
2922
|
-
}
|
2923
|
-
}
|
2924
|
-
],
|
2925
|
-
PreviousVersion = "1.0.0",
|
2926
|
-
PreviousRequirements =
|
2927
|
-
[
|
2928
|
-
new ReportedRequirement()
|
2929
|
-
{
|
2930
|
-
Requirement = "1.0.0",
|
2931
|
-
File = "/project.csproj",
|
2932
|
-
Groups = ["dependencies"],
|
2933
|
-
}
|
2934
|
-
],
|
2935
|
-
}
|
2936
|
-
],
|
2937
|
-
UpdatedDependencyFiles =
|
2938
|
-
[
|
2939
|
-
new DependencyFile()
|
2940
|
-
{
|
2941
|
-
Name = "project.csproj",
|
2942
|
-
Directory = "/",
|
2943
|
-
Content = "updated contents irrelevant",
|
2944
|
-
},
|
2945
|
-
],
|
2946
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
2947
|
-
CommitMessage = TestPullRequestCommitMessage,
|
2948
|
-
PrTitle = TestPullRequestTitle,
|
2949
|
-
PrBody = TestPullRequestBody,
|
2950
|
-
DependencyGroup = null,
|
2951
|
-
},
|
2952
|
-
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
2953
|
-
]
|
2954
|
-
);
|
2955
|
-
}
|
2956
|
-
|
2957
|
-
[Fact]
|
2958
|
-
public async Task ByteOrderMarksAreDetectedAndRestored()
|
2959
|
-
{
|
2960
|
-
var rawBOM = Encoding.UTF8.GetPreamble();
|
2961
|
-
|
2962
|
-
// file1 goes from BOM to no BOM
|
2963
|
-
var file1ContentOriginal = rawBOM.Concat(Encoding.ASCII.GetBytes("content1")).ToArray();
|
2964
|
-
var file1ContentUpdated = Encoding.ASCII.GetBytes("updated1");
|
2965
|
-
|
2966
|
-
// file2 goes from no BOM to BOM
|
2967
|
-
var file2ContentOriginal = Encoding.ASCII.GetBytes("content2");
|
2968
|
-
var file2ContentUpdated = rawBOM.Concat(Encoding.ASCII.GetBytes("updated2")).ToArray();
|
2969
|
-
|
2970
|
-
await RunAsync(
|
2971
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
2972
|
-
job: new Job()
|
2973
|
-
{
|
2974
|
-
Source = new()
|
2975
|
-
{
|
2976
|
-
Provider = "github",
|
2977
|
-
Repo = "test/repo",
|
2978
|
-
Directory = "/",
|
2979
|
-
}
|
2980
|
-
},
|
2981
|
-
rawFiles:
|
2982
|
-
[
|
2983
|
-
("file1", file1ContentOriginal),
|
2984
|
-
("file2", file2ContentOriginal)
|
2985
|
-
],
|
2986
|
-
discoveryWorker: TestDiscoveryWorker.FromResults(("/", new()
|
2987
|
-
{
|
2988
|
-
Path = "/",
|
2989
|
-
Projects = [
|
2990
|
-
new()
|
2991
|
-
{
|
2992
|
-
FilePath = "file1",
|
2993
|
-
Dependencies = [new("Dependency1", "1.0.0", DependencyType.PackageReference)],
|
2994
|
-
ImportedFiles = [],
|
2995
|
-
AdditionalFiles = [],
|
2996
|
-
},
|
2997
|
-
new()
|
2998
|
-
{
|
2999
|
-
FilePath = "file2",
|
3000
|
-
Dependencies = [new("Dependency2", "2.0.0", DependencyType.PackageReference)],
|
3001
|
-
ImportedFiles = [],
|
3002
|
-
AdditionalFiles = [],
|
3003
|
-
}
|
3004
|
-
]
|
3005
|
-
})),
|
3006
|
-
analyzeWorker: new TestAnalyzeWorker(args =>
|
3007
|
-
{
|
3008
|
-
AnalysisResult result = args.Item3.Name switch
|
3009
|
-
{
|
3010
|
-
"Dependency1" => new()
|
3011
|
-
{
|
3012
|
-
CanUpdate = true,
|
3013
|
-
UpdatedVersion = "1.0.1",
|
3014
|
-
UpdatedDependencies = [new("Dependency1", "1.0.1", DependencyType.PackageReference)],
|
3015
|
-
},
|
3016
|
-
"Dependency2" => new()
|
3017
|
-
{
|
3018
|
-
CanUpdate = true,
|
3019
|
-
UpdatedVersion = "2.0.1",
|
3020
|
-
UpdatedDependencies = [new("Dependency2", "2.0.1", DependencyType.PackageReference)],
|
3021
|
-
},
|
3022
|
-
_ => throw new NotImplementedException()
|
3023
|
-
};
|
3024
|
-
return Task.FromResult(result);
|
3025
|
-
}),
|
3026
|
-
updaterWorker: new TestUpdaterWorker(async args =>
|
3027
|
-
{
|
3028
|
-
var (repoRoot, filePath, dependencyName, _previousVersion, _newVersion, _isTransitive) = args;
|
3029
|
-
|
3030
|
-
// file1 is rewritten without BOM, file2 is rewritten with BOM
|
3031
|
-
var (updatedFileContent, newVersion) = dependencyName switch
|
3032
|
-
{
|
3033
|
-
"Dependency1" => (file1ContentUpdated, "1.0.1"),
|
3034
|
-
"Dependency2" => (file2ContentUpdated, "2.0.1"),
|
3035
|
-
_ => throw new NotImplementedException(),
|
3036
|
-
};
|
3037
|
-
var fullFilePath = Path.Join(repoRoot, filePath);
|
3038
|
-
await File.WriteAllBytesAsync(fullFilePath, updatedFileContent);
|
3039
|
-
return new UpdateOperationResult()
|
3040
|
-
{
|
3041
|
-
UpdateOperations = [new DirectUpdate()
|
3042
|
-
{
|
3043
|
-
DependencyName = dependencyName,
|
3044
|
-
NewVersion = NuGetVersion.Parse(newVersion),
|
3045
|
-
UpdatedFiles = [filePath],
|
3046
|
-
}],
|
3047
|
-
};
|
3048
|
-
}),
|
3049
|
-
expectedResult: new()
|
3050
|
-
{
|
3051
|
-
Base64DependencyFiles = [
|
3052
|
-
new()
|
3053
|
-
{
|
3054
|
-
Directory = "/",
|
3055
|
-
Name = "file1",
|
3056
|
-
Content = Convert.ToBase64String(file1ContentOriginal),
|
3057
|
-
ContentEncoding = "base64",
|
3058
|
-
},
|
3059
|
-
new()
|
3060
|
-
{
|
3061
|
-
Directory = "/",
|
3062
|
-
Name = "file2",
|
3063
|
-
Content = Convert.ToBase64String(file2ContentOriginal),
|
3064
|
-
ContentEncoding = "base64",
|
3065
|
-
}
|
3066
|
-
],
|
3067
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
3068
|
-
},
|
3069
|
-
expectedApiMessages: [
|
3070
|
-
new UpdatedDependencyList()
|
3071
|
-
{
|
3072
|
-
Dependencies = [
|
3073
|
-
new()
|
3074
|
-
{
|
3075
|
-
Name = "Dependency1",
|
3076
|
-
Version = "1.0.0",
|
3077
|
-
Requirements = [
|
3078
|
-
new()
|
3079
|
-
{
|
3080
|
-
Requirement = "1.0.0",
|
3081
|
-
File = "/file1",
|
3082
|
-
Groups = ["dependencies"],
|
3083
|
-
}
|
3084
|
-
]
|
3085
|
-
},
|
3086
|
-
new()
|
3087
|
-
{
|
3088
|
-
Name = "Dependency2",
|
3089
|
-
Version = "2.0.0",
|
3090
|
-
Requirements = [
|
3091
|
-
new()
|
3092
|
-
{
|
3093
|
-
Requirement = "2.0.0",
|
3094
|
-
File = "/file2",
|
3095
|
-
Groups = ["dependencies"]
|
3096
|
-
}
|
3097
|
-
]
|
3098
|
-
}
|
3099
|
-
],
|
3100
|
-
DependencyFiles = ["/file1", "/file2"]
|
3101
|
-
},
|
3102
|
-
new IncrementMetric()
|
3103
|
-
{
|
3104
|
-
Metric = "updater.started",
|
3105
|
-
Tags = new()
|
3106
|
-
{
|
3107
|
-
["operation"] = "group_update_all_versions"
|
3108
|
-
}
|
3109
|
-
},
|
3110
|
-
new CreatePullRequest()
|
3111
|
-
{
|
3112
|
-
Dependencies =
|
3113
|
-
[
|
3114
|
-
new ReportedDependency()
|
3115
|
-
{
|
3116
|
-
Name = "Dependency1",
|
3117
|
-
Version = "1.0.1",
|
3118
|
-
Requirements =
|
3119
|
-
[
|
3120
|
-
new ReportedRequirement()
|
3121
|
-
{
|
3122
|
-
Requirement = "1.0.1",
|
3123
|
-
File = "/file1",
|
3124
|
-
Groups = ["dependencies"],
|
3125
|
-
Source = new() { SourceUrl = null },
|
3126
|
-
}
|
3127
|
-
],
|
3128
|
-
PreviousVersion = "1.0.0",
|
3129
|
-
PreviousRequirements =
|
3130
|
-
[
|
3131
|
-
new ReportedRequirement()
|
3132
|
-
{
|
3133
|
-
Requirement = "1.0.0",
|
3134
|
-
File = "/file1",
|
3135
|
-
Groups = ["dependencies"],
|
3136
|
-
}
|
3137
|
-
],
|
3138
|
-
},
|
3139
|
-
new ReportedDependency()
|
3140
|
-
{
|
3141
|
-
Name = "Dependency2",
|
3142
|
-
Version = "2.0.1",
|
3143
|
-
Requirements =
|
3144
|
-
[
|
3145
|
-
new ReportedRequirement()
|
3146
|
-
{
|
3147
|
-
Requirement = "2.0.1",
|
3148
|
-
File = "/file2",
|
3149
|
-
Groups = ["dependencies"],
|
3150
|
-
Source = new() { SourceUrl = null },
|
3151
|
-
}
|
3152
|
-
],
|
3153
|
-
PreviousVersion = "2.0.0",
|
3154
|
-
PreviousRequirements =
|
3155
|
-
[
|
3156
|
-
new ReportedRequirement()
|
3157
|
-
{
|
3158
|
-
Requirement = "2.0.0",
|
3159
|
-
File = "/file2",
|
3160
|
-
Groups = ["dependencies"],
|
3161
|
-
}
|
3162
|
-
],
|
3163
|
-
},
|
3164
|
-
],
|
3165
|
-
UpdatedDependencyFiles =
|
3166
|
-
[
|
3167
|
-
// original line endings have been restored
|
3168
|
-
new DependencyFile()
|
3169
|
-
{
|
3170
|
-
Name = "file1",
|
3171
|
-
Directory = "/",
|
3172
|
-
Content = Convert.ToBase64String(rawBOM.Concat(file1ContentUpdated).ToArray()),
|
3173
|
-
ContentEncoding = "base64",
|
3174
|
-
},
|
3175
|
-
new DependencyFile()
|
3176
|
-
{
|
3177
|
-
Name = "file2",
|
3178
|
-
Directory = "/",
|
3179
|
-
Content = "updated2",
|
3180
|
-
},
|
3181
|
-
],
|
3182
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
3183
|
-
CommitMessage = TestPullRequestCommitMessage,
|
3184
|
-
PrTitle = TestPullRequestTitle,
|
3185
|
-
PrBody = TestPullRequestBody,
|
3186
|
-
DependencyGroup = null,
|
3187
|
-
},
|
3188
|
-
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
3189
|
-
]
|
3190
|
-
);
|
3191
|
-
}
|
3192
|
-
|
3193
|
-
[Fact]
|
3194
|
-
public async Task LineEndingsAreDetectedAndRestored()
|
3195
|
-
{
|
3196
|
-
await RunAsync(
|
3197
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
3198
|
-
job: new Job()
|
3199
|
-
{
|
3200
|
-
Source = new()
|
3201
|
-
{
|
3202
|
-
Provider = "github",
|
3203
|
-
Repo = "test/repo",
|
3204
|
-
Directory = "/",
|
3205
|
-
}
|
3206
|
-
},
|
3207
|
-
files:
|
3208
|
-
[
|
3209
|
-
// initially LF
|
3210
|
-
("file1", string.Concat(
|
3211
|
-
"file1-line1\n",
|
3212
|
-
"file1-line2\n",
|
3213
|
-
"file1-line3\n"
|
3214
|
-
)
|
3215
|
-
),
|
3216
|
-
// initially CRLF
|
3217
|
-
("file2", string.Concat(
|
3218
|
-
"file2-line1\r\n",
|
3219
|
-
"file2-line2\r\n",
|
3220
|
-
"file2-line3\r\n"
|
3221
|
-
)
|
3222
|
-
)
|
3223
|
-
],
|
3224
|
-
discoveryWorker: TestDiscoveryWorker.FromResults(("/", new()
|
3225
|
-
{
|
3226
|
-
Path = "/",
|
3227
|
-
Projects = [
|
3228
|
-
new()
|
3229
|
-
{
|
3230
|
-
FilePath = "file1",
|
3231
|
-
Dependencies = [new("Dependency1", "1.0.0", DependencyType.PackageReference)],
|
3232
|
-
ImportedFiles = [],
|
3233
|
-
AdditionalFiles = [],
|
3234
|
-
},
|
3235
|
-
new()
|
3236
|
-
{
|
3237
|
-
FilePath = "file2",
|
3238
|
-
Dependencies = [new("Dependency2", "2.0.0", DependencyType.PackageReference)],
|
3239
|
-
ImportedFiles = [],
|
3240
|
-
AdditionalFiles = [],
|
3241
|
-
}
|
3242
|
-
]
|
3243
|
-
})),
|
3244
|
-
analyzeWorker: new TestAnalyzeWorker(args =>
|
3245
|
-
{
|
3246
|
-
AnalysisResult result = args.Item3.Name switch
|
3247
|
-
{
|
3248
|
-
"Dependency1" => new()
|
3249
|
-
{
|
3250
|
-
CanUpdate = true,
|
3251
|
-
UpdatedVersion = "1.0.1",
|
3252
|
-
UpdatedDependencies = [new("Dependency1", "1.0.1", DependencyType.PackageReference)],
|
3253
|
-
},
|
3254
|
-
"Dependency2" => new()
|
3255
|
-
{
|
3256
|
-
CanUpdate = true,
|
3257
|
-
UpdatedVersion = "2.0.1",
|
3258
|
-
UpdatedDependencies = [new("Dependency2", "2.0.1", DependencyType.PackageReference)],
|
3259
|
-
},
|
3260
|
-
_ => throw new NotImplementedException()
|
3261
|
-
};
|
3262
|
-
return Task.FromResult(result);
|
3263
|
-
}),
|
3264
|
-
updaterWorker: new TestUpdaterWorker(async args =>
|
3265
|
-
{
|
3266
|
-
var (repoRoot, filePath, dependencyName, _previousVersion, _newVersion, _isTransitive) = args;
|
3267
|
-
|
3268
|
-
// file is explicitly updated with CR
|
3269
|
-
var (updatedFileContent, newVersion) = dependencyName switch
|
3270
|
-
{
|
3271
|
-
"Dependency1" => (string.Concat(
|
3272
|
-
"file1-line1-updated\r",
|
3273
|
-
"file1-line2-updated\r",
|
3274
|
-
"file1-line3-updated\r"), "1.0.1"),
|
3275
|
-
"Dependency2" => (string.Concat(
|
3276
|
-
"file2-line1-updated\r",
|
3277
|
-
"file2-line2-updated\r",
|
3278
|
-
"file2-line3-updated\r"), "2.0.1"),
|
3279
|
-
_ => throw new NotImplementedException(),
|
3280
|
-
};
|
3281
|
-
var fullFilePath = Path.Join(repoRoot, filePath);
|
3282
|
-
await File.WriteAllTextAsync(fullFilePath, updatedFileContent);
|
3283
|
-
return new UpdateOperationResult()
|
3284
|
-
{
|
3285
|
-
UpdateOperations = [new DirectUpdate()
|
3286
|
-
{
|
3287
|
-
DependencyName = dependencyName,
|
3288
|
-
NewVersion = NuGetVersion.Parse(newVersion),
|
3289
|
-
UpdatedFiles = [filePath],
|
3290
|
-
}],
|
3291
|
-
};
|
3292
|
-
}),
|
3293
|
-
expectedResult: new()
|
3294
|
-
{
|
3295
|
-
Base64DependencyFiles = [
|
3296
|
-
new()
|
3297
|
-
{
|
3298
|
-
Directory = "/",
|
3299
|
-
Name = "file1",
|
3300
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Concat(
|
3301
|
-
"file1-line1\n",
|
3302
|
-
"file1-line2\n",
|
3303
|
-
"file1-line3\n"))),
|
3304
|
-
ContentEncoding = "base64",
|
3305
|
-
},
|
3306
|
-
new()
|
3307
|
-
{
|
3308
|
-
Directory = "/",
|
3309
|
-
Name = "file2",
|
3310
|
-
Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Concat(
|
3311
|
-
"file2-line1\r\n",
|
3312
|
-
"file2-line2\r\n",
|
3313
|
-
"file2-line3\r\n"))),
|
3314
|
-
ContentEncoding = "base64",
|
3315
|
-
}
|
3316
|
-
],
|
3317
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
3318
|
-
},
|
3319
|
-
expectedApiMessages: [
|
3320
|
-
new UpdatedDependencyList()
|
3321
|
-
{
|
3322
|
-
Dependencies = [
|
3323
|
-
new()
|
3324
|
-
{
|
3325
|
-
Name = "Dependency1",
|
3326
|
-
Version = "1.0.0",
|
3327
|
-
Requirements = [
|
3328
|
-
new()
|
3329
|
-
{
|
3330
|
-
Requirement = "1.0.0",
|
3331
|
-
File = "/file1",
|
3332
|
-
Groups = ["dependencies"],
|
3333
|
-
}
|
3334
|
-
]
|
3335
|
-
},
|
3336
|
-
new()
|
3337
|
-
{
|
3338
|
-
Name = "Dependency2",
|
3339
|
-
Version = "2.0.0",
|
3340
|
-
Requirements = [
|
3341
|
-
new()
|
3342
|
-
{
|
3343
|
-
Requirement = "2.0.0",
|
3344
|
-
File = "/file2",
|
3345
|
-
Groups = ["dependencies"]
|
3346
|
-
}
|
3347
|
-
]
|
3348
|
-
}
|
3349
|
-
],
|
3350
|
-
DependencyFiles = ["/file1", "/file2"]
|
3351
|
-
},
|
3352
|
-
new IncrementMetric()
|
3353
|
-
{
|
3354
|
-
Metric = "updater.started",
|
3355
|
-
Tags = new()
|
3356
|
-
{
|
3357
|
-
["operation"] = "group_update_all_versions"
|
3358
|
-
}
|
3359
|
-
},
|
3360
|
-
new CreatePullRequest()
|
3361
|
-
{
|
3362
|
-
Dependencies =
|
3363
|
-
[
|
3364
|
-
new ReportedDependency()
|
3365
|
-
{
|
3366
|
-
Name = "Dependency1",
|
3367
|
-
Version = "1.0.1",
|
3368
|
-
Requirements =
|
3369
|
-
[
|
3370
|
-
new ReportedRequirement()
|
3371
|
-
{
|
3372
|
-
Requirement = "1.0.1",
|
3373
|
-
File = "/file1",
|
3374
|
-
Groups = ["dependencies"],
|
3375
|
-
Source = new() { SourceUrl = null },
|
3376
|
-
}
|
3377
|
-
],
|
3378
|
-
PreviousVersion = "1.0.0",
|
3379
|
-
PreviousRequirements =
|
3380
|
-
[
|
3381
|
-
new ReportedRequirement()
|
3382
|
-
{
|
3383
|
-
Requirement = "1.0.0",
|
3384
|
-
File = "/file1",
|
3385
|
-
Groups = ["dependencies"],
|
3386
|
-
}
|
3387
|
-
],
|
3388
|
-
},
|
3389
|
-
new ReportedDependency()
|
3390
|
-
{
|
3391
|
-
Name = "Dependency2",
|
3392
|
-
Version = "2.0.1",
|
3393
|
-
Requirements =
|
3394
|
-
[
|
3395
|
-
new ReportedRequirement()
|
3396
|
-
{
|
3397
|
-
Requirement = "2.0.1",
|
3398
|
-
File = "/file2",
|
3399
|
-
Groups = ["dependencies"],
|
3400
|
-
Source = new() { SourceUrl = null },
|
3401
|
-
}
|
3402
|
-
],
|
3403
|
-
PreviousVersion = "2.0.0",
|
3404
|
-
PreviousRequirements =
|
3405
|
-
[
|
3406
|
-
new ReportedRequirement()
|
3407
|
-
{
|
3408
|
-
Requirement = "2.0.0",
|
3409
|
-
File = "/file2",
|
3410
|
-
Groups = ["dependencies"],
|
3411
|
-
}
|
3412
|
-
],
|
3413
|
-
},
|
3414
|
-
],
|
3415
|
-
UpdatedDependencyFiles =
|
3416
|
-
[
|
3417
|
-
// original line endings have been restored
|
3418
|
-
new DependencyFile()
|
3419
|
-
{
|
3420
|
-
Name = "file1",
|
3421
|
-
Directory = "/",
|
3422
|
-
Content = string.Concat(
|
3423
|
-
"file1-line1-updated\n",
|
3424
|
-
"file1-line2-updated\n",
|
3425
|
-
"file1-line3-updated\n"
|
3426
|
-
),
|
3427
|
-
},
|
3428
|
-
new DependencyFile()
|
3429
|
-
{
|
3430
|
-
Name = "file2",
|
3431
|
-
Directory = "/",
|
3432
|
-
Content = string.Concat(
|
3433
|
-
"file2-line1-updated\r\n",
|
3434
|
-
"file2-line2-updated\r\n",
|
3435
|
-
"file2-line3-updated\r\n"
|
3436
|
-
),
|
3437
|
-
},
|
3438
|
-
],
|
3439
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
3440
|
-
CommitMessage = TestPullRequestCommitMessage,
|
3441
|
-
PrTitle = TestPullRequestTitle,
|
3442
|
-
PrBody = TestPullRequestBody,
|
3443
|
-
DependencyGroup = null,
|
3444
|
-
},
|
3445
|
-
new MarkAsProcessed("TEST-COMMIT-SHA"),
|
3446
|
-
]
|
3447
|
-
);
|
3448
|
-
}
|
3449
|
-
|
3450
|
-
[Fact]
|
3451
|
-
public async Task UnknownErrorsGenerateAllRequiredApiCalls()
|
3452
|
-
{
|
3453
|
-
await RunAsync(
|
3454
|
-
experimentsManager: new ExperimentsManager() { UseLegacyUpdateHandler = true },
|
3455
|
-
job: new Job()
|
3456
|
-
{
|
3457
|
-
Source = new()
|
3458
|
-
{
|
3459
|
-
Provider = "github",
|
3460
|
-
Repo = "test/repo",
|
3461
|
-
Directory = "some-dir",
|
3462
|
-
}
|
3463
|
-
},
|
3464
|
-
packages: [],
|
3465
|
-
files: [],
|
3466
|
-
discoveryWorker: new TestDiscoveryWorker(_input =>
|
3467
|
-
{
|
3468
|
-
throw new FileNotFoundException("some required file is missing");
|
3469
|
-
}),
|
3470
|
-
analyzeWorker: TestAnalyzeWorker.FromResults(), // unreachable
|
3471
|
-
updaterWorker: TestUpdaterWorker.FromResults(), // unreachable
|
3472
|
-
expectedResult: new RunResult()
|
3473
|
-
{
|
3474
|
-
Base64DependencyFiles = [],
|
3475
|
-
BaseCommitSha = "TEST-COMMIT-SHA",
|
3476
|
-
},
|
3477
|
-
expectedApiMessages:
|
3478
|
-
[
|
3479
|
-
new UnknownError(new FileNotFoundException("some required file is missing"), "TEST-JOB-ID"), // from record_update_job_error
|
3480
|
-
new UnknownError(new FileNotFoundException("some required file is missing"), "TEST-JOB-ID"), // from record_update_job_unknown_error
|
3481
|
-
new IncrementMetric()
|
3482
|
-
{
|
3483
|
-
Metric = "updater.update_job_unknown_error",
|
3484
|
-
Tags = new()
|
3485
|
-
{
|
3486
|
-
["package_manager"] = "nuget",
|
3487
|
-
["class_name"] = "FileNotFoundException"
|
3488
|
-
}
|
3489
|
-
},
|
3490
|
-
new MarkAsProcessed("TEST-COMMIT-SHA")
|
3491
|
-
]
|
3492
|
-
);
|
3493
|
-
}
|
3494
|
-
|
3495
|
-
internal static Task RunAsync(Job job, TestFile[] files, IDiscoveryWorker? discoveryWorker, IAnalyzeWorker? analyzeWorker, IUpdaterWorker? updaterWorker, RunResult expectedResult, object[] expectedApiMessages, MockNuGetPackage[]? packages = null, ExperimentsManager? experimentsManager = null, string? repoContentsPath = null)
|
3496
|
-
{
|
3497
|
-
var rawTestFiles = files.Select(f => (f.Path, Encoding.UTF8.GetBytes(f.Content))).ToArray();
|
3498
|
-
return RunAsync(job, rawTestFiles, discoveryWorker, analyzeWorker, updaterWorker, expectedResult, expectedApiMessages, packages, experimentsManager, repoContentsPath);
|
3499
|
-
}
|
3500
|
-
|
3501
|
-
private static async Task RunAsync(Job job, RawTestFile[] rawFiles, IDiscoveryWorker? discoveryWorker, IAnalyzeWorker? analyzeWorker, IUpdaterWorker? updaterWorker, RunResult expectedResult, object[] expectedApiMessages, MockNuGetPackage[]? packages = null, ExperimentsManager? experimentsManager = null, string? repoContentsPath = null)
|
3502
|
-
{
|
3503
|
-
// arrange
|
3504
|
-
using var tempDirectory = new TemporaryDirectory();
|
3505
|
-
repoContentsPath ??= tempDirectory.DirectoryPath;
|
3506
|
-
await UpdateWorkerTestBase.MockNuGetPackagesInDirectory(packages, repoContentsPath);
|
3507
|
-
foreach (var (path, content) in rawFiles)
|
3508
|
-
{
|
3509
|
-
var fullPath = Path.Combine(repoContentsPath, path);
|
3510
|
-
var directory = Path.GetDirectoryName(fullPath)!;
|
3511
|
-
Directory.CreateDirectory(directory);
|
3512
|
-
await File.WriteAllBytesAsync(fullPath, content);
|
3513
|
-
}
|
3514
|
-
|
3515
|
-
// act
|
3516
|
-
experimentsManager ??= new ExperimentsManager();
|
3517
|
-
var testApiHandler = new TestApiHandler();
|
3518
|
-
var logger = new TestLogger();
|
3519
|
-
var jobId = "TEST-JOB-ID";
|
3520
|
-
discoveryWorker ??= new DiscoveryWorker(jobId, experimentsManager, logger);
|
3521
|
-
analyzeWorker ??= new AnalyzeWorker(jobId, experimentsManager, logger);
|
3522
|
-
updaterWorker ??= new UpdaterWorker(jobId, experimentsManager, logger);
|
3523
|
-
|
3524
|
-
var worker = new RunWorker(jobId, testApiHandler, discoveryWorker, analyzeWorker, updaterWorker, logger);
|
3525
|
-
var repoContentsPathDirectoryInfo = new DirectoryInfo(tempDirectory.DirectoryPath);
|
3526
|
-
var actualResult = await worker.RunAsync(job, repoContentsPathDirectoryInfo, repoContentsPathDirectoryInfo, "TEST-COMMIT-SHA", experimentsManager);
|
3527
|
-
var actualApiMessages = testApiHandler.ReceivedMessages
|
3528
|
-
.Select(m =>
|
3529
|
-
{
|
3530
|
-
object newObject;
|
3531
|
-
switch (m.Object)
|
3532
|
-
{
|
3533
|
-
// this isn't the place to verify the generated text
|
3534
|
-
case CreatePullRequest create:
|
3535
|
-
newObject = create with { CommitMessage = TestPullRequestCommitMessage, PrTitle = TestPullRequestTitle, PrBody = TestPullRequestBody };
|
3536
|
-
break;
|
3537
|
-
case UpdatePullRequest update:
|
3538
|
-
newObject = update with { CommitMessage = TestPullRequestCommitMessage, PrTitle = TestPullRequestTitle, PrBody = TestPullRequestBody };
|
3539
|
-
break;
|
3540
|
-
// don't test callstacks
|
3541
|
-
case UnknownError unknown:
|
3542
|
-
var message = (string)unknown.Details["error-message"];
|
3543
|
-
var stackTraceOffset = message.IndexOf('\n');
|
3544
|
-
if (stackTraceOffset >= 0)
|
3545
|
-
{
|
3546
|
-
var messageWithoutStackTrace = message[..stackTraceOffset].TrimEnd('\r');
|
3547
|
-
unknown.Details["error-message"] = messageWithoutStackTrace;
|
3548
|
-
}
|
3549
|
-
|
3550
|
-
newObject = unknown;
|
3551
|
-
break;
|
3552
|
-
default:
|
3553
|
-
newObject = m.Object;
|
3554
|
-
break;
|
3555
|
-
}
|
3556
|
-
|
3557
|
-
return (m.Type, Object: newObject);
|
3558
|
-
}
|
3559
|
-
).ToArray();
|
3560
|
-
|
3561
|
-
// assert
|
3562
|
-
var actualRunResultJson = JsonSerializer.Serialize(actualResult);
|
3563
|
-
var expectedRunResultJson = JsonSerializer.Serialize(expectedResult);
|
3564
|
-
Assert.Equal(expectedRunResultJson, actualRunResultJson);
|
3565
|
-
for (int i = 0; i < Math.Min(actualApiMessages.Length, expectedApiMessages.Length); i++)
|
3566
|
-
{
|
3567
|
-
var actualMessage = actualApiMessages[i];
|
3568
|
-
var expectedMessage = expectedApiMessages[i];
|
3569
|
-
Assert.Equal(expectedMessage.GetType(), actualMessage.Type);
|
3570
|
-
|
3571
|
-
var expectedContent = SerializeObjectAndType(expectedMessage);
|
3572
|
-
var actualContent = SerializeObjectAndType(actualMessage.Object);
|
3573
|
-
Assert.Equal(expectedContent, actualContent);
|
3574
|
-
}
|
3575
|
-
|
3576
|
-
if (actualApiMessages.Length > expectedApiMessages.Length)
|
3577
|
-
{
|
3578
|
-
var extraApiMessages = actualApiMessages.Skip(expectedApiMessages.Length).Select(m => SerializeObjectAndType(m.Object)).ToArray();
|
3579
|
-
Assert.Fail($"Expected {expectedApiMessages.Length} API messages, but got {extraApiMessages.Length} extra:\n\t{string.Join("\n\t", extraApiMessages)}");
|
3580
|
-
}
|
3581
|
-
if (expectedApiMessages.Length > actualApiMessages.Length)
|
3582
|
-
{
|
3583
|
-
var missingApiMessages = expectedApiMessages.Skip(actualApiMessages.Length).Select(m => SerializeObjectAndType(m)).ToArray();
|
3584
|
-
Assert.Fail($"Expected {expectedApiMessages.Length} API messages, but only got {actualApiMessages.Length}; missing:\n\t{string.Join("\n\t", missingApiMessages)}");
|
3585
|
-
}
|
3586
|
-
}
|
3587
|
-
|
3588
|
-
internal static string SerializeObjectAndType(object obj)
|
3589
|
-
{
|
3590
|
-
return $"{obj.GetType().Name}:{JsonSerializer.Serialize(obj, RunWorker.SerializerOptions)}";
|
3591
|
-
}
|
3592
|
-
}
|