dependabot-nuget 0.321.2 → 0.322.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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/lib/NuGetUpdater/Directory.Packages.props +22 -22
  3. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation/Model/PackageMapper.cs +9 -0
  4. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation.Cli/Program.cs +21 -7
  5. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/AnalyzeCommand.cs +19 -11
  6. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/CloneCommand.cs +19 -9
  7. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/DiscoverCommand.cs +21 -14
  8. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/FrameworkCheckCommand.cs +8 -5
  9. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/RunCommand.cs +29 -16
  10. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/UpdateCommand.cs +20 -19
  11. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Program.cs +2 -1
  12. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyDiscoveryTargetingPacks.props +2 -0
  13. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencySolver/IDependencySolver.cs +8 -0
  14. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencySolver/MSBuildDependencySolver.cs +32 -0
  15. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/ProjectDiscoveryResult.cs +1 -0
  16. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs +10 -1
  17. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/WorkspaceDiscoveryResult.cs +6 -0
  18. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/ExperimentsManager.cs +3 -0
  19. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/GlobalJsonBuildFile.cs +5 -13
  20. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/PrivateSourceTimedOutException.cs +12 -0
  21. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/JobErrorBase.cs +4 -0
  22. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/PrivateSourceTimedOut.cs +10 -0
  23. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestTextGenerator.cs +1 -1
  24. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/CreateSecurityUpdatePullRequestHandler.cs +1 -1
  25. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/GroupUpdateAllVersionsHandler.cs +2 -2
  26. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshGroupUpdatePullRequestHandler.cs +1 -1
  27. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandler.cs +1 -1
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandler.cs +1 -1
  29. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/DotNetToolsJsonUpdater.cs +6 -3
  30. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/FileWriters/FileWriterWorker.cs +376 -0
  31. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/FileWriters/IFileWriter.cs +14 -0
  32. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/FileWriters/XmlFileWriter.cs +477 -0
  33. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/GlobalJsonUpdater.cs +9 -5
  34. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdateOperationBase.cs +18 -7
  35. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +26 -1
  36. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +15 -0
  37. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/DependencySolver/MSBuildDependencySolverTests.cs +633 -0
  38. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.GlobalJson.cs +0 -2
  39. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.cs +0 -2
  40. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/SdkProjectDiscoveryTests.cs +49 -0
  41. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/GlobalJsonBuildFileTests.cs +0 -1
  42. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/EndToEndTests.cs +484 -0
  43. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/HttpApiHandlerTests.cs +1 -0
  44. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/JobErrorBaseTests.cs +7 -0
  45. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/MessageReportTests.cs +11 -0
  46. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestTextTests.cs +21 -22
  47. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs +1 -1
  48. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/SerializationTests.cs +8 -0
  49. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/DotNetToolsJsonUpdaterTests.cs +181 -0
  50. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/FileWriterTestsBase.cs +61 -0
  51. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/FileWriterWorkerTests.cs +917 -0
  52. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/FileWriterWorkerTests_MiscellaneousTests.cs +154 -0
  53. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/TestFileWriterReturnsConstantResult.cs +20 -0
  54. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/XmlFileWriterTests.cs +1620 -0
  55. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/XmlFileWriterTests_CreateUpdatedVersionRangeTests.cs +25 -0
  56. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/GlobalJsonUpdaterTests.cs +139 -0
  57. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackagesConfigUpdaterTests.cs +1961 -1
  58. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateOperationResultTests.cs +116 -0
  59. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +16 -1043
  60. data/helpers/lib/NuGetUpdater/global.json +1 -1
  61. metadata +21 -10
  62. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DotNetTools.cs +0 -375
  63. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.GlobalJson.cs +0 -296
  64. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.LockFile.cs +0 -251
  65. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Mixed.cs +0 -201
  66. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackageReference.cs +0 -3821
  67. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +0 -2706
@@ -0,0 +1,1620 @@
1
+ using NuGetUpdater.Core.Updater.FileWriters;
2
+
3
+ using Xunit;
4
+
5
+ namespace NuGetUpdater.Core.Test.Update.FileWriters;
6
+
7
+ public class XmlFileWriterTests : FileWriterTestsBase
8
+ {
9
+ public override IFileWriter FileWriter => new XmlFileWriter(new TestLogger());
10
+
11
+ [Fact]
12
+ public async Task SingleDependency_SingleFile_AttributeDirectUpdate()
13
+ {
14
+ await TestAsync(
15
+ files: [
16
+ ("project.csproj", """
17
+ <Project Sdk="Microsoft.NET.Sdk">
18
+ <ItemGroup>
19
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
20
+ <PackageReference Include="Some.Dependency" Version="1.0.0" />
21
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
22
+ </ItemGroup>
23
+ </Project>
24
+ """)
25
+ ],
26
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
27
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
28
+ expectedFiles: [
29
+ ("project.csproj", """
30
+ <Project Sdk="Microsoft.NET.Sdk">
31
+ <ItemGroup>
32
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
33
+ <PackageReference Include="Some.Dependency" Version="2.0.0" />
34
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
35
+ </ItemGroup>
36
+ </Project>
37
+ """)
38
+ ]
39
+ );
40
+ }
41
+
42
+ [Fact]
43
+ public async Task SingleDependency_SingleFile_AttributeDirectUpdate_ProjectHasXmlNamespace()
44
+ {
45
+ await TestAsync(
46
+ files: [
47
+ ("project.csproj", """
48
+ <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
49
+ <ItemGroup>
50
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
51
+ <PackageReference Include="Some.Dependency" Version="1.0.0" />
52
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
53
+ </ItemGroup>
54
+ </Project>
55
+ """)
56
+ ],
57
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
58
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
59
+ expectedFiles: [
60
+ ("project.csproj", """
61
+ <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
62
+ <ItemGroup>
63
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
64
+ <PackageReference Include="Some.Dependency" Version="2.0.0" />
65
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
66
+ </ItemGroup>
67
+ </Project>
68
+ """)
69
+ ]
70
+ );
71
+ }
72
+
73
+ [Fact]
74
+ public async Task SingleDependency_SingleFile_AttributeDirectUpdate_IncludeAttributeHasExtraWhitespace()
75
+ {
76
+ await TestAsync(
77
+ files: [
78
+ ("project.csproj", """
79
+ <Project Sdk="Microsoft.NET.Sdk">
80
+ <ItemGroup>
81
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
82
+ <PackageReference Include=" Some.Dependency " Version="1.0.0" />
83
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
84
+ </ItemGroup>
85
+ </Project>
86
+ """)
87
+ ],
88
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
89
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
90
+ expectedFiles: [
91
+ ("project.csproj", """
92
+ <Project Sdk="Microsoft.NET.Sdk">
93
+ <ItemGroup>
94
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
95
+ <PackageReference Include=" Some.Dependency " Version="2.0.0" />
96
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
97
+ </ItemGroup>
98
+ </Project>
99
+ """)
100
+ ]
101
+ );
102
+ }
103
+
104
+ [Fact]
105
+ public async Task SingleDependency_SingleFile_AttributeDirectUpdate_MultipleSemicolonSeparatedPackages()
106
+ {
107
+ await TestAsync(
108
+ files: [
109
+ ("project.csproj", """
110
+ <Project Sdk="Microsoft.NET.Sdk">
111
+ <ItemGroup>
112
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
113
+ <PackageReference Include=" Some.Dependency ; Some.Other.Dependency " Version="1.0.0" />
114
+ </ItemGroup>
115
+ </Project>
116
+ """)
117
+ ],
118
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
119
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
120
+ expectedFiles: [
121
+ ("project.csproj", """
122
+ <Project Sdk="Microsoft.NET.Sdk">
123
+ <ItemGroup>
124
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
125
+ <PackageReference Include=" Some.Dependency ; Some.Other.Dependency " Version="2.0.0" />
126
+ </ItemGroup>
127
+ </Project>
128
+ """)
129
+ ]
130
+ );
131
+ }
132
+
133
+ [Fact]
134
+ public async Task SingleDependency_SingleFile_AttributeDirectUpdate_FourPartVersionNumber()
135
+ {
136
+ await TestAsync(
137
+ files: [
138
+ ("project.csproj", """
139
+ <Project Sdk="Microsoft.NET.Sdk">
140
+ <ItemGroup>
141
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
142
+ <PackageReference Include="Some.Dependency" Version="1.0.0.0" />
143
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
144
+ </ItemGroup>
145
+ </Project>
146
+ """)
147
+ ],
148
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0.0"],
149
+ requiredDependencyStrings: ["Some.Dependency/2.0.0.0"],
150
+ expectedFiles: [
151
+ ("project.csproj", """
152
+ <Project Sdk="Microsoft.NET.Sdk">
153
+ <ItemGroup>
154
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
155
+ <PackageReference Include="Some.Dependency" Version="2.0.0.0" />
156
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
157
+ </ItemGroup>
158
+ </Project>
159
+ """)
160
+ ]
161
+ );
162
+ }
163
+
164
+ [Fact]
165
+ public async Task SingleDependency_SingleFile_AttributeDirectUpdate_AttributeCasingIsWrong()
166
+ {
167
+ await TestAsync(
168
+ files: [
169
+ ("project.csproj", """
170
+ <Project Sdk="Microsoft.NET.Sdk">
171
+ <ItemGroup>
172
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
173
+ <PackageReference Include="Some.Dependency" VERSION="1.0.0" />
174
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
175
+ </ItemGroup>
176
+ </Project>
177
+ """)
178
+ ],
179
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
180
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
181
+ expectedFiles: [
182
+ ("project.csproj", """
183
+ <Project Sdk="Microsoft.NET.Sdk">
184
+ <ItemGroup>
185
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
186
+ <PackageReference Include="Some.Dependency" VERSION="2.0.0" />
187
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
188
+ </ItemGroup>
189
+ </Project>
190
+ """)
191
+ ]
192
+ );
193
+ }
194
+
195
+ [Fact]
196
+ public async Task SingleDependency_SingleFile_AttributeDirectUpdate_ExactMatchVersionRange()
197
+ {
198
+ await TestAsync(
199
+ files: [
200
+ ("project.csproj", """
201
+ <Project Sdk="Microsoft.NET.Sdk">
202
+ <ItemGroup>
203
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
204
+ <PackageReference Include="Some.Dependency" Version="[1.0.0]" />
205
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
206
+ </ItemGroup>
207
+ </Project>
208
+ """)
209
+ ],
210
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
211
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
212
+ expectedFiles: [
213
+ ("project.csproj", """
214
+ <Project Sdk="Microsoft.NET.Sdk">
215
+ <ItemGroup>
216
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
217
+ <PackageReference Include="Some.Dependency" Version="[2.0.0]" />
218
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
219
+ </ItemGroup>
220
+ </Project>
221
+ """)
222
+ ]
223
+ );
224
+ }
225
+
226
+ [Fact]
227
+ public async Task SingleDependency_SingleFile_AttributeDirectUpdate_ExactMatchVersionRangeFromPropertyEvaluation()
228
+ {
229
+ await TestAsync(
230
+ files: [
231
+ ("project.csproj", """
232
+ <Project Sdk="Microsoft.NET.Sdk">
233
+ <PropertyGroup>
234
+ <SomeDependencyVersion>1.0.0</SomeDependencyVersion>
235
+ </PropertyGroup>
236
+ <ItemGroup>
237
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
238
+ <PackageReference Include="Some.Dependency" Version="[$(SomeDependencyVersion)]" />
239
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
240
+ </ItemGroup>
241
+ </Project>
242
+ """)
243
+ ],
244
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
245
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
246
+ expectedFiles: [
247
+ ("project.csproj", """
248
+ <Project Sdk="Microsoft.NET.Sdk">
249
+ <PropertyGroup>
250
+ <SomeDependencyVersion>2.0.0</SomeDependencyVersion>
251
+ </PropertyGroup>
252
+ <ItemGroup>
253
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
254
+ <PackageReference Include="Some.Dependency" Version="[$(SomeDependencyVersion)]" />
255
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
256
+ </ItemGroup>
257
+ </Project>
258
+ """)
259
+ ]
260
+ );
261
+ }
262
+
263
+ [Fact]
264
+ public async Task SingleDependency_SingleFile_AttributeDirectUpdate_ExactMatchVersionRangeFromPropertyValue()
265
+ {
266
+ await TestAsync(
267
+ files: [
268
+ ("project.csproj", """
269
+ <Project Sdk="Microsoft.NET.Sdk">
270
+ <PropertyGroup>
271
+ <SomeDependencyVersion>[1.0.0]</SomeDependencyVersion>
272
+ </PropertyGroup>
273
+ <ItemGroup>
274
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
275
+ <PackageReference Include="Some.Dependency" Version="$(SomeDependencyVersion)" />
276
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
277
+ </ItemGroup>
278
+ </Project>
279
+ """)
280
+ ],
281
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
282
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
283
+ expectedFiles: [
284
+ ("project.csproj", """
285
+ <Project Sdk="Microsoft.NET.Sdk">
286
+ <PropertyGroup>
287
+ <SomeDependencyVersion>[2.0.0]</SomeDependencyVersion>
288
+ </PropertyGroup>
289
+ <ItemGroup>
290
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
291
+ <PackageReference Include="Some.Dependency" Version="$(SomeDependencyVersion)" />
292
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
293
+ </ItemGroup>
294
+ </Project>
295
+ """)
296
+ ]
297
+ );
298
+ }
299
+
300
+ [Fact]
301
+ public async Task SingleDependency_SingleFile_UpdateVersionAttribute()
302
+ {
303
+ await TestAsync(
304
+ files: [
305
+ ("project.csproj", """
306
+ <Project Sdk="Microsoft.NET.Sdk">
307
+ <ItemGroup>
308
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
309
+ <PackageReference Include="Some.Dependency" />
310
+ <PackageReference Update="Some.Dependency" Version="1.0.0" />
311
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
312
+ </ItemGroup>
313
+ </Project>
314
+ """)
315
+ ],
316
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
317
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
318
+ expectedFiles: [
319
+ ("project.csproj", """
320
+ <Project Sdk="Microsoft.NET.Sdk">
321
+ <ItemGroup>
322
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
323
+ <PackageReference Include="Some.Dependency" />
324
+ <PackageReference Update="Some.Dependency" Version="2.0.0" />
325
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
326
+ </ItemGroup>
327
+ </Project>
328
+ """)
329
+ ]
330
+ );
331
+ }
332
+
333
+ [Fact]
334
+ public async Task SingleDependency_SingleFile_UpdateVersionElement()
335
+ {
336
+ await TestAsync(
337
+ files: [
338
+ ("project.csproj", """
339
+ <Project Sdk="Microsoft.NET.Sdk">
340
+ <ItemGroup>
341
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
342
+ <PackageReference Include="Some.Dependency" />
343
+ <PackageReference Update="Some.Dependency">
344
+ <Version>1.0.0</Version>
345
+ </PackageReference>
346
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
347
+ </ItemGroup>
348
+ </Project>
349
+ """)
350
+ ],
351
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
352
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
353
+ expectedFiles: [
354
+ ("project.csproj", """
355
+ <Project Sdk="Microsoft.NET.Sdk">
356
+ <ItemGroup>
357
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
358
+ <PackageReference Include="Some.Dependency" />
359
+ <PackageReference Update="Some.Dependency">
360
+ <Version>2.0.0</Version>
361
+ </PackageReference>
362
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
363
+ </ItemGroup>
364
+ </Project>
365
+ """)
366
+ ]
367
+ );
368
+ }
369
+
370
+ [Fact]
371
+ public async Task SingleDependency_SingleFile_UpdateVersionAttribute_ThroughProperty()
372
+ {
373
+ await TestAsync(
374
+ files: [
375
+ ("project.csproj", """
376
+ <Project Sdk="Microsoft.NET.Sdk">
377
+ <PropertyGroup>
378
+ <SomeDependencyVersion>1.0.0</SomeDependencyVersion>
379
+ </PropertyGroup>
380
+ <ItemGroup>
381
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
382
+ <PackageReference Include="Some.Dependency" />
383
+ <PackageReference Update="Some.Dependency" Version="$(SomeDependencyVersion)" />
384
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
385
+ </ItemGroup>
386
+ </Project>
387
+ """)
388
+ ],
389
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
390
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
391
+ expectedFiles: [
392
+ ("project.csproj", """
393
+ <Project Sdk="Microsoft.NET.Sdk">
394
+ <PropertyGroup>
395
+ <SomeDependencyVersion>2.0.0</SomeDependencyVersion>
396
+ </PropertyGroup>
397
+ <ItemGroup>
398
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
399
+ <PackageReference Include="Some.Dependency" />
400
+ <PackageReference Update="Some.Dependency" Version="$(SomeDependencyVersion)" />
401
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
402
+ </ItemGroup>
403
+ </Project>
404
+ """)
405
+ ]
406
+ );
407
+ }
408
+
409
+ [Fact]
410
+ public async Task SingleDependency_SingleFile_DuplicateEntry_DirectUpdateForBoth()
411
+ {
412
+ await TestAsync(
413
+ files: [
414
+ ("project.csproj", """
415
+ <Project Sdk="Microsoft.NET.Sdk">
416
+ <ItemGroup>
417
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
418
+ <PackageReference Include="Some.Dependency" Version="1.0.0" />
419
+ <PackageReference Include="Some.Dependency">
420
+ <Version>1.0.0</Version>
421
+ </PackageReference>
422
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
423
+ </ItemGroup>
424
+ </Project>
425
+ """)
426
+ ],
427
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
428
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
429
+ expectedFiles: [
430
+ ("project.csproj", """
431
+ <Project Sdk="Microsoft.NET.Sdk">
432
+ <ItemGroup>
433
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
434
+ <PackageReference Include="Some.Dependency" Version="2.0.0" />
435
+ <PackageReference Include="Some.Dependency">
436
+ <Version>2.0.0</Version>
437
+ </PackageReference>
438
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
439
+ </ItemGroup>
440
+ </Project>
441
+ """)
442
+ ]
443
+ );
444
+ }
445
+
446
+ [Fact]
447
+ public async Task SingleDependency_SingleFile_DuplicateEntry_DirectUpdateAndPropertyUpdate()
448
+ {
449
+ await TestAsync(
450
+ files: [
451
+ ("project.csproj", """
452
+ <Project Sdk="Microsoft.NET.Sdk">
453
+ <PropertyGroup>
454
+ <SomeDependencyVersion>1.0.0</SomeDependencyVersion>
455
+ </PropertyGroup>
456
+ <ItemGroup>
457
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
458
+ <PackageReference Include="Some.Dependency" Version="1.0.0" />
459
+ <PackageReference Include="Some.Dependency">
460
+ <Version>$(SomeDependencyVersion)</Version>
461
+ </PackageReference>
462
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
463
+ </ItemGroup>
464
+ </Project>
465
+ """)
466
+ ],
467
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
468
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
469
+ expectedFiles: [
470
+ ("project.csproj", """
471
+ <Project Sdk="Microsoft.NET.Sdk">
472
+ <PropertyGroup>
473
+ <SomeDependencyVersion>2.0.0</SomeDependencyVersion>
474
+ </PropertyGroup>
475
+ <ItemGroup>
476
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
477
+ <PackageReference Include="Some.Dependency" Version="2.0.0" />
478
+ <PackageReference Include="Some.Dependency">
479
+ <Version>$(SomeDependencyVersion)</Version>
480
+ </PackageReference>
481
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
482
+ </ItemGroup>
483
+ </Project>
484
+ """)
485
+ ]
486
+ );
487
+ }
488
+
489
+ [Fact]
490
+ public async Task SingleDependency_SingleFile_GlobalPackageReference()
491
+ {
492
+ await TestAsync(
493
+ files: [
494
+ ("project.csproj", """
495
+ <Project Sdk="Microsoft.NET.Sdk" />
496
+ """),
497
+ ("Directory.Packages.props", """
498
+ <Project>
499
+ <PropertyGroup>
500
+ <SomeDependencyVersion>1.0.0</SomeDependencyVersion>
501
+ </PropertyGroup>
502
+ <ItemGroup>
503
+ <GlobalPackageReference Include="Ignored.Dependency" Version="7.0.0" />
504
+ <GlobalPackageReference Include="Some.Dependency" Version="$(SomeDependencyVersion)" />
505
+ <GlobalPackageReference Include="Some.Other.Dependency" Version="8.0.0" />
506
+ </ItemGroup>
507
+ </Project>
508
+ """)
509
+ ],
510
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
511
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
512
+ expectedFiles: [
513
+ ("project.csproj", """
514
+ <Project Sdk="Microsoft.NET.Sdk" />
515
+ """),
516
+ ("Directory.Packages.props", """
517
+ <Project>
518
+ <PropertyGroup>
519
+ <SomeDependencyVersion>2.0.0</SomeDependencyVersion>
520
+ </PropertyGroup>
521
+ <ItemGroup>
522
+ <GlobalPackageReference Include="Ignored.Dependency" Version="7.0.0" />
523
+ <GlobalPackageReference Include="Some.Dependency" Version="$(SomeDependencyVersion)" />
524
+ <GlobalPackageReference Include="Some.Other.Dependency" Version="8.0.0" />
525
+ </ItemGroup>
526
+ </Project>
527
+ """)
528
+ ]
529
+ );
530
+ }
531
+
532
+ [Theory]
533
+ [InlineData("$(SomeDependencyVersion")] // missing close paren
534
+ [InlineData("$SomeDependencyVersion)")] // missing open paren
535
+ [InlineData("$SomeDependencyVersion")] // missing both parens
536
+ [InlineData("SomeDependencyVersion)")] // missing expansion and open paren
537
+ public async Task SingleDependency_SingleFile_InvalidPropertyExpansionFailsGracefully(string versionString)
538
+ {
539
+ await TestNoChangeAsync(
540
+ files: [
541
+ ("project.csproj", $"""
542
+ <Project Sdk="Microsoft.NET.Sdk">
543
+ <PropertyGroup>
544
+ <SomeDependencyVersion>9.0.1</SomeDependencyVersion>
545
+ </PropertyGroup>
546
+ <ItemGroup>
547
+ <PackageReference Include="Some.Dependency" Version="{versionString}" />
548
+ </ItemGroup>
549
+ </Project>
550
+ """)
551
+ ],
552
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
553
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"]
554
+ );
555
+ }
556
+
557
+ [Fact]
558
+ public async Task SingleDependency_SingleFile_MissingPropertyFailsGracefully()
559
+ {
560
+ await TestNoChangeAsync(
561
+ files: [
562
+ ("project.csproj", """
563
+ <Project Sdk="Microsoft.NET.Sdk">
564
+ <ItemGroup>
565
+ <PackageReference Include="Some.Dependency" Version="$(SomeDependencyVersion)" />
566
+ </ItemGroup>
567
+ </Project>
568
+ """)
569
+ ],
570
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
571
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"]
572
+ );
573
+ }
574
+
575
+ [Fact]
576
+ public async Task SingleDependency_SingleFile_NoChangeForNonReferencedPackage()
577
+ {
578
+ await TestNoChangeAsync(
579
+ files: [
580
+ ("project.csproj", """
581
+ <Project Sdk="Microsoft.NET.Sdk">
582
+ <ItemGroup>
583
+ <PackageReference Include="Some.Dependency" Version="1.0.0" />
584
+ </ItemGroup>
585
+ </Project>
586
+ """)
587
+ ],
588
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
589
+ requiredDependencyStrings: ["Unrelated.Dependency/2.0.0"]
590
+ );
591
+ }
592
+
593
+ [Fact]
594
+ public async Task MultiDependency_SingleFile_AttributeDirectUpdate()
595
+ {
596
+ await TestAsync(
597
+ files: [
598
+ ("project.csproj", """
599
+ <Project Sdk="Microsoft.NET.Sdk">
600
+ <ItemGroup>
601
+ <PackageReference Include="Some.Dependency" Version="1.0.0" />
602
+ <PackageReference Include="Transitive.Dependency" Version="3.0.0" />
603
+ <PackageReference Include="Unrelated.Dependency" Version="5.0.0" />
604
+ </ItemGroup>
605
+ </Project>
606
+ """)
607
+ ],
608
+ initialProjectDependencyStrings: [
609
+ "Some.Dependency/1.0.0",
610
+ "Transitive.Dependency/3.0.0"
611
+ ],
612
+ requiredDependencyStrings: [
613
+ "Some.Dependency/2.0.0",
614
+ "Transitive.Dependency/4.0.0",
615
+ ],
616
+ expectedFiles: [
617
+ ("project.csproj", """
618
+ <Project Sdk="Microsoft.NET.Sdk">
619
+ <ItemGroup>
620
+ <PackageReference Include="Some.Dependency" Version="2.0.0" />
621
+ <PackageReference Include="Transitive.Dependency" Version="4.0.0" />
622
+ <PackageReference Include="Unrelated.Dependency" Version="5.0.0" />
623
+ </ItemGroup>
624
+ </Project>
625
+ """)
626
+ ]
627
+ );
628
+ }
629
+
630
+ [Fact]
631
+ public async Task MultiDependency_SingleFile_SomeAlreadyUpToDate_FromDiscovery()
632
+ {
633
+ await TestAsync(
634
+ files: [
635
+ ("project.csproj", """
636
+ <Project Sdk="Microsoft.NET.Sdk">
637
+ <ItemGroup>
638
+ <PackageReference Include="Some.Dependency" Version="1.0.0" />
639
+ <PackageReference Include="Transitive.Dependency" Version="3.0.0" />
640
+ </ItemGroup>
641
+ </Project>
642
+ """)
643
+ ],
644
+ initialProjectDependencyStrings: [
645
+ "Some.Dependency/1.0.0",
646
+ "Transitive.Dependency/3.0.0"
647
+ ],
648
+ requiredDependencyStrings: [
649
+ "Some.Dependency/1.0.0",
650
+ "Transitive.Dependency/4.0.0",
651
+ ],
652
+ expectedFiles: [
653
+ ("project.csproj", """
654
+ <Project Sdk="Microsoft.NET.Sdk">
655
+ <ItemGroup>
656
+ <PackageReference Include="Some.Dependency" Version="1.0.0" />
657
+ <PackageReference Include="Transitive.Dependency" Version="4.0.0" />
658
+ </ItemGroup>
659
+ </Project>
660
+ """)
661
+ ]
662
+ );
663
+ }
664
+
665
+ [Fact]
666
+ public async Task MultiDependency_SingleFile_SomeAlreadyUpToDate_FromXml()
667
+ {
668
+ // this test simulates a previous pass that updated `Some.Dependency` and now a subsequent pass is attempting that again without up-to-date discovery
669
+ await TestAsync(
670
+ files: [
671
+ ("project.csproj", """
672
+ <Project Sdk="Microsoft.NET.Sdk">
673
+ <ItemGroup>
674
+ <PackageReference Include="Some.Dependency" Version="2.0.0" />
675
+ <PackageReference Include="Transitive.Dependency" Version="3.0.0" />
676
+ </ItemGroup>
677
+ </Project>
678
+ """)
679
+ ],
680
+ initialProjectDependencyStrings: [
681
+ "Some.Dependency/1.0.0",
682
+ "Transitive.Dependency/3.0.0"
683
+ ],
684
+ requiredDependencyStrings: [
685
+ "Some.Dependency/2.0.0",
686
+ "Transitive.Dependency/4.0.0",
687
+ ],
688
+ expectedFiles: [
689
+ ("project.csproj", """
690
+ <Project Sdk="Microsoft.NET.Sdk">
691
+ <ItemGroup>
692
+ <PackageReference Include="Some.Dependency" Version="2.0.0" />
693
+ <PackageReference Include="Transitive.Dependency" Version="4.0.0" />
694
+ </ItemGroup>
695
+ </Project>
696
+ """)
697
+ ]
698
+ );
699
+ }
700
+
701
+ [Fact]
702
+ public async Task SingleDependency_SingleFile_ElementDirectUpdate()
703
+ {
704
+ await TestAsync(
705
+ files: [
706
+ ("project.csproj", """
707
+ <Project Sdk="Microsoft.NET.Sdk">
708
+ <ItemGroup>
709
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
710
+ <PackageReference Include="Some.Dependency">
711
+ <Version>1.0.0</Version>
712
+ </PackageReference>
713
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
714
+ </ItemGroup>
715
+ </Project>
716
+ """)
717
+ ],
718
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
719
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
720
+ expectedFiles: [
721
+ ("project.csproj", """
722
+ <Project Sdk="Microsoft.NET.Sdk">
723
+ <ItemGroup>
724
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
725
+ <PackageReference Include="Some.Dependency">
726
+ <Version>2.0.0</Version>
727
+ </PackageReference>
728
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
729
+ </ItemGroup>
730
+ </Project>
731
+ """)
732
+ ]
733
+ );
734
+ }
735
+
736
+ [Fact]
737
+ public async Task SingleDependency_CentralPackageManagement_AttributeDirectUpdate()
738
+ {
739
+ await TestAsync(
740
+ files: [
741
+ ("project.csproj", """
742
+ <Project Sdk="Microsoft.NET.Sdk">
743
+ <ItemGroup>
744
+ <PackageReference Include="Ignored.Dependency" />
745
+ <PackageReference Include="Some.Dependency" />
746
+ <PackageReference Include="Some.Other.Dependency" />
747
+ </ItemGroup>
748
+ </Project>
749
+ """),
750
+ ("Directory.Packages.props", """
751
+ <Project>
752
+ <ItemGroup>
753
+ <PackageVersion Include="Ignored.Dependency" Version="7.0.0" />
754
+ <PackageVersion Include="Some.Dependency" Version="1.0.0" />
755
+ <PackageVersion Include="Some.Other.Dependency" Version="8.0.0" />
756
+ </ItemGroup>
757
+ </Project>
758
+ """)
759
+ ],
760
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
761
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
762
+ expectedFiles: [
763
+ ("project.csproj", """
764
+ <Project Sdk="Microsoft.NET.Sdk">
765
+ <ItemGroup>
766
+ <PackageReference Include="Ignored.Dependency" />
767
+ <PackageReference Include="Some.Dependency" />
768
+ <PackageReference Include="Some.Other.Dependency" />
769
+ </ItemGroup>
770
+ </Project>
771
+ """),
772
+ ("Directory.Packages.props", """
773
+ <Project>
774
+ <ItemGroup>
775
+ <PackageVersion Include="Ignored.Dependency" Version="7.0.0" />
776
+ <PackageVersion Include="Some.Dependency" Version="2.0.0" />
777
+ <PackageVersion Include="Some.Other.Dependency" Version="8.0.0" />
778
+ </ItemGroup>
779
+ </Project>
780
+ """)
781
+ ]
782
+ );
783
+ }
784
+
785
+ [Fact]
786
+ public async Task MultiDependency_CentralPackageManagement_AttributeDirectUpdate()
787
+ {
788
+ await TestAsync(
789
+ files: [
790
+ ("project.csproj", """
791
+ <Project Sdk="Microsoft.NET.Sdk">
792
+ <ItemGroup>
793
+ <PackageReference Include="Some.Dependency" />
794
+ <PackageReference Include="Transitive.Dependency" />
795
+ <PackageReference Include="Unrelated.Dependency" />
796
+ </ItemGroup>
797
+ </Project>
798
+ """),
799
+ ("Directory.Packages.props", """
800
+ <Project>
801
+ <ItemGroup>
802
+ <PackageVersion Include="Some.Dependency" Version="1.0.0" />
803
+ <PackageVersion Include="Transitive.Dependency" Version="3.0.0" />
804
+ <PackageVersion Include="Unrelated.Dependency" Version="5.0.0" />
805
+ </ItemGroup>
806
+ </Project>
807
+ """)
808
+ ],
809
+ initialProjectDependencyStrings: [
810
+ "Some.Dependency/1.0.0",
811
+ "Transitive.Dependency/3.0.0",
812
+ "Unrelated.Dependency/5.0.0",
813
+ ],
814
+ requiredDependencyStrings: [
815
+ "Some.Dependency/2.0.0",
816
+ "Transitive.Dependency/4.0.0",
817
+ ],
818
+ expectedFiles: [
819
+ ("project.csproj", """
820
+ <Project Sdk="Microsoft.NET.Sdk">
821
+ <ItemGroup>
822
+ <PackageReference Include="Some.Dependency" />
823
+ <PackageReference Include="Transitive.Dependency" />
824
+ <PackageReference Include="Unrelated.Dependency" />
825
+ </ItemGroup>
826
+ </Project>
827
+ """),
828
+ ("Directory.Packages.props", """
829
+ <Project>
830
+ <ItemGroup>
831
+ <PackageVersion Include="Some.Dependency" Version="2.0.0" />
832
+ <PackageVersion Include="Transitive.Dependency" Version="4.0.0" />
833
+ <PackageVersion Include="Unrelated.Dependency" Version="5.0.0" />
834
+ </ItemGroup>
835
+ </Project>
836
+ """)
837
+ ]
838
+ );
839
+ }
840
+
841
+ [Fact]
842
+ public async Task SingleDependency_CentralPackageManagement_ElementDirectUpdate()
843
+ {
844
+ await TestAsync(
845
+ files: [
846
+ ("project.csproj", """
847
+ <Project Sdk="Microsoft.NET.Sdk">
848
+ <ItemGroup>
849
+ <PackageReference Include="Ignored.Dependency" />
850
+ <PackageReference Include="Some.Dependency" />
851
+ <PackageReference Include="Some.Other.Dependency" />
852
+ </ItemGroup>
853
+ </Project>
854
+ """),
855
+ ("Directory.Packages.props", """
856
+ <Project>
857
+ <ItemGroup>
858
+ <PackageVersion Include="Ignored.Dependency" Version="7.0.0" />
859
+ <PackageVersion Include="Some.Dependency">
860
+ <Version>1.0.0</Version>
861
+ </PackageVersion>
862
+ <PackageVersion Include="Some.Other.Dependency" Version="8.0.0" />
863
+ </ItemGroup>
864
+ </Project>
865
+ """)
866
+ ],
867
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
868
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
869
+ expectedFiles: [
870
+ ("project.csproj", """
871
+ <Project Sdk="Microsoft.NET.Sdk">
872
+ <ItemGroup>
873
+ <PackageReference Include="Ignored.Dependency" />
874
+ <PackageReference Include="Some.Dependency" />
875
+ <PackageReference Include="Some.Other.Dependency" />
876
+ </ItemGroup>
877
+ </Project>
878
+ """),
879
+ ("Directory.Packages.props", """
880
+ <Project>
881
+ <ItemGroup>
882
+ <PackageVersion Include="Ignored.Dependency" Version="7.0.0" />
883
+ <PackageVersion Include="Some.Dependency">
884
+ <Version>2.0.0</Version>
885
+ </PackageVersion>
886
+ <PackageVersion Include="Some.Other.Dependency" Version="8.0.0" />
887
+ </ItemGroup>
888
+ </Project>
889
+ """)
890
+ ]
891
+ );
892
+ }
893
+
894
+ [Fact]
895
+ public async Task SingleDependency_CentralPackageManagement_UpdateThroughPropertyWithExactMatch()
896
+ {
897
+ await TestAsync(
898
+ files: [
899
+ ("project.csproj", """
900
+ <Project Sdk="Microsoft.NET.Sdk">
901
+ <ItemGroup>
902
+ <PackageReference Include="Ignored.Dependency" />
903
+ <PackageReference Include="Some.Dependency" />
904
+ <PackageReference Include="Some.Other.Dependency" />
905
+ </ItemGroup>
906
+ </Project>
907
+ """),
908
+ ("Directory.Packages.props", """
909
+ <Project>
910
+ <PropertyGroup>
911
+ <SomeDependencyVersion>[1.0.0]</SomeDependencyVersion>
912
+ </PropertyGroup>
913
+ <ItemGroup>
914
+ <PackageVersion Include="Ignored.Dependency" Version="7.0.0" />
915
+ <PackageVersion Include="Some.Dependency" Version="$(SomeDependencyVersion)" />
916
+ <PackageVersion Include="Some.Other.Dependency" Version="8.0.0" />
917
+ </ItemGroup>
918
+ </Project>
919
+ """)
920
+ ],
921
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
922
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
923
+ expectedFiles: [
924
+ ("project.csproj", """
925
+ <Project Sdk="Microsoft.NET.Sdk">
926
+ <ItemGroup>
927
+ <PackageReference Include="Ignored.Dependency" />
928
+ <PackageReference Include="Some.Dependency" />
929
+ <PackageReference Include="Some.Other.Dependency" />
930
+ </ItemGroup>
931
+ </Project>
932
+ """),
933
+ ("Directory.Packages.props", """
934
+ <Project>
935
+ <PropertyGroup>
936
+ <SomeDependencyVersion>[2.0.0]</SomeDependencyVersion>
937
+ </PropertyGroup>
938
+ <ItemGroup>
939
+ <PackageVersion Include="Ignored.Dependency" Version="7.0.0" />
940
+ <PackageVersion Include="Some.Dependency" Version="$(SomeDependencyVersion)" />
941
+ <PackageVersion Include="Some.Other.Dependency" Version="8.0.0" />
942
+ </ItemGroup>
943
+ </Project>
944
+ """)
945
+ ]
946
+ );
947
+ }
948
+
949
+ [Fact]
950
+ public async Task SingleDependency_CentralPackageManagement_UpdateThroughPropertyInDifferentFile()
951
+ {
952
+ await TestAsync(
953
+ files: [
954
+ ("project.csproj", """
955
+ <Project Sdk="Microsoft.NET.Sdk">
956
+ <ItemGroup>
957
+ <PackageReference Include="Ignored.Dependency" />
958
+ <PackageReference Include="Some.Dependency" />
959
+ <PackageReference Include="Some.Other.Dependency" />
960
+ </ItemGroup>
961
+ </Project>
962
+ """),
963
+ ("Directory.Packages.props", """
964
+ <Project>
965
+ <Import Project="Versions.props" />
966
+ <ItemGroup>
967
+ <PackageVersion Include="Ignored.Dependency" Version="7.0.0" />
968
+ <PackageVersion Include="Some.Dependency" Version="$(SomeDependencyVersion)" />
969
+ <PackageVersion Include="Some.Other.Dependency" Version="8.0.0" />
970
+ </ItemGroup>
971
+ </Project>
972
+ """),
973
+ ("Versions.props", """
974
+ <Project>
975
+ <PropertyGroup>
976
+ <SomeDependencyVersion>1.0.0</SomeDependencyVersion>
977
+ </PropertyGroup>
978
+ </Project>
979
+ """)
980
+ ],
981
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
982
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
983
+ expectedFiles: [
984
+ ("project.csproj", """
985
+ <Project Sdk="Microsoft.NET.Sdk">
986
+ <ItemGroup>
987
+ <PackageReference Include="Ignored.Dependency" />
988
+ <PackageReference Include="Some.Dependency" />
989
+ <PackageReference Include="Some.Other.Dependency" />
990
+ </ItemGroup>
991
+ </Project>
992
+ """),
993
+ ("Directory.Packages.props", """
994
+ <Project>
995
+ <Import Project="Versions.props" />
996
+ <ItemGroup>
997
+ <PackageVersion Include="Ignored.Dependency" Version="7.0.0" />
998
+ <PackageVersion Include="Some.Dependency" Version="$(SomeDependencyVersion)" />
999
+ <PackageVersion Include="Some.Other.Dependency" Version="8.0.0" />
1000
+ </ItemGroup>
1001
+ </Project>
1002
+ """),
1003
+ ("Versions.props", """
1004
+ <Project>
1005
+ <PropertyGroup>
1006
+ <SomeDependencyVersion>2.0.0</SomeDependencyVersion>
1007
+ </PropertyGroup>
1008
+ </Project>
1009
+ """)
1010
+ ]
1011
+ );
1012
+ }
1013
+
1014
+ [Fact]
1015
+ public async Task SingleDependency_SingleFile_AttributePropertyUpdate()
1016
+ {
1017
+ await TestAsync(
1018
+ files: [
1019
+ ("project.csproj", """
1020
+ <Project Sdk="Microsoft.NET.Sdk">
1021
+ <PropertyGroup>
1022
+ <UnrelatedProperty>1.0.0</UnrelatedProperty>
1023
+ <SomeDependencyVersion>$(UnrelatedProperty)</SomeDependencyVersion>
1024
+ </PropertyGroup>
1025
+ <ItemGroup>
1026
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
1027
+ <PackageReference Include="Some.Dependency" Version="$(SomeDependencyVersion)" />
1028
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
1029
+ </ItemGroup>
1030
+ </Project>
1031
+ """)
1032
+ ],
1033
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
1034
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
1035
+ expectedFiles: [
1036
+ ("project.csproj", """
1037
+ <Project Sdk="Microsoft.NET.Sdk">
1038
+ <PropertyGroup>
1039
+ <UnrelatedProperty>2.0.0</UnrelatedProperty>
1040
+ <SomeDependencyVersion>$(UnrelatedProperty)</SomeDependencyVersion>
1041
+ </PropertyGroup>
1042
+ <ItemGroup>
1043
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
1044
+ <PackageReference Include="Some.Dependency" Version="$(SomeDependencyVersion)" />
1045
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
1046
+ </ItemGroup>
1047
+ </Project>
1048
+ """)
1049
+ ]
1050
+ );
1051
+ }
1052
+
1053
+ [Fact]
1054
+ public async Task SingleDependency_SingleFile_AttributePropertyUpdate_PropertyNameDoesNotMatchCase()
1055
+ {
1056
+ await TestAsync(
1057
+ files: [
1058
+ ("project.csproj", """
1059
+ <Project Sdk="Microsoft.NET.Sdk">
1060
+ <PropertyGroup>
1061
+ <UnrelatedProperty>1.0.0</UnrelatedProperty>
1062
+ <SomeDependencyVersion>$(unrelatedPROPERTY)</SomeDependencyVersion>
1063
+ </PropertyGroup>
1064
+ <ItemGroup>
1065
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
1066
+ <PackageReference Include="Some.Dependency" Version="$(someDEPENDENCYversion)" />
1067
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
1068
+ </ItemGroup>
1069
+ </Project>
1070
+ """)
1071
+ ],
1072
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
1073
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
1074
+ expectedFiles: [
1075
+ ("project.csproj", """
1076
+ <Project Sdk="Microsoft.NET.Sdk">
1077
+ <PropertyGroup>
1078
+ <UnrelatedProperty>2.0.0</UnrelatedProperty>
1079
+ <SomeDependencyVersion>$(unrelatedPROPERTY)</SomeDependencyVersion>
1080
+ </PropertyGroup>
1081
+ <ItemGroup>
1082
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
1083
+ <PackageReference Include="Some.Dependency" Version="$(someDEPENDENCYversion)" />
1084
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
1085
+ </ItemGroup>
1086
+ </Project>
1087
+ """)
1088
+ ]
1089
+ );
1090
+ }
1091
+
1092
+ [Fact]
1093
+ public async Task SingleDependency_SingleFile_MultiplePropertiesBestFitIsUsed()
1094
+ {
1095
+ await TestAsync(
1096
+ files: [
1097
+ ("project.csproj", """
1098
+ <Project Sdk="Microsoft.NET.Sdk">
1099
+ <PropertyGroup>
1100
+ <SomeDependencyVersion Condition="'$(UnknownProperty_1)' == 'true'">4.0.0</SomeDependencyVersion>
1101
+ <SomeDependencyVersion>1.0.0</SomeDependencyVersion>
1102
+ <SomeDependencyVersion Condition="'$(UnknownProperty_2)' == 'true'">5.0.0</SomeDependencyVersion>
1103
+ </PropertyGroup>
1104
+ <ItemGroup>
1105
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
1106
+ <PackageReference Include="Some.Dependency" Version="$(SomeDependencyVersion)" />
1107
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
1108
+ </ItemGroup>
1109
+ </Project>
1110
+ """)
1111
+ ],
1112
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
1113
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
1114
+ expectedFiles: [
1115
+ ("project.csproj", """
1116
+ <Project Sdk="Microsoft.NET.Sdk">
1117
+ <PropertyGroup>
1118
+ <SomeDependencyVersion Condition="'$(UnknownProperty_1)' == 'true'">4.0.0</SomeDependencyVersion>
1119
+ <SomeDependencyVersion>2.0.0</SomeDependencyVersion>
1120
+ <SomeDependencyVersion Condition="'$(UnknownProperty_2)' == 'true'">5.0.0</SomeDependencyVersion>
1121
+ </PropertyGroup>
1122
+ <ItemGroup>
1123
+ <PackageReference Include="Ignored.Dependency" Version="7.0.0" />
1124
+ <PackageReference Include="Some.Dependency" Version="$(SomeDependencyVersion)" />
1125
+ <PackageReference Include="Some.Other.Dependency" Version="8.0.0" />
1126
+ </ItemGroup>
1127
+ </Project>
1128
+ """)
1129
+ ]
1130
+ );
1131
+ }
1132
+
1133
+ [Fact]
1134
+ public async Task SingleDependency_SingleFile_TransitiveIsPinnedAtFront()
1135
+ {
1136
+ await TestAsync(
1137
+ files: [
1138
+ ("project.csproj", """
1139
+ <Project Sdk="Microsoft.NET.Sdk">
1140
+ <ItemGroup>
1141
+ <PackageReference Include="Some.Dependency" Version="1.0.0" />
1142
+ </ItemGroup>
1143
+ </Project>
1144
+ """)
1145
+ ],
1146
+ initialProjectDependencyStrings: [
1147
+ "A.Transitive.Dependency/2.0.0",
1148
+ "Some.Dependency/1.0.0",
1149
+ ],
1150
+ requiredDependencyStrings: [
1151
+ "A.Transitive.Dependency/3.0.0",
1152
+ "Some.Dependency/1.0.0",
1153
+ ],
1154
+ expectedFiles: [
1155
+ ("project.csproj", """
1156
+ <Project Sdk="Microsoft.NET.Sdk">
1157
+ <ItemGroup>
1158
+ <PackageReference Include="A.Transitive.Dependency" Version="3.0.0" />
1159
+ <PackageReference Include="Some.Dependency" Version="1.0.0" />
1160
+ </ItemGroup>
1161
+ </Project>
1162
+ """)
1163
+ ]
1164
+ );
1165
+ }
1166
+
1167
+ [Fact]
1168
+ public async Task SingleDependency_SingleFile_TransitiveIsPinnedInMiddle()
1169
+ {
1170
+ await TestAsync(
1171
+ files: [
1172
+ ("project.csproj", """
1173
+ <Project Sdk="Microsoft.NET.Sdk">
1174
+ <ItemGroup>
1175
+ <PackageReference Include="Some.Dependency" Version="1.0.0" />
1176
+ </ItemGroup>
1177
+ </Project>
1178
+ """)
1179
+ ],
1180
+ initialProjectDependencyStrings: [
1181
+ "Some.Dependency/1.0.0",
1182
+ "Transitive.Dependency/2.0.0",
1183
+ ],
1184
+ requiredDependencyStrings: [
1185
+ "Some.Dependency/1.0.0",
1186
+ "Transitive.Dependency/3.0.0",
1187
+ ],
1188
+ expectedFiles: [
1189
+ ("project.csproj", """
1190
+ <Project Sdk="Microsoft.NET.Sdk">
1191
+ <ItemGroup>
1192
+ <PackageReference Include="Some.Dependency" Version="1.0.0" />
1193
+ <PackageReference Include="Transitive.Dependency" Version="3.0.0" />
1194
+ </ItemGroup>
1195
+ </Project>
1196
+ """)
1197
+ ]
1198
+ );
1199
+ }
1200
+
1201
+ [Fact]
1202
+ public async Task SingleDependency_CentralPackageManagement_TransitiveIsPinned_ExistingPackageVersionElement_AlreadyCorrect()
1203
+ {
1204
+ await TestAsync(
1205
+ files: [
1206
+ ("project.csproj", """
1207
+ <Project Sdk="Microsoft.NET.Sdk">
1208
+ <ItemGroup>
1209
+ <PackageReference Include="Some.Dependency" />
1210
+ </ItemGroup>
1211
+ </Project>
1212
+ """),
1213
+ ("Directory.Packages.props", """
1214
+ <Project>
1215
+ <ItemGroup>
1216
+ <PackageVersion Include="Some.Dependency" Version="1.0.0" />
1217
+ <PackageVersion Include="Transitive.Dependency" Version="3.0.0" />
1218
+ </ItemGroup>
1219
+ </Project>
1220
+ """)
1221
+ ],
1222
+ initialProjectDependencyStrings: [
1223
+ "Some.Dependency/1.0.0",
1224
+ "Transitive.Dependency/2.0.0",
1225
+ ],
1226
+ requiredDependencyStrings: [
1227
+ "Some.Dependency/1.0.0",
1228
+ "Transitive.Dependency/3.0.0",
1229
+ ],
1230
+ expectedFiles: [
1231
+ ("project.csproj", """
1232
+ <Project Sdk="Microsoft.NET.Sdk">
1233
+ <ItemGroup>
1234
+ <PackageReference Include="Some.Dependency" />
1235
+ <PackageReference Include="Transitive.Dependency" />
1236
+ </ItemGroup>
1237
+ </Project>
1238
+ """),
1239
+ ("Directory.Packages.props", """
1240
+ <Project>
1241
+ <ItemGroup>
1242
+ <PackageVersion Include="Some.Dependency" Version="1.0.0" />
1243
+ <PackageVersion Include="Transitive.Dependency" Version="3.0.0" />
1244
+ </ItemGroup>
1245
+ </Project>
1246
+ """)
1247
+ ]
1248
+ );
1249
+ }
1250
+
1251
+ [Fact]
1252
+ public async Task SingleDependency_CentralPackageManagement_TransitiveIsPinned_ExistingPackageVersionElement_VersionOverrideNeeded()
1253
+ {
1254
+ await TestAsync(
1255
+ files: [
1256
+ ("project.csproj", """
1257
+ <Project Sdk="Microsoft.NET.Sdk">
1258
+ <ItemGroup>
1259
+ <PackageReference Include="Some.Dependency" />
1260
+ </ItemGroup>
1261
+ </Project>
1262
+ """),
1263
+ ("Directory.Packages.props", """
1264
+ <Project>
1265
+ <ItemGroup>
1266
+ <PackageVersion Include="Some.Dependency" Version="1.0.0" />
1267
+ <PackageVersion Include="Transitive.Dependency" Version="9.0.0" />
1268
+ </ItemGroup>
1269
+ </Project>
1270
+ """)
1271
+ ],
1272
+ initialProjectDependencyStrings: [
1273
+ "Some.Dependency/1.0.0",
1274
+ "Transitive.Dependency/2.0.0",
1275
+ ],
1276
+ requiredDependencyStrings: [
1277
+ "Some.Dependency/1.0.0",
1278
+ "Transitive.Dependency/3.0.0",
1279
+ ],
1280
+ expectedFiles: [
1281
+ ("project.csproj", """
1282
+ <Project Sdk="Microsoft.NET.Sdk">
1283
+ <ItemGroup>
1284
+ <PackageReference Include="Some.Dependency" />
1285
+ <PackageReference Include="Transitive.Dependency" VersionOverride="3.0.0" />
1286
+ </ItemGroup>
1287
+ </Project>
1288
+ """),
1289
+ ("Directory.Packages.props", """
1290
+ <Project>
1291
+ <ItemGroup>
1292
+ <PackageVersion Include="Some.Dependency" Version="1.0.0" />
1293
+ <PackageVersion Include="Transitive.Dependency" Version="9.0.0" />
1294
+ </ItemGroup>
1295
+ </Project>
1296
+ """)
1297
+ ]
1298
+ );
1299
+ }
1300
+
1301
+ [Fact]
1302
+ public async Task SingleDependency_CentralPackageManagement_TransitiveIsPinned_NoExistingPackageVersionElement_VersionElementAddedAtFront()
1303
+ {
1304
+ await TestAsync(
1305
+ files: [
1306
+ ("project.csproj", """
1307
+ <Project Sdk="Microsoft.NET.Sdk">
1308
+ <ItemGroup>
1309
+ <PackageReference Include="Some.Dependency" />
1310
+ </ItemGroup>
1311
+ </Project>
1312
+ """),
1313
+ ("Directory.Packages.props", """
1314
+ <Project>
1315
+ <ItemGroup>
1316
+ <PackageVersion Include="Some.Dependency" Version="1.0.0" />
1317
+ </ItemGroup>
1318
+ </Project>
1319
+ """)
1320
+ ],
1321
+ initialProjectDependencyStrings: [
1322
+ "A.Transitive.Dependency/2.0.0",
1323
+ "Some.Dependency/1.0.0",
1324
+ ],
1325
+ requiredDependencyStrings: [
1326
+ "A.Transitive.Dependency/3.0.0",
1327
+ "Some.Dependency/1.0.0",
1328
+ ],
1329
+ expectedFiles: [
1330
+ ("project.csproj", """
1331
+ <Project Sdk="Microsoft.NET.Sdk">
1332
+ <ItemGroup>
1333
+ <PackageReference Include="A.Transitive.Dependency" />
1334
+ <PackageReference Include="Some.Dependency" />
1335
+ </ItemGroup>
1336
+ </Project>
1337
+ """),
1338
+ ("Directory.Packages.props", """
1339
+ <Project>
1340
+ <ItemGroup>
1341
+ <PackageVersion Include="A.Transitive.Dependency" Version="3.0.0" />
1342
+ <PackageVersion Include="Some.Dependency" Version="1.0.0" />
1343
+ </ItemGroup>
1344
+ </Project>
1345
+ """)
1346
+ ]
1347
+ );
1348
+ }
1349
+
1350
+ [Fact]
1351
+ public async Task SingleDependency_CentralPackageManagement_TransitiveIsPinned_NoExistingPackageVersionElement_VersionElementAddedInMiddle()
1352
+ {
1353
+ await TestAsync(
1354
+ files: [
1355
+ ("project.csproj", """
1356
+ <Project Sdk="Microsoft.NET.Sdk">
1357
+ <ItemGroup>
1358
+ <PackageReference Include="Some.Dependency" />
1359
+ </ItemGroup>
1360
+ </Project>
1361
+ """),
1362
+ ("Directory.Packages.props", """
1363
+ <Project>
1364
+ <ItemGroup>
1365
+ <PackageVersion Include="Some.Dependency" Version="1.0.0" />
1366
+ </ItemGroup>
1367
+ </Project>
1368
+ """)
1369
+ ],
1370
+ initialProjectDependencyStrings: [
1371
+ "Some.Dependency/1.0.0",
1372
+ "Transitive.Dependency/2.0.0",
1373
+ ],
1374
+ requiredDependencyStrings: [
1375
+ "Some.Dependency/1.0.0",
1376
+ "Transitive.Dependency/3.0.0",
1377
+ ],
1378
+ expectedFiles: [
1379
+ ("project.csproj", """
1380
+ <Project Sdk="Microsoft.NET.Sdk">
1381
+ <ItemGroup>
1382
+ <PackageReference Include="Some.Dependency" />
1383
+ <PackageReference Include="Transitive.Dependency" />
1384
+ </ItemGroup>
1385
+ </Project>
1386
+ """),
1387
+ ("Directory.Packages.props", """
1388
+ <Project>
1389
+ <ItemGroup>
1390
+ <PackageVersion Include="Some.Dependency" Version="1.0.0" />
1391
+ <PackageVersion Include="Transitive.Dependency" Version="3.0.0" />
1392
+ </ItemGroup>
1393
+ </Project>
1394
+ """)
1395
+ ]
1396
+ );
1397
+ }
1398
+
1399
+ [Fact]
1400
+ public async Task SingleDependency_CentralPackageManagement_TransitiveIsPinned_NoExistingPackageVersionElement_TransitivePinningEnabled_OnlyPackagesPropsIsUpdated()
1401
+ {
1402
+ await TestAsync(
1403
+ useCentralPackageTransitivePinning: true,
1404
+ files: [
1405
+ ("project.csproj", """
1406
+ <Project Sdk="Microsoft.NET.Sdk">
1407
+ <ItemGroup>
1408
+ <PackageReference Include="Some.Dependency" />
1409
+ </ItemGroup>
1410
+ </Project>
1411
+ """),
1412
+ ("Directory.Packages.props", """
1413
+ <Project>
1414
+ <ItemGroup>
1415
+ <PackageVersion Include="Some.Dependency" Version="1.0.0" />
1416
+ </ItemGroup>
1417
+ </Project>
1418
+ """)
1419
+ ],
1420
+ initialProjectDependencyStrings: [
1421
+ "Some.Dependency/1.0.0",
1422
+ "Transitive.Dependency/2.0.0",
1423
+ ],
1424
+ requiredDependencyStrings: [
1425
+ "Some.Dependency/1.0.0",
1426
+ "Transitive.Dependency/3.0.0",
1427
+ ],
1428
+ expectedFiles: [
1429
+ ("project.csproj", """
1430
+ <Project Sdk="Microsoft.NET.Sdk">
1431
+ <ItemGroup>
1432
+ <PackageReference Include="Some.Dependency" />
1433
+ </ItemGroup>
1434
+ </Project>
1435
+ """),
1436
+ ("Directory.Packages.props", """
1437
+ <Project>
1438
+ <ItemGroup>
1439
+ <PackageVersion Include="Some.Dependency" Version="1.0.0" />
1440
+ <PackageVersion Include="Transitive.Dependency" Version="3.0.0" />
1441
+ </ItemGroup>
1442
+ </Project>
1443
+ """)
1444
+ ]
1445
+ );
1446
+ }
1447
+
1448
+ [Fact]
1449
+ public async Task FormattingIsPreserved_UpdateAttribute()
1450
+ {
1451
+ // the formatting of the XML is weird and should be kept
1452
+ await TestAsync(
1453
+ files: [
1454
+ ("project.csproj", """
1455
+ <Project Sdk="Microsoft.NET.Sdk">
1456
+
1457
+ <ItemGroup>
1458
+
1459
+
1460
+ <PackageReference Include="Some.Dependency" Version="1.0.0" />
1461
+
1462
+ </ItemGroup>
1463
+ </Project>
1464
+ """)
1465
+ ],
1466
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
1467
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
1468
+ expectedFiles: [
1469
+ ("project.csproj", """
1470
+ <Project Sdk="Microsoft.NET.Sdk">
1471
+
1472
+ <ItemGroup>
1473
+
1474
+
1475
+ <PackageReference Include="Some.Dependency" Version="2.0.0" />
1476
+
1477
+ </ItemGroup>
1478
+ </Project>
1479
+ """)
1480
+ ]
1481
+ );
1482
+ }
1483
+
1484
+ [Fact]
1485
+ public async Task FormattingIsPreserved_CommentsArePreserved_WhenInsertingAtFirstOfList()
1486
+ {
1487
+ await TestAsync(
1488
+ files: [
1489
+ ("project.csproj", """
1490
+ <Project Sdk="Microsoft.NET.Sdk">
1491
+ <ItemGroup>
1492
+ <!-- some comment -->
1493
+ <PackageReference Include="Unrelated.Dependency" Version="3.0.0" />
1494
+ </ItemGroup>
1495
+ </Project>
1496
+ """)
1497
+ ],
1498
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
1499
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
1500
+ expectedFiles: [
1501
+ ("project.csproj", """
1502
+ <Project Sdk="Microsoft.NET.Sdk">
1503
+ <ItemGroup>
1504
+ <PackageReference Include="Some.Dependency" Version="2.0.0" />
1505
+ <!-- some comment -->
1506
+ <PackageReference Include="Unrelated.Dependency" Version="3.0.0" />
1507
+ </ItemGroup>
1508
+ </Project>
1509
+ """)
1510
+ ]
1511
+ );
1512
+ }
1513
+
1514
+ [Fact]
1515
+ public async Task FormattingIsPreserved_CommentsArePreserved_WhenInsertingAfterSibling()
1516
+ {
1517
+ await TestAsync(
1518
+ files: [
1519
+ ("project.csproj", """
1520
+ <Project Sdk="Microsoft.NET.Sdk">
1521
+ <ItemGroup>
1522
+ <PackageReference Include="A.Dependency" Version="3.0.0" /> <!-- some comment -->
1523
+ </ItemGroup>
1524
+ </Project>
1525
+ """)
1526
+ ],
1527
+ initialProjectDependencyStrings: ["Some.Dependency/1.0.0"],
1528
+ requiredDependencyStrings: ["Some.Dependency/2.0.0"],
1529
+ expectedFiles: [
1530
+ ("project.csproj", """
1531
+ <Project Sdk="Microsoft.NET.Sdk">
1532
+ <ItemGroup>
1533
+ <PackageReference Include="A.Dependency" Version="3.0.0" /> <!-- some comment -->
1534
+ <PackageReference Include="Some.Dependency" Version="2.0.0" />
1535
+ </ItemGroup>
1536
+ </Project>
1537
+ """)
1538
+ ]
1539
+ );
1540
+ }
1541
+
1542
+ [Fact]
1543
+ public async Task UpdateOfSdkManagedPackageCanOccurDespiteVersionReplacements()
1544
+ {
1545
+ // To avoid a unit test that's tightly coupled to the installed SDK, A list of SDK-managed packages is faked.
1546
+ // In this test the package `Test.Sdk.Managed.Package` is listed in the project as 1.0.0, but the SDK replaces
1547
+ // the version with 1.0.1 during a restore operation, so that's what the file updater thinks it's starting with.
1548
+ // The update then proceeds from 1.0.1 to 1.0.2.
1549
+ using var tempDirectory = new TemporaryDirectory();
1550
+ var packageCorrelationFile = Path.Combine(tempDirectory.DirectoryPath, "dotnet-package-correlation.json");
1551
+ await File.WriteAllTextAsync(packageCorrelationFile, """
1552
+ {
1553
+ "Runtimes": {
1554
+ "1.0.0": {
1555
+ "Packages": {
1556
+ "Dependabot.App.Core.Ref": "1.0.0",
1557
+ "Test.Sdk.Managed.Package": "1.0.0"
1558
+ }
1559
+ },
1560
+ "1.0.1": {
1561
+ "Packages": {
1562
+ "Dependabot.App.Core.Ref": "1.0.1",
1563
+ "Test.Sdk.Managed.Package": "1.0.1"
1564
+ }
1565
+ }
1566
+ }
1567
+ }
1568
+ """, TestContext.Current.CancellationToken);
1569
+ using var tempEnvironment = new TemporaryEnvironment([("DOTNET_PACKAGE_CORRELATION_FILE_PATH", packageCorrelationFile)]);
1570
+
1571
+ await TestAsync(
1572
+ files: [
1573
+ ("project.csproj", """
1574
+ <Project Sdk="Microsoft.NET.Sdk">
1575
+ <ItemGroup>
1576
+ <PackageReference Include="Test.Sdk.Managed.Package" Version="1.0.0" />
1577
+ </ItemGroup>
1578
+ </Project>
1579
+ """)
1580
+ ],
1581
+ initialProjectDependencyStrings: ["Test.Sdk.Managed.Package/1.0.1"],
1582
+ requiredDependencyStrings: ["Test.Sdk.Managed.Package/1.0.2"],
1583
+ expectedFiles: [
1584
+ ("project.csproj", """
1585
+ <Project Sdk="Microsoft.NET.Sdk">
1586
+ <ItemGroup>
1587
+ <PackageReference Include="Test.Sdk.Managed.Package" Version="1.0.2" />
1588
+ </ItemGroup>
1589
+ </Project>
1590
+ """)
1591
+ ]
1592
+ );
1593
+ }
1594
+
1595
+ [Fact]
1596
+ public async Task NoChangesForUnsupportedInitialFile()
1597
+ {
1598
+ // the extension `.xyproj` is not supported by the file writer; it is immediately rejected
1599
+ await TestNoChangeAsync(
1600
+ files: [
1601
+ ("unsupported.xyproj", """
1602
+ <Project Sdk="Microsoft.NET.Sdk">
1603
+ <ItemGroup>
1604
+ <PackageReference Include="Some.Package" Version="$(SomePackageVersion)" />
1605
+ </ItemGroup>
1606
+ </Project
1607
+ """),
1608
+ ("versions.props", """
1609
+ <Project>
1610
+ <PropertyGroup>
1611
+ <SomePackageVersion>1.0.0</SomePackageVersion>
1612
+ </PropertyGroup>
1613
+ </Project>
1614
+ """)
1615
+ ],
1616
+ initialProjectDependencyStrings: ["Some.Package/1.0.0"],
1617
+ requiredDependencyStrings: ["Some.Package/2.0.0"]
1618
+ );
1619
+ }
1620
+ }