-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into bump-corepack
- Loading branch information
Showing
3 changed files
with
268 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
251 changes: 251 additions & 0 deletions
251
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.LockFile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
using Xunit; | ||
|
||
namespace NuGetUpdater.Core.Test.Update; | ||
|
||
public partial class UpdateWorkerTests | ||
{ | ||
public class LockFile : UpdateWorkerTestBase | ||
{ | ||
[Fact] | ||
public async Task UpdateSingleDependency() | ||
{ | ||
await TestUpdateForProject("Some.Package", "1.0.0", "2.0.0", | ||
packages: | ||
[ | ||
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0"), | ||
MockNuGetPackage.CreateSimplePackage("Some.Package", "2.0.0", "net8.0"), | ||
], | ||
// initial | ||
projectContents: $""" | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Some.Package" Version="1.0.0" /> | ||
</ItemGroup> | ||
</Project> | ||
""", | ||
additionalFiles: | ||
[ | ||
("packages.lock.json", "{}") | ||
], | ||
// expected | ||
expectedProjectContents: $""" | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Some.Package" Version="2.0.0" /> | ||
</ItemGroup> | ||
</Project> | ||
""", | ||
additionalChecks: path => | ||
{ | ||
var lockContents = File.ReadAllText(Path.Combine(path, "packages.lock.json")); | ||
Assert.Contains("\"resolved\": \"2.0.0\"", lockContents); | ||
} | ||
); | ||
} | ||
|
||
[Fact] | ||
public async Task UpdateSingleDependency_CentralPackageManagement() | ||
{ | ||
await TestUpdateForProject("Some.Package", "1.0.0", "2.0.0", | ||
packages: | ||
[ | ||
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0"), | ||
MockNuGetPackage.CreateSimplePackage("Some.Package", "2.0.0", "net8.0"), | ||
], | ||
// initial | ||
projectContents: $""" | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Some.Package" /> | ||
</ItemGroup> | ||
</Project> | ||
""", | ||
additionalFiles: | ||
[ | ||
("packages.lock.json", "{}"), | ||
("Directory.Packages.props", """ | ||
<Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageVersion Include="Some.Package" Version="1.0.0" /> | ||
</ItemGroup> | ||
</Project> | ||
""") | ||
], | ||
// expected | ||
expectedProjectContents: $""" | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Some.Package" /> | ||
</ItemGroup> | ||
</Project> | ||
""", | ||
additionalFilesExpected: | ||
[ | ||
("Directory.Packages.props", """ | ||
<Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageVersion Include="Some.Package" Version="2.0.0" /> | ||
</ItemGroup> | ||
</Project> | ||
""") | ||
], | ||
additionalChecks: path => | ||
{ | ||
var lockContents = File.ReadAllText(Path.Combine(path, "packages.lock.json")); | ||
Assert.Contains("\"resolved\": \"2.0.0\"", lockContents); | ||
} | ||
); | ||
} | ||
|
||
[Fact] | ||
public async Task UpdateSingleDependency_WindowsSpecific() | ||
{ | ||
await TestUpdateForProject("Some.Package", "1.0.0", "2.0.0", | ||
packages: | ||
[ | ||
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0"), | ||
MockNuGetPackage.CreateSimplePackage("Some.Package", "2.0.0", "net8.0"), | ||
], | ||
// initial | ||
projectContents: $""" | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0-windows</TargetFramework> | ||
<UseWindowsForms>true</UseWindowsForms> | ||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Some.Package" Version="1.0.0" /> | ||
</ItemGroup> | ||
</Project> | ||
""", | ||
additionalFiles: | ||
[ | ||
("packages.lock.json", "{}") | ||
], | ||
// expected | ||
expectedProjectContents: $""" | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0-windows</TargetFramework> | ||
<UseWindowsForms>true</UseWindowsForms> | ||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Some.Package" Version="2.0.0" /> | ||
</ItemGroup> | ||
</Project> | ||
""", | ||
additionalChecks: path => | ||
{ | ||
var lockContents = File.ReadAllText(Path.Combine(path, "packages.lock.json")); | ||
Assert.Contains("\"resolved\": \"2.0.0\"", lockContents); | ||
} | ||
); | ||
} | ||
|
||
[Fact] | ||
public async Task UpdateSingleDependency_CentralPackageManagement_WindowsSpecific() | ||
{ | ||
await TestUpdateForProject("Some.Package", "1.0.0", "2.0.0", | ||
packages: | ||
[ | ||
MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0"), | ||
MockNuGetPackage.CreateSimplePackage("Some.Package", "2.0.0", "net8.0"), | ||
], | ||
// initial | ||
projectContents: $""" | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0-windows</TargetFramework> | ||
<UseWindowsForms>true</UseWindowsForms> | ||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Some.Package" /> | ||
</ItemGroup> | ||
</Project> | ||
""", | ||
additionalFiles: | ||
[ | ||
("packages.lock.json", "{}"), | ||
("Directory.Packages.props", """ | ||
<Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageVersion Include="Some.Package" Version="1.0.0" /> | ||
</ItemGroup> | ||
</Project> | ||
""") | ||
], | ||
// expected | ||
expectedProjectContents: $""" | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0-windows</TargetFramework> | ||
<UseWindowsForms>true</UseWindowsForms> | ||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Some.Package" /> | ||
</ItemGroup> | ||
</Project> | ||
""", | ||
additionalFilesExpected: | ||
[ | ||
("Directory.Packages.props", """ | ||
<Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageVersion Include="Some.Package" Version="2.0.0" /> | ||
</ItemGroup> | ||
</Project> | ||
""") | ||
], | ||
additionalChecks: path => | ||
{ | ||
var lockContents = File.ReadAllText(Path.Combine(path, "packages.lock.json")); | ||
Assert.Contains("\"resolved\": \"2.0.0\"", lockContents); | ||
} | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters