Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH1738: NuGetInstaller resolves correct files when package has dependencies #1740

Merged
merged 1 commit into from
Aug 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Cake.NuGet.Tests/Unit/NuGetPackageInstallerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#if !NETCORE
using System.Collections.Generic;
using System.Linq;
using Cake.Core.IO;
using Cake.Core.Packaging;
using Cake.NuGet.Tests.Fixtures;
Expand Down Expand Up @@ -343,6 +344,28 @@ public void Should_Not_Install_If_Resource_Already_Is_Installed()
"Package {0} has already been installed.",
"Cake.Foo");
}

[Fact]
public void Should_Return_Correct_Files_When_Resource_Has_Dependencies()
{
// Given
var fixture = new NuGetPackageInstallerFixture();
fixture.FileSystem.CreateFile("/Working/nuget/cake.foo.1.2.3/Cake.Abc/Cake.Abc.dll");
fixture.FileSystem.CreateFile("/Working/nuget/cake.foo.1.2.3/Cake.Foo/Cake.Foo.dll");
fixture.FileSystem.CreateFile("/Working/nuget/cake.foo.1.2.3/Cake.Xyz/Cake.Xyz.dll");
fixture.ContentResolver.GetFiles(
Arg.Any<DirectoryPath>(), Arg.Any<PackageReference>(), Arg.Any<PackageType>())
.Returns(new List<IFile> { Substitute.For<IFile>() });

// When
var result = fixture.Install();

// Then
fixture.ContentResolver.Received(1).GetFiles(
Arg.Is<DirectoryPath>(x => x.FullPath.Equals("/Working/nuget/cake.foo.1.2.3/Cake.Foo")),
fixture.Package,
PackageType.Addin);
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Cake.NuGet/NuGetPackageInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public IReadOnlyCollection<IFile> Install(PackageReference package, PackageType
}

// Package already exist?
var packagePath = GetPackagePath(root);
var packagePath = GetPackagePath(root, package.Package);
if (packagePath != null)
{
// Fetch available content from disc.
Expand All @@ -152,7 +152,7 @@ public IReadOnlyCollection<IFile> Install(PackageReference package, PackageType
InstallPackage(package, path);

// Try locating the install folder again.
packagePath = GetPackagePath(root);
packagePath = GetPackagePath(root, package.Package);

// Get the files.
var result = _contentResolver.GetFiles(packagePath, package, type);
Expand All @@ -173,10 +173,10 @@ public IReadOnlyCollection<IFile> Install(PackageReference package, PackageType
return result;
}

private static DirectoryPath GetPackagePath(IDirectory root)
private static DirectoryPath GetPackagePath(IDirectory root, string package)
{
var directories = root.GetDirectories("*", SearchScope.Current).ToArray();
return directories.FirstOrDefault()?.Path;
return directories.FirstOrDefault(p => p.Path.GetDirectoryName().Equals(package, StringComparison.OrdinalIgnoreCase))?.Path;
}

private static DirectoryPath GetPackagePath(DirectoryPath root, PackageReference package)
Expand Down