Skip to content

Commit

Permalink
Merge branch 'mholo65-feature/GH1738' into develop
Browse files Browse the repository at this point in the history
* mholo65-feature/GH1738:
  (GH-1738) NuGetInstaller resolves correct files when package has dependencies
  • Loading branch information
devlead committed Aug 9, 2017
2 parents aa97faf + 2bfb81d commit 129162b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
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

0 comments on commit 129162b

Please sign in to comment.