-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix package download when CPM is enabled (#119)
* fix: fix problem when downloading packages and CPM is enabled Closes #118 * test: add tests for new CheckCpmPreprocessor * feat: redo download packages when CPM enabled
- Loading branch information
Showing
6 changed files
with
376 additions
and
12 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
210 changes: 210 additions & 0 deletions
210
src/Core/Liz.Core.Tests/Preparation/CheckCpmPreprocessorTests.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,210 @@ | ||
using ArrangeContext.Moq; | ||
using FluentAssertions; | ||
using Liz.Core.Preparation; | ||
using Liz.Core.Preparation.Contracts.Models; | ||
using Liz.Core.Settings; | ||
using System.IO.Abstractions; | ||
using System.IO.Abstractions.TestingHelpers; | ||
using Xunit; | ||
|
||
namespace Liz.Core.Tests.Preparation; | ||
|
||
public sealed class CheckCpmPreprocessorTests | ||
{ | ||
[Fact] | ||
public async Task Gets_Not_Enabled_When_No_Props_File() | ||
{ | ||
const string targetFile = "C:/some/directory/target.file"; | ||
var sourceInfo = new SourceInfo(); | ||
var mockFileSystem = new MockFileSystem(new Dictionary<string, MockFileData> | ||
{ | ||
{ targetFile, new MockFileData("") } | ||
}); | ||
|
||
var context = ArrangeContext<CheckCpmPreprocessor>.Create(); | ||
context.Use(sourceInfo); | ||
context.Use<IFileSystem>(mockFileSystem); | ||
|
||
context | ||
.For<ExtractLicensesSettingsBase>() | ||
.Setup(settings => settings.GetTargetFile()) | ||
.Returns(targetFile); | ||
|
||
var sut = context.Build(); | ||
|
||
await sut.PreprocessAsync(); | ||
|
||
sourceInfo | ||
.IsCpmEnabled | ||
.Should() | ||
.BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public async Task Gets_Not_Enabled_When_No_Enabling_Element() | ||
{ | ||
const string propsFileContent = @" | ||
<Project> | ||
<ItemGroup> | ||
<PackageVersion Include=""NewtonSoft.Json"" Version=""1.3.3"" /> | ||
</ItemGroup> | ||
</Project>"; | ||
|
||
const string targetFile = "C:/some/directory/target.file"; | ||
var sourceInfo = new SourceInfo(); | ||
var mockFileSystem = new MockFileSystem(new Dictionary<string, MockFileData> | ||
{ | ||
{ targetFile, new MockFileData("") }, | ||
{ "C:/some/Directory.Packages.props", new MockFileData(propsFileContent) } | ||
}); | ||
|
||
var context = ArrangeContext<CheckCpmPreprocessor>.Create(); | ||
context.Use(sourceInfo); | ||
context.Use<IFileSystem>(mockFileSystem); | ||
|
||
context | ||
.For<ExtractLicensesSettingsBase>() | ||
.Setup(settings => settings.GetTargetFile()) | ||
.Returns(targetFile); | ||
|
||
var sut = context.Build(); | ||
|
||
await sut.PreprocessAsync(); | ||
|
||
sourceInfo | ||
.IsCpmEnabled | ||
.Should() | ||
.BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public async Task Gets_Not_Enabled_When_Enabling_Elements_Value_Is_False() | ||
{ | ||
const string propsFileContent = @" | ||
<Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageVersion Include=""NewtonSoft.Json"" Version=""1.3.3"" /> | ||
</ItemGroup> | ||
</Project>"; | ||
|
||
const string targetFile = "C:/some/directory/target.file"; | ||
var sourceInfo = new SourceInfo(); | ||
var mockFileSystem = new MockFileSystem(new Dictionary<string, MockFileData> | ||
{ | ||
{ targetFile, new MockFileData("") }, | ||
{ "C:/some/Directory.Packages.props", new MockFileData(propsFileContent) } | ||
}); | ||
|
||
var context = ArrangeContext<CheckCpmPreprocessor>.Create(); | ||
context.Use(sourceInfo); | ||
context.Use<IFileSystem>(mockFileSystem); | ||
|
||
context | ||
.For<ExtractLicensesSettingsBase>() | ||
.Setup(settings => settings.GetTargetFile()) | ||
.Returns(targetFile); | ||
|
||
var sut = context.Build(); | ||
|
||
await sut.PreprocessAsync(); | ||
|
||
sourceInfo | ||
.IsCpmEnabled | ||
.Should() | ||
.BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public async Task Gets_Enabled_When_Enabling_Elements_Value_Is_True() | ||
{ | ||
const string propsFileContent = @" | ||
<Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageVersion Include=""NewtonSoft.Json"" Version=""1.3.3"" /> | ||
</ItemGroup> | ||
</Project>"; | ||
|
||
const string targetFile = "C:/some/directory/target.file"; | ||
var sourceInfo = new SourceInfo(); | ||
var mockFileSystem = new MockFileSystem(new Dictionary<string, MockFileData> | ||
{ | ||
{ targetFile, new MockFileData("") }, | ||
{ "C:/some/Directory.Packages.props", new MockFileData(propsFileContent) } | ||
}); | ||
|
||
var context = ArrangeContext<CheckCpmPreprocessor>.Create(); | ||
context.Use(sourceInfo); | ||
context.Use<IFileSystem>(mockFileSystem); | ||
|
||
context | ||
.For<ExtractLicensesSettingsBase>() | ||
.Setup(settings => settings.GetTargetFile()) | ||
.Returns(targetFile); | ||
|
||
var sut = context.Build(); | ||
|
||
await sut.PreprocessAsync(); | ||
|
||
sourceInfo | ||
.IsCpmEnabled | ||
.Should() | ||
.BeTrue(); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public async Task Gets_Enabled_Status_From_Imported_File(bool enabledInImportedFile) | ||
{ | ||
const string propsFileContent = @" | ||
<Project> | ||
<Import Project=""../Directory.Packages.props""/> | ||
<ItemGroup> | ||
<PackageVersion Include=""NewtonSoft.Json"" Version=""1.3.3"" /> | ||
</ItemGroup> | ||
</Project>"; | ||
|
||
var importedPropsFileContent = $@" | ||
<Project> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>{enabledInImportedFile}</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
</Project>"; | ||
|
||
const string targetFile = "C:/some/directory/target.file"; | ||
var sourceInfo = new SourceInfo(); | ||
var mockFileSystem = new MockFileSystem(new Dictionary<string, MockFileData> | ||
{ | ||
{ targetFile, new MockFileData("") }, | ||
{ "C:/some/Directory.Packages.props", new MockFileData(propsFileContent) }, | ||
{ "C:/Directory.Packages.props", new MockFileData(importedPropsFileContent) } | ||
}); | ||
|
||
var context = ArrangeContext<CheckCpmPreprocessor>.Create(); | ||
context.Use(sourceInfo); | ||
context.Use<IFileSystem>(mockFileSystem); | ||
|
||
context | ||
.For<ExtractLicensesSettingsBase>() | ||
.Setup(settings => settings.GetTargetFile()) | ||
.Returns(targetFile); | ||
|
||
var sut = context.Build(); | ||
|
||
await sut.PreprocessAsync(); | ||
|
||
sourceInfo | ||
.IsCpmEnabled | ||
.Should() | ||
.Be(enabledInImportedFile); | ||
} | ||
} |
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
Oops, something went wrong.