dependabot-nuget 0.321.1 → 0.321.3

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation/Model/PackageMapper.cs +9 -0
  3. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyDiscoveryTargetingPacks.props +2 -0
  4. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencySolver/IDependencySolver.cs +8 -0
  5. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencySolver/MSBuildDependencySolver.cs +32 -0
  6. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/ProjectDiscoveryResult.cs +1 -0
  7. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs +10 -1
  8. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/WorkspaceDiscoveryResult.cs +6 -0
  9. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/ExperimentsManager.cs +3 -0
  10. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/DotNetToolsJsonUpdater.cs +6 -3
  11. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/FileWriters/FileWriterWorker.cs +326 -0
  12. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/FileWriters/IFileWriter.cs +14 -0
  13. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/FileWriters/XmlFileWriter.cs +465 -0
  14. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/GlobalJsonUpdater.cs +9 -5
  15. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +26 -1
  16. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/DependencySolver/MSBuildDependencySolverTests.cs +633 -0
  17. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/SdkProjectDiscoveryTests.cs +49 -0
  18. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/EndToEndTests.cs +484 -0
  19. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/DotNetToolsJsonUpdaterTests.cs +181 -0
  20. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/FileWriterTestsBase.cs +61 -0
  21. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/FileWriterWorkerTests.cs +917 -0
  22. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/FileWriterWorkerTests_MiscellaneousTests.cs +109 -0
  23. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/TestFileWriterReturnsConstantResult.cs +20 -0
  24. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/XmlFileWriterTests.cs +1594 -0
  25. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/XmlFileWriterTests_CreateUpdatedVersionRangeTests.cs +25 -0
  26. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/GlobalJsonUpdaterTests.cs +139 -0
  27. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackagesConfigUpdaterTests.cs +1961 -1
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateOperationResultTests.cs +116 -0
  29. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +0 -1043
  30. metadata +19 -10
  31. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DotNetTools.cs +0 -375
  32. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.GlobalJson.cs +0 -296
  33. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.LockFile.cs +0 -251
  34. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Mixed.cs +0 -201
  35. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackageReference.cs +0 -3821
  36. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +0 -2706
@@ -0,0 +1,181 @@
1
+ using Xunit;
2
+
3
+ namespace NuGetUpdater.Core.Test.Update;
4
+
5
+ public class DotNetToolsJsonUpdaterTests
6
+ {
7
+ [Fact]
8
+ public async Task UpdateDependency_MaintainComments()
9
+ {
10
+ await TestAsync(
11
+ dotnetToolsContent: """
12
+ {
13
+ // this is a comment
14
+ "version": 1,
15
+ "isRoot": true,
16
+ "tools": {
17
+ "some.dotnet.tool": {
18
+ // this is a deep comment
19
+ "version": "1.0.0",
20
+ "commands": [
21
+ "some.dotnet.tool"
22
+ ]
23
+ },
24
+ "some-other-tool": {
25
+ "version": "2.1.3",
26
+ "commands": [
27
+ "some-other-tool"
28
+ ]
29
+ }
30
+ }
31
+ }
32
+ """,
33
+ dependencyName: "Some.DotNet.Tool",
34
+ previousDependencyVersion: "1.0.0",
35
+ newDependencyVersion: "1.1.0",
36
+ expectedUpdatedDotnetToolsContent: """
37
+ {
38
+ // this is a comment
39
+ "version": 1,
40
+ "isRoot": true,
41
+ "tools": {
42
+ "some.dotnet.tool": {
43
+ // this is a deep comment
44
+ "version": "1.1.0",
45
+ "commands": [
46
+ "some.dotnet.tool"
47
+ ]
48
+ },
49
+ "some-other-tool": {
50
+ "version": "2.1.3",
51
+ "commands": [
52
+ "some-other-tool"
53
+ ]
54
+ }
55
+ }
56
+ }
57
+ """
58
+ );
59
+ }
60
+
61
+ [Fact]
62
+ public async Task UpdateDependency_TrailingCommaInOriginal()
63
+ {
64
+ await TestAsync(
65
+ dotnetToolsContent: """
66
+ {
67
+ "version": 1,
68
+ "isRoot": true,
69
+ "tools": {
70
+ "some.dotnet.tool": {
71
+ "version": "1.0.0",
72
+ "commands": [
73
+ "some.dotnet.tool"
74
+ ],
75
+ },
76
+ "some-other-tool": {
77
+ "version": "2.1.3",
78
+ "commands": [
79
+ "some-other-tool"
80
+ ],
81
+ }
82
+ }
83
+ }
84
+ """,
85
+ dependencyName: "Some.DotNet.Tool",
86
+ previousDependencyVersion: "1.0.0",
87
+ newDependencyVersion: "1.1.0",
88
+ expectedUpdatedDotnetToolsContent: """
89
+ {
90
+ "version": 1,
91
+ "isRoot": true,
92
+ "tools": {
93
+ "some.dotnet.tool": {
94
+ "version": "1.1.0",
95
+ "commands": [
96
+ "some.dotnet.tool"
97
+ ]
98
+ },
99
+ "some-other-tool": {
100
+ "version": "2.1.3",
101
+ "commands": [
102
+ "some-other-tool"
103
+ ]
104
+ }
105
+ }
106
+ }
107
+ """
108
+ );
109
+ }
110
+
111
+ [Fact]
112
+ public async Task MissingDependency_NoUpdatePerformed()
113
+ {
114
+ await TestAsync(
115
+ dotnetToolsContent: """
116
+ {
117
+ "version": 1,
118
+ "isRoot": true,
119
+ "tools": {
120
+ "some-other-tool": {
121
+ "version": "2.1.3",
122
+ "commands": [
123
+ "some-other-tool"
124
+ ]
125
+ }
126
+ }
127
+ }
128
+ """,
129
+ dependencyName: "Some.DotNet.Tool",
130
+ previousDependencyVersion: "1.0.0",
131
+ newDependencyVersion: "1.1.0",
132
+ expectedUpdatedDotnetToolsContent: """
133
+ {
134
+ "version": 1,
135
+ "isRoot": true,
136
+ "tools": {
137
+ "some-other-tool": {
138
+ "version": "2.1.3",
139
+ "commands": [
140
+ "some-other-tool"
141
+ ]
142
+ }
143
+ }
144
+ }
145
+ """
146
+ );
147
+ }
148
+
149
+ private async Task TestAsync(
150
+ string dotnetToolsContent,
151
+ string dependencyName,
152
+ string previousDependencyVersion,
153
+ string newDependencyVersion,
154
+ string expectedUpdatedDotnetToolsContent,
155
+ string workspaceDirectory = "/",
156
+ string dotnetToolsJsonPath = ".config/dotnet-tools.json"
157
+ )
158
+ {
159
+ // arrange
160
+ using var tempDir = await TemporaryDirectory.CreateWithContentsAsync(
161
+ (dotnetToolsJsonPath, dotnetToolsContent)
162
+ );
163
+ var logger = new TestLogger();
164
+
165
+ // act
166
+ var updatedFilePath = await DotNetToolsJsonUpdater.UpdateDependencyAsync(tempDir.DirectoryPath, workspaceDirectory, dependencyName, previousDependencyVersion, newDependencyVersion, logger);
167
+
168
+ // assert
169
+ var expectedUpdateToHappen = dotnetToolsContent.Replace("\r", "") != expectedUpdatedDotnetToolsContent.Replace("\r", "");
170
+ if (expectedUpdateToHappen)
171
+ {
172
+ Assert.NotNull(updatedFilePath);
173
+ var relativeUpdatedFilePath = Path.GetRelativePath(tempDir.DirectoryPath, updatedFilePath).NormalizePathToUnix();
174
+ Assert.Equal(dotnetToolsJsonPath, relativeUpdatedFilePath);
175
+ }
176
+
177
+ var actualFileContents = await tempDir.ReadFileContentsAsync([dotnetToolsJsonPath]);
178
+ var actualContent = actualFileContents.Single().Contents.Replace("\r", "");
179
+ Assert.Equal(expectedUpdatedDotnetToolsContent.Replace("\r", ""), actualContent);
180
+ }
181
+ }
@@ -0,0 +1,61 @@
1
+ using System.Collections.Immutable;
2
+
3
+ using NuGetUpdater.Core.Updater.FileWriters;
4
+
5
+ using Xunit;
6
+
7
+ namespace NuGetUpdater.Core.Test.Update.FileWriters;
8
+
9
+ public abstract class FileWriterTestsBase
10
+ {
11
+ public abstract IFileWriter FileWriter { get; }
12
+
13
+ protected async Task TestAsync(
14
+ (string path, string contents)[] files,
15
+ ImmutableArray<string> initialProjectDependencyStrings,
16
+ ImmutableArray<string> requiredDependencyStrings,
17
+ (string path, string contents)[] expectedFiles,
18
+ bool useCentralPackageTransitivePinning = false
19
+ )
20
+ {
21
+ using var tempDir = await TemporaryDirectory.CreateWithContentsAsync(files);
22
+ var repoContentsPath = new DirectoryInfo(tempDir.DirectoryPath);
23
+ var initialProjectDependencies = initialProjectDependencyStrings.Select(s => new Dependency(s.Split('/')[0], s.Split('/')[1], DependencyType.Unknown)).ToImmutableArray();
24
+ var requiredDependencies = requiredDependencyStrings.Select(s => new Dependency(s.Split('/')[0], s.Split('/')[1], DependencyType.Unknown)).ToImmutableArray();
25
+ var addPackageReferenceElementForPinnedPackages = !useCentralPackageTransitivePinning;
26
+ var success = await FileWriter.UpdatePackageVersionsAsync(repoContentsPath, [.. files.Select(f => f.path)], initialProjectDependencies, requiredDependencies, addPackageReferenceElementForPinnedPackages);
27
+ Assert.True(success);
28
+
29
+ var expectedFileNames = expectedFiles.Select(f => f.path).ToHashSet();
30
+ var actualFiles = (await tempDir.ReadFileContentsAsync(expectedFileNames)).ToDictionary(f => f.Path, f => f.Contents);
31
+ foreach (var (expectedPath, expectedContents) in expectedFiles)
32
+ {
33
+ Assert.True(actualFiles.TryGetValue(expectedPath, out var actualContents), $"Expected file {expectedPath} not found.");
34
+ Assert.Equal(expectedContents.Replace("\r", ""), actualContents.Replace("\r", ""));
35
+ }
36
+ }
37
+
38
+ protected async Task TestNoChangeAsync(
39
+ (string path, string contents)[] files,
40
+ ImmutableArray<string> initialProjectDependencyStrings,
41
+ ImmutableArray<string> requiredDependencyStrings,
42
+ bool useCentralPackageTransitivePinning = false
43
+ )
44
+ {
45
+ using var tempDir = await TemporaryDirectory.CreateWithContentsAsync(files);
46
+ var repoContentsPath = new DirectoryInfo(tempDir.DirectoryPath);
47
+ var initialProjectDependencies = initialProjectDependencyStrings.Select(s => new Dependency(s.Split('/')[0], s.Split('/')[1], DependencyType.Unknown)).ToImmutableArray();
48
+ var requiredDependencies = requiredDependencyStrings.Select(s => new Dependency(s.Split('/')[0], s.Split('/')[1], DependencyType.Unknown)).ToImmutableArray();
49
+ var addPackageReferenceElementForPinnedPackages = !useCentralPackageTransitivePinning;
50
+ var success = await FileWriter.UpdatePackageVersionsAsync(repoContentsPath, [.. files.Select(f => f.path)], initialProjectDependencies, requiredDependencies, addPackageReferenceElementForPinnedPackages);
51
+ Assert.False(success);
52
+
53
+ var expectedFileNames = files.Select(f => f.path).ToHashSet();
54
+ var actualFiles = (await tempDir.ReadFileContentsAsync(expectedFileNames)).ToDictionary(f => f.Path, f => f.Contents);
55
+ foreach (var (expectedPath, expectedContents) in files)
56
+ {
57
+ Assert.True(actualFiles.TryGetValue(expectedPath, out var actualContents), $"Expected file {expectedPath} not found.");
58
+ Assert.Equal(expectedContents.Replace("\r", ""), actualContents.Replace("\r", ""));
59
+ }
60
+ }
61
+ }