dependabot-nuget 0.316.0 → 0.318.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/DependencyInfo.cs +3 -0
  3. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/VersionFinder.cs +30 -1
  4. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/FrameworkCompatibilityService.cs +25 -1
  5. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Condition.cs +13 -1
  6. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/DependencyGroup.cs +29 -18
  7. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Job.cs +7 -9
  8. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestTextGenerator.cs +6 -1
  9. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +13 -1
  10. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/CreateSecurityUpdatePullRequestHandler.cs +18 -10
  11. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/GroupUpdateAllVersionsHandler.cs +11 -16
  12. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshGroupUpdatePullRequestHandler.cs +4 -2
  13. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandler.cs +29 -13
  14. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandler.cs +25 -7
  15. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs +15 -8
  16. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/SpecialImportsConditionPatcher.cs +15 -2
  17. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +11 -3
  18. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/VersionFinderTests.cs +39 -0
  19. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/FrameworkCompatibilityServiceFacts.cs +8 -11
  20. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/MiscellaneousTests.cs +108 -15
  21. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestTextTests.cs +39 -0
  22. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/SerializationTests.cs +2 -2
  23. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/GroupUpdateAllVersionsHandlerTests.cs +291 -0
  24. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshGroupUpdatePullRequestHandlerTests.cs +311 -6
  25. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandlerTests.cs +273 -0
  26. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandlerTests.cs +307 -0
  27. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackageReferenceUpdaterTests.cs +51 -1
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/SpecialFilePatcherTests.cs +25 -0
  29. metadata +4 -4
@@ -271,6 +271,279 @@ public class RefreshSecurityUpdatePullRequestHandlerTests : UpdateHandlersTestsB
271
271
  );
272
272
  }
273
273
 
274
+ [Fact]
275
+ public async Task GeneratesUpdatePullRequest_FirstUpdateDidNothingSecondUpdateSucceeded()
276
+ {
277
+ await TestAsync(
278
+ job: new Job()
279
+ {
280
+ Dependencies = ["Some.Dependency"],
281
+ ExistingPullRequests = [new() { Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("2.0.0") }] }],
282
+ SecurityAdvisories = [new() { DependencyName = "Some.Dependency", AffectedVersions = [Requirement.Parse("= 1.0.0")] }],
283
+ SecurityUpdatesOnly = true,
284
+ Source = CreateJobSource("/src"),
285
+ UpdatingAPullRequest = true,
286
+ },
287
+ files: [
288
+ ("src/Directory.Packages.props", "initial contents"),
289
+ ("src/project1.csproj", "initial contents"),
290
+ ("src/project2.csproj", "initial contents"),
291
+ ],
292
+ discoveryWorker: TestDiscoveryWorker.FromResults(
293
+ ("/src", new WorkspaceDiscoveryResult()
294
+ {
295
+ Path = "/src",
296
+ Projects = [
297
+ new()
298
+ {
299
+ FilePath = "project1.csproj",
300
+ Dependencies = [
301
+ new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
302
+ ],
303
+ ImportedFiles = ["Directory.Packages.props"],
304
+ AdditionalFiles = [],
305
+ },
306
+ new()
307
+ {
308
+ FilePath = "project2.csproj",
309
+ Dependencies = [
310
+ new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
311
+ ],
312
+ ImportedFiles = ["Directory.Packages.props"],
313
+ AdditionalFiles = [],
314
+ },
315
+ ],
316
+ })
317
+ ),
318
+ analyzeWorker: new TestAnalyzeWorker(input =>
319
+ {
320
+ var repoRoot = input.Item1;
321
+ var discovery = input.Item2;
322
+ var dependencyInfo = input.Item3;
323
+ if (dependencyInfo.Name != "Some.Dependency")
324
+ {
325
+ throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}");
326
+ }
327
+
328
+ return Task.FromResult(new AnalysisResult()
329
+ {
330
+ CanUpdate = true,
331
+ UpdatedVersion = "2.0.0",
332
+ UpdatedDependencies = [],
333
+ });
334
+ }),
335
+ updaterWorker: new TestUpdaterWorker(async input =>
336
+ {
337
+ var repoRoot = input.Item1;
338
+ var workspacePath = input.Item2;
339
+ var dependencyName = input.Item3;
340
+ var previousVersion = input.Item4;
341
+ var newVersion = input.Item5;
342
+ var isTransitive = input.Item6;
343
+
344
+ await File.WriteAllTextAsync(Path.Join(repoRoot, "src/Directory.Packages.props"), "updated contents");
345
+
346
+ // only report an update performed on the second project
347
+ ImmutableArray<UpdateOperationBase> updateOperations = workspacePath.EndsWith("project2.csproj")
348
+ ? [new DirectUpdate() { DependencyName = "Some.Dependency", NewVersion = NuGetVersion.Parse("2.0.0"), UpdatedFiles = ["/src/Directory.Packages.csproj"] }]
349
+ : [];
350
+
351
+ return new UpdateOperationResult()
352
+ {
353
+ UpdateOperations = updateOperations,
354
+ };
355
+ }),
356
+ expectedUpdateHandler: RefreshSecurityUpdatePullRequestHandler.Instance,
357
+ expectedApiMessages: [
358
+ new UpdatedDependencyList()
359
+ {
360
+ Dependencies = [
361
+ new()
362
+ {
363
+ Name = "Some.Dependency",
364
+ Version = "1.0.0",
365
+ Requirements = [
366
+ new() { Requirement = "1.0.0", File = "/src/project1.csproj", Groups = ["dependencies"] },
367
+ ],
368
+ },
369
+ new()
370
+ {
371
+ Name = "Some.Dependency",
372
+ Version = "1.0.0",
373
+ Requirements = [
374
+ new() { Requirement = "1.0.0", File = "/src/project2.csproj", Groups = ["dependencies"] },
375
+ ],
376
+ },
377
+ ],
378
+ DependencyFiles = ["/src/Directory.Packages.props", "/src/project1.csproj", "/src/project2.csproj"],
379
+ },
380
+ new IncrementMetric()
381
+ {
382
+ Metric = "updater.started",
383
+ Tags = new()
384
+ {
385
+ ["operation"] = "update_security_pr",
386
+ }
387
+ },
388
+ new UpdatePullRequest()
389
+ {
390
+ DependencyNames = ["Some.Dependency"],
391
+ DependencyGroup = null,
392
+ UpdatedDependencyFiles = [
393
+ new()
394
+ {
395
+ Directory = "/src",
396
+ Name = "Directory.Packages.props",
397
+ Content = "updated contents",
398
+ }
399
+ ],
400
+ BaseCommitSha = "TEST-COMMIT-SHA",
401
+ CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
402
+ PrTitle = RunWorkerTests.TestPullRequestTitle,
403
+ PrBody = RunWorkerTests.TestPullRequestBody,
404
+ },
405
+ new MarkAsProcessed("TEST-COMMIT-SHA"),
406
+ ]
407
+ );
408
+ }
409
+
410
+ [Fact]
411
+ public async Task GeneratesUpdatePullRequest_FirstDependencyNotAbleToUpdate()
412
+ {
413
+ var responseNumber = 0; // used to track which request was sent
414
+ await TestAsync(
415
+ job: new Job()
416
+ {
417
+ Dependencies = ["Some.Dependency"],
418
+ ExistingPullRequests = [new() { Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("2.0.0") }] }],
419
+ SecurityAdvisories = [new() { DependencyName = "Some.Dependency", AffectedVersions = [Requirement.Parse("= 1.0.0")] }],
420
+ SecurityUpdatesOnly = true,
421
+ Source = CreateJobSource("/src"),
422
+ UpdatingAPullRequest = true,
423
+ },
424
+ files: [
425
+ ("src/Directory.Packages.props", "initial contents"),
426
+ ("src/project1.csproj", "initial contents"),
427
+ ("src/project2.csproj", "initial contents"),
428
+ ],
429
+ discoveryWorker: TestDiscoveryWorker.FromResults(
430
+ ("/src", new WorkspaceDiscoveryResult()
431
+ {
432
+ Path = "/src",
433
+ Projects = [
434
+ new()
435
+ {
436
+ FilePath = "project1.csproj",
437
+ Dependencies = [
438
+ new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
439
+ ],
440
+ ImportedFiles = ["Directory.Packages.props"],
441
+ AdditionalFiles = [],
442
+ },
443
+ new()
444
+ {
445
+ FilePath = "project2.csproj",
446
+ Dependencies = [
447
+ new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
448
+ ],
449
+ ImportedFiles = ["Directory.Packages.props"],
450
+ AdditionalFiles = [],
451
+ },
452
+ ],
453
+ })
454
+ ),
455
+ analyzeWorker: new TestAnalyzeWorker(input =>
456
+ {
457
+ var repoRoot = input.Item1;
458
+ var discovery = input.Item2;
459
+ var dependencyInfo = input.Item3;
460
+ if (dependencyInfo.Name != "Some.Dependency")
461
+ {
462
+ throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}");
463
+ }
464
+
465
+ AnalysisResult result = responseNumber == 0
466
+ ? new() { CanUpdate = false, UpdatedVersion = "1.0.0", UpdatedDependencies = [] }
467
+ : new() { CanUpdate = true, UpdatedVersion = "2.0.0", UpdatedDependencies = [] };
468
+ responseNumber++;
469
+
470
+ return Task.FromResult(result);
471
+ }),
472
+ updaterWorker: new TestUpdaterWorker(async input =>
473
+ {
474
+ var repoRoot = input.Item1;
475
+ var workspacePath = input.Item2;
476
+ var dependencyName = input.Item3;
477
+ var previousVersion = input.Item4;
478
+ var newVersion = input.Item5;
479
+ var isTransitive = input.Item6;
480
+
481
+ await File.WriteAllTextAsync(Path.Join(repoRoot, "src/Directory.Packages.props"), "updated contents");
482
+
483
+ // only report an update performed on the second project
484
+ ImmutableArray<UpdateOperationBase> updateOperations = workspacePath.EndsWith("project2.csproj")
485
+ ? [new DirectUpdate() { DependencyName = "Some.Dependency", NewVersion = NuGetVersion.Parse("2.0.0"), UpdatedFiles = ["/src/Directory.Packages.csproj"] }]
486
+ : [];
487
+
488
+ return new UpdateOperationResult()
489
+ {
490
+ UpdateOperations = updateOperations,
491
+ };
492
+ }),
493
+ expectedUpdateHandler: RefreshSecurityUpdatePullRequestHandler.Instance,
494
+ expectedApiMessages: [
495
+ new UpdatedDependencyList()
496
+ {
497
+ Dependencies = [
498
+ new()
499
+ {
500
+ Name = "Some.Dependency",
501
+ Version = "1.0.0",
502
+ Requirements = [
503
+ new() { Requirement = "1.0.0", File = "/src/project1.csproj", Groups = ["dependencies"] },
504
+ ],
505
+ },
506
+ new()
507
+ {
508
+ Name = "Some.Dependency",
509
+ Version = "1.0.0",
510
+ Requirements = [
511
+ new() { Requirement = "1.0.0", File = "/src/project2.csproj", Groups = ["dependencies"] },
512
+ ],
513
+ },
514
+ ],
515
+ DependencyFiles = ["/src/Directory.Packages.props", "/src/project1.csproj", "/src/project2.csproj"],
516
+ },
517
+ new IncrementMetric()
518
+ {
519
+ Metric = "updater.started",
520
+ Tags = new()
521
+ {
522
+ ["operation"] = "update_security_pr",
523
+ }
524
+ },
525
+ new UpdatePullRequest()
526
+ {
527
+ DependencyNames = ["Some.Dependency"],
528
+ DependencyGroup = null,
529
+ UpdatedDependencyFiles = [
530
+ new()
531
+ {
532
+ Directory = "/src",
533
+ Name = "Directory.Packages.props",
534
+ Content = "updated contents",
535
+ }
536
+ ],
537
+ BaseCommitSha = "TEST-COMMIT-SHA",
538
+ CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
539
+ PrTitle = RunWorkerTests.TestPullRequestTitle,
540
+ PrBody = RunWorkerTests.TestPullRequestBody,
541
+ },
542
+ new MarkAsProcessed("TEST-COMMIT-SHA"),
543
+ ]
544
+ );
545
+ }
546
+
274
547
  [Fact]
275
548
  public async Task GeneratesClosePullRequest_DependenciesRemoved()
276
549
  {
@@ -1,3 +1,5 @@
1
+ using System.Collections.Immutable;
2
+
1
3
  using NuGet.Versioning;
2
4
 
3
5
  using NuGetUpdater.Core.Analyze;
@@ -131,6 +133,311 @@ public class RefreshVersionUpdatePullRequestHandlerTests : UpdateHandlersTestsBa
131
133
  );
132
134
  }
133
135
 
136
+ [Fact]
137
+ public async Task GeneratesUpdatePullRequest_FirstUpdateDidNothingSecondUpdateSucceeded()
138
+ {
139
+ await TestAsync(
140
+ job: new Job()
141
+ {
142
+ Dependencies = ["Some.Dependency"],
143
+ ExistingPullRequests = [new() { Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("2.0.0") }] }],
144
+ Source = CreateJobSource("/src"),
145
+ UpdatingAPullRequest = true,
146
+ },
147
+ files: [
148
+ ("src/project1.csproj", "initial contents"),
149
+ ("src/project2.csproj", "initial contents"),
150
+ ],
151
+ discoveryWorker: TestDiscoveryWorker.FromResults(
152
+ ("/src", new WorkspaceDiscoveryResult()
153
+ {
154
+ Path = "/src",
155
+ Projects = [
156
+ new()
157
+ {
158
+ FilePath = "project1.csproj",
159
+ Dependencies = [
160
+ new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
161
+ new("Unrelated.Dependency", "3.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
162
+ ],
163
+ ImportedFiles = [],
164
+ AdditionalFiles = [],
165
+ },
166
+ new()
167
+ {
168
+ FilePath = "project2.csproj",
169
+ Dependencies = [
170
+ new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
171
+ new("Unrelated.Dependency", "3.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
172
+ ],
173
+ ImportedFiles = [],
174
+ AdditionalFiles = [],
175
+ },
176
+ ],
177
+ })
178
+ ),
179
+ analyzeWorker: new TestAnalyzeWorker(input =>
180
+ {
181
+ var repoRoot = input.Item1;
182
+ var discovery = input.Item2;
183
+ var dependencyInfo = input.Item3;
184
+ if (dependencyInfo.Name != "Some.Dependency")
185
+ {
186
+ throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}");
187
+ }
188
+
189
+ return Task.FromResult(new AnalysisResult()
190
+ {
191
+ CanUpdate = true,
192
+ UpdatedVersion = "2.0.0",
193
+ UpdatedDependencies = [],
194
+ });
195
+ }),
196
+ updaterWorker: new TestUpdaterWorker(async input =>
197
+ {
198
+ var repoRoot = input.Item1;
199
+ var workspacePath = input.Item2;
200
+ var dependencyName = input.Item3;
201
+ var previousVersion = input.Item4;
202
+ var newVersion = input.Item5;
203
+ var isTransitive = input.Item6;
204
+
205
+ ImmutableArray<UpdateOperationBase> updateOperations = [];
206
+ if (workspacePath.EndsWith("project2.csproj"))
207
+ {
208
+ // only report an update performed on the second project
209
+ updateOperations = [new DirectUpdate() { DependencyName = "Some.Dependency", NewVersion = NuGetVersion.Parse("2.0.0"), UpdatedFiles = ["/src/project2.csproj"] }];
210
+ await File.WriteAllTextAsync(Path.Join(repoRoot, workspacePath), "updated contents");
211
+ }
212
+
213
+ return new UpdateOperationResult()
214
+ {
215
+ UpdateOperations = updateOperations,
216
+ };
217
+ }),
218
+ expectedUpdateHandler: RefreshVersionUpdatePullRequestHandler.Instance,
219
+ expectedApiMessages: [
220
+ new UpdatedDependencyList()
221
+ {
222
+ Dependencies = [
223
+ new()
224
+ {
225
+ Name = "Some.Dependency",
226
+ Version = "1.0.0",
227
+ Requirements = [
228
+ new() { Requirement = "1.0.0", File = "/src/project1.csproj", Groups = ["dependencies"] },
229
+ ],
230
+ },
231
+ new()
232
+ {
233
+ Name = "Unrelated.Dependency",
234
+ Version = "3.0.0",
235
+ Requirements = [
236
+ new() { Requirement = "3.0.0", File = "/src/project1.csproj", Groups = ["dependencies"] },
237
+ ],
238
+ },
239
+ new()
240
+ {
241
+ Name = "Some.Dependency",
242
+ Version = "1.0.0",
243
+ Requirements = [
244
+ new() { Requirement = "1.0.0", File = "/src/project2.csproj", Groups = ["dependencies"] },
245
+ ],
246
+ },
247
+ new()
248
+ {
249
+ Name = "Unrelated.Dependency",
250
+ Version = "3.0.0",
251
+ Requirements = [
252
+ new() { Requirement = "3.0.0", File = "/src/project2.csproj", Groups = ["dependencies"] },
253
+ ],
254
+ },
255
+ ],
256
+ DependencyFiles = ["/src/project1.csproj", "/src/project2.csproj"],
257
+ },
258
+ new IncrementMetric()
259
+ {
260
+ Metric = "updater.started",
261
+ Tags = new()
262
+ {
263
+ ["operation"] = "update_version_pr",
264
+ }
265
+ },
266
+ new UpdatePullRequest()
267
+ {
268
+ DependencyNames = ["Some.Dependency"],
269
+ DependencyGroup = null,
270
+ UpdatedDependencyFiles = [
271
+ new()
272
+ {
273
+ Directory = "/src",
274
+ Name = "project2.csproj",
275
+ Content = "updated contents",
276
+ }
277
+ ],
278
+ BaseCommitSha = "TEST-COMMIT-SHA",
279
+ CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
280
+ PrTitle = RunWorkerTests.TestPullRequestTitle,
281
+ PrBody = RunWorkerTests.TestPullRequestBody,
282
+ },
283
+ new MarkAsProcessed("TEST-COMMIT-SHA"),
284
+ ]
285
+ );
286
+ }
287
+
288
+ [Fact]
289
+ public async Task GeneratesUpdatePullRequest_FirstDependencyNotAbleToUpdate()
290
+ {
291
+ var responseNumber = 0; // used to track which request was sent
292
+ await TestAsync(
293
+ job: new Job()
294
+ {
295
+ Dependencies = ["Some.Dependency"],
296
+ ExistingPullRequests = [new() { Dependencies = [new() { DependencyName = "Some.Dependency", DependencyVersion = NuGetVersion.Parse("2.0.0") }] }],
297
+ Source = CreateJobSource("/src"),
298
+ UpdatingAPullRequest = true,
299
+ },
300
+ files: [
301
+ ("src/project1.csproj", "initial contents"),
302
+ ("src/project2.csproj", "initial contents"),
303
+ ],
304
+ discoveryWorker: TestDiscoveryWorker.FromResults(
305
+ ("/src", new WorkspaceDiscoveryResult()
306
+ {
307
+ Path = "/src",
308
+ Projects = [
309
+ new()
310
+ {
311
+ FilePath = "project1.csproj",
312
+ Dependencies = [
313
+ new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
314
+ new("Unrelated.Dependency", "3.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
315
+ ],
316
+ ImportedFiles = [],
317
+ AdditionalFiles = [],
318
+ },
319
+ new()
320
+ {
321
+ FilePath = "project2.csproj",
322
+ Dependencies = [
323
+ new("Some.Dependency", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
324
+ new("Unrelated.Dependency", "3.0.0", DependencyType.PackageReference, TargetFrameworks: ["net9.0"]),
325
+ ],
326
+ ImportedFiles = [],
327
+ AdditionalFiles = [],
328
+ },
329
+ ],
330
+ })
331
+ ),
332
+ analyzeWorker: new TestAnalyzeWorker(input =>
333
+ {
334
+ var repoRoot = input.Item1;
335
+ var discovery = input.Item2;
336
+ var dependencyInfo = input.Item3;
337
+ if (dependencyInfo.Name != "Some.Dependency")
338
+ {
339
+ throw new NotImplementedException($"Test didn't expect to update dependency {dependencyInfo.Name}");
340
+ }
341
+
342
+ AnalysisResult result = responseNumber == 0
343
+ ? new() { CanUpdate = false, UpdatedVersion = "1.0.0", UpdatedDependencies = [] }
344
+ : new() { CanUpdate = true, UpdatedVersion = "2.0.0", UpdatedDependencies = [] };
345
+ responseNumber++;
346
+
347
+ return Task.FromResult(result);
348
+ }),
349
+ updaterWorker: new TestUpdaterWorker(async input =>
350
+ {
351
+ var repoRoot = input.Item1;
352
+ var workspacePath = input.Item2;
353
+ var dependencyName = input.Item3;
354
+ var previousVersion = input.Item4;
355
+ var newVersion = input.Item5;
356
+ var isTransitive = input.Item6;
357
+
358
+ ImmutableArray<UpdateOperationBase> updateOperations = [];
359
+ if (workspacePath.EndsWith("project2.csproj"))
360
+ {
361
+ // only report an update performed on the second project
362
+ updateOperations = [new DirectUpdate() { DependencyName = "Some.Dependency", NewVersion = NuGetVersion.Parse("2.0.0"), UpdatedFiles = ["/src/project2.csproj"] }];
363
+ await File.WriteAllTextAsync(Path.Join(repoRoot, workspacePath), "updated contents");
364
+ }
365
+
366
+ return new UpdateOperationResult()
367
+ {
368
+ UpdateOperations = updateOperations,
369
+ };
370
+ }),
371
+ expectedUpdateHandler: RefreshVersionUpdatePullRequestHandler.Instance,
372
+ expectedApiMessages: [
373
+ new UpdatedDependencyList()
374
+ {
375
+ Dependencies = [
376
+ new()
377
+ {
378
+ Name = "Some.Dependency",
379
+ Version = "1.0.0",
380
+ Requirements = [
381
+ new() { Requirement = "1.0.0", File = "/src/project1.csproj", Groups = ["dependencies"] },
382
+ ],
383
+ },
384
+ new()
385
+ {
386
+ Name = "Unrelated.Dependency",
387
+ Version = "3.0.0",
388
+ Requirements = [
389
+ new() { Requirement = "3.0.0", File = "/src/project1.csproj", Groups = ["dependencies"] },
390
+ ],
391
+ },
392
+ new()
393
+ {
394
+ Name = "Some.Dependency",
395
+ Version = "1.0.0",
396
+ Requirements = [
397
+ new() { Requirement = "1.0.0", File = "/src/project2.csproj", Groups = ["dependencies"] },
398
+ ],
399
+ },
400
+ new()
401
+ {
402
+ Name = "Unrelated.Dependency",
403
+ Version = "3.0.0",
404
+ Requirements = [
405
+ new() { Requirement = "3.0.0", File = "/src/project2.csproj", Groups = ["dependencies"] },
406
+ ],
407
+ },
408
+ ],
409
+ DependencyFiles = ["/src/project1.csproj", "/src/project2.csproj"],
410
+ },
411
+ new IncrementMetric()
412
+ {
413
+ Metric = "updater.started",
414
+ Tags = new()
415
+ {
416
+ ["operation"] = "update_version_pr",
417
+ }
418
+ },
419
+ new UpdatePullRequest()
420
+ {
421
+ DependencyNames = ["Some.Dependency"],
422
+ DependencyGroup = null,
423
+ UpdatedDependencyFiles = [
424
+ new()
425
+ {
426
+ Directory = "/src",
427
+ Name = "project2.csproj",
428
+ Content = "updated contents",
429
+ }
430
+ ],
431
+ BaseCommitSha = "TEST-COMMIT-SHA",
432
+ CommitMessage = RunWorkerTests.TestPullRequestCommitMessage,
433
+ PrTitle = RunWorkerTests.TestPullRequestTitle,
434
+ PrBody = RunWorkerTests.TestPullRequestBody,
435
+ },
436
+ new MarkAsProcessed("TEST-COMMIT-SHA"),
437
+ ]
438
+ );
439
+ }
440
+
134
441
  [Fact]
135
442
  public async Task GeneratesClosePullRequest_DependenciesRemoved()
136
443
  {
@@ -189,7 +189,8 @@ public class PackageReferenceUpdaterTests
189
189
  MockNuGetPackage.CreateSimplePackage("Transitive.Package", "1.0.0", "net9.0", [(null, [("Super.Transitive.Package", "1.0.0")])]),
190
190
  MockNuGetPackage.CreateSimplePackage("Transitive.Package", "2.0.0", "net9.0", [(null, [("Super.Transitive.Package", "2.0.0")])]),
191
191
  MockNuGetPackage.CreateSimplePackage("Super.Transitive.Package", "1.0.0", "net9.0"),
192
- MockNuGetPackage.CreateSimplePackage("Super.Transitive.Package", "2.0.0", "net9.0")
192
+ MockNuGetPackage.CreateSimplePackage("Super.Transitive.Package", "2.0.0", "net9.0"),
193
+ MockNuGetPackage.CreateSimplePackage("Unrelated.Package", "1.0.0", "net9.0"),
193
194
  ], repoRoot.DirectoryPath);
194
195
 
195
196
  // act
@@ -331,5 +332,54 @@ public class PackageReferenceUpdaterTests
331
332
  }
332
333
  )
333
334
  ];
335
+
336
+ // dependency was not updated
337
+ yield return
338
+ [
339
+ // topLevelDependencies
340
+ ImmutableArray.Create(
341
+ new Dependency("Parent.Package", "1.0.0", DependencyType.PackageReference)
342
+ ),
343
+ // requestedUpdates
344
+ ImmutableArray.Create(
345
+ new Dependency("Transitive.Package", "2.0.0", DependencyType.PackageReference)
346
+ ),
347
+ // resolvedDependencies
348
+ ImmutableArray.Create(
349
+ new Dependency("Parent.Package", "1.0.0", DependencyType.PackageReference)
350
+ ),
351
+ // expectedUpdateOperations
352
+ ImmutableArray<UpdateOperationBase>.Empty,
353
+ ];
354
+
355
+ // initial dependency has a wildcard
356
+ yield return
357
+ [
358
+ // topLevelDependencies
359
+ ImmutableArray.Create(
360
+ new Dependency("Parent.Package", "1.0.0", DependencyType.PackageReference),
361
+ new Dependency("Unrelated.Package", "1.0.*", DependencyType.PackageReference)
362
+ ),
363
+ // requestedUpdates
364
+ ImmutableArray.Create(
365
+ new Dependency("Transitive.Package", "2.0.0", DependencyType.PackageReference)
366
+ ),
367
+ // resolvedDependencies
368
+ ImmutableArray.Create(
369
+ new Dependency("Parent.Package", "2.0.0", DependencyType.PackageReference),
370
+ new Dependency("Unrelated.Package", "1.0.0", DependencyType.PackageReference)
371
+ ),
372
+ // expectedUpdateOperations
373
+ ImmutableArray.Create<UpdateOperationBase>(
374
+ new ParentUpdate()
375
+ {
376
+ DependencyName = "Transitive.Package",
377
+ NewVersion = NuGetVersion.Parse("2.0.0"),
378
+ UpdatedFiles = [],
379
+ ParentDependencyName = "Parent.Package",
380
+ ParentNewVersion = NuGetVersion.Parse("2.0.0"),
381
+ }
382
+ ),
383
+ ];
334
384
  }
335
385
  }