2016-02-16 18:20:23 +00:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2016-02-24 03:07:27 +00:00
|
|
|
|
using System.IO.Compression;
|
2016-06-03 22:46:16 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Xml.Linq;
|
2016-02-18 10:27:35 +00:00
|
|
|
|
using FluentAssertions;
|
2016-02-16 18:20:23 +00:00
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
namespace Microsoft.DotNet.Tools.Pack.Tests
|
2016-02-16 18:20:23 +00:00
|
|
|
|
{
|
|
|
|
|
public class PackTests : TestBase
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
[Fact(Skip="https://github.com/dotnet/cli/issues/4488")]
|
2016-02-16 18:20:23 +00:00
|
|
|
|
public void OutputsPackagesToConfigurationSubdirWhenOutputParameterIsNotPassed()
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var testInstance = TestAssets.Get("TestLibraryWithConfiguration")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithRestoreFiles();
|
|
|
|
|
|
|
|
|
|
var packCommand = new PackCommand(configuration: "Test")
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root);
|
2016-02-16 18:20:23 +00:00
|
|
|
|
|
2016-04-13 00:29:07 +00:00
|
|
|
|
var result = packCommand.Execute();
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-02-16 18:20:23 +00:00
|
|
|
|
result.Should().Pass();
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var outputDir = testInstance.Root
|
|
|
|
|
.GetDirectory("bin", "Test");
|
|
|
|
|
|
|
|
|
|
outputDir.Should().Exist()
|
|
|
|
|
.And.HaveFiles(new []
|
|
|
|
|
{
|
|
|
|
|
"TestLibraryWithConfiguration.1.0.0.nupkg",
|
|
|
|
|
"TestLibraryWithConfiguration.1.0.0.symbols.nupkg"
|
|
|
|
|
});
|
2016-02-16 18:20:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void OutputsPackagesFlatIntoOutputDirWhenOutputParameterIsPassed()
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var testInstance = TestAssets.Get("TestLibraryWithConfiguration")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithBuildFiles()
|
|
|
|
|
.WithRestoreFiles();
|
2016-02-16 18:20:23 +00:00
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var outputDir = testInstance.Root
|
|
|
|
|
.GetDirectory("bin2");
|
2016-02-16 18:20:23 +00:00
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var packCommand = new PackCommand(output: outputDir.FullName)
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
2016-02-16 18:20:23 +00:00
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
outputDir.Should().Exist()
|
|
|
|
|
.And.HaveFiles(new []
|
|
|
|
|
{
|
|
|
|
|
"TestLibraryWithConfiguration.1.0.0.nupkg"
|
|
|
|
|
});
|
2016-02-16 18:20:23 +00:00
|
|
|
|
}
|
2016-04-07 22:59:25 +00:00
|
|
|
|
|
2016-02-18 10:27:35 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void SettingVersionSuffixFlag_ShouldStampAssemblyInfoInOutputAssemblyAndPackage()
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var testInstance = TestAssets.Get("TestLibraryWithConfiguration")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithRestoreFiles();
|
|
|
|
|
|
|
|
|
|
new PackCommand(versionSuffix: "85")
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root.FullName)
|
|
|
|
|
.WithConfiguration("Debug")
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
var output = testInstance.Root
|
|
|
|
|
.GetDirectory("bin", "Debug", DefaultLibraryFramework)
|
|
|
|
|
.GetFile("TestLibraryWithConfiguration.dll");
|
|
|
|
|
|
|
|
|
|
var informationalVersion = PeReaderUtils.GetAssemblyAttributeValue(output.FullName, "AssemblyInformationalVersionAttribute");
|
|
|
|
|
|
|
|
|
|
informationalVersion.Should().NotBeNull()
|
|
|
|
|
.And.BeEquivalentTo("1.0.0-85");
|
|
|
|
|
|
|
|
|
|
var outputPackage = testInstance.Root
|
2016-11-04 19:56:21 +00:00
|
|
|
|
.GetDirectory("bin", "Debug")
|
2016-10-28 01:46:43 +00:00
|
|
|
|
.GetFile("TestLibraryWithConfiguration.1.0.0-85.nupkg");
|
|
|
|
|
|
|
|
|
|
outputPackage.Should().Exist();
|
2016-02-24 03:07:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
[Fact(Skip="https://github.com/dotnet/cli/issues/4486")]
|
2016-04-12 02:25:28 +00:00
|
|
|
|
public void HasIncludedFiles()
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var testInstance = TestAssets.Get("EndToEndTestApp")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithRestoreFiles()
|
|
|
|
|
.WithBuildFiles();
|
|
|
|
|
|
|
|
|
|
new PackCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
var outputPackage = testInstance.Root
|
|
|
|
|
.GetDirectory("bin", "Debug")
|
|
|
|
|
.GetFile("EndToEndTestApp.1.0.0.nupkg");
|
|
|
|
|
|
|
|
|
|
outputPackage.Should().Exist();
|
|
|
|
|
|
|
|
|
|
ZipFile.Open(outputPackage.FullName, ZipArchiveMode.Read)
|
|
|
|
|
.Entries
|
|
|
|
|
.Should().Contain(e => e.FullName == "packfiles/pack1.txt")
|
|
|
|
|
.And.Contain(e => e.FullName == "newpath/pack2.txt")
|
|
|
|
|
.And.Contain(e => e.FullName == "anotherpath/pack2.txt");
|
2016-04-12 02:25:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
[Fact(Skip="https://github.com/dotnet/cli/issues/4487")]
|
2016-04-07 22:59:25 +00:00
|
|
|
|
public void PackAddsCorrectFilesForProjectsWithOutputNameSpecified()
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var testInstance = TestAssets.Get("LibraryWithOutputAssemblyName")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithRestoreFiles();
|
|
|
|
|
|
|
|
|
|
new PackCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
|
|
// netstandard1.5 is a workaround for https://github.com/dotnet/sdk/issues/318
|
|
|
|
|
var outputPackage = testInstance.Root
|
|
|
|
|
.GetDirectory("bin", "Debug", "netstandard1.5")
|
|
|
|
|
.GetFile("LibraryWithOutputAssemblyName.1.0.0.nupkg");
|
|
|
|
|
|
|
|
|
|
outputPackage.Should().Exist();
|
|
|
|
|
|
|
|
|
|
ZipFile.Open(outputPackage.FullName, ZipArchiveMode.Read)
|
|
|
|
|
.Entries
|
|
|
|
|
.Should().Contain(e => e.FullName == "lib/netstandard1.5/MyLibrary.dll");
|
|
|
|
|
|
|
|
|
|
var symbolsPackage = testInstance.Root
|
|
|
|
|
.GetDirectory("bin", "Debug")
|
|
|
|
|
.GetFile("LibraryWithOutputAssemblyName.1.0.0.symbols.nupkg");
|
|
|
|
|
|
|
|
|
|
symbolsPackage.Should().Exist();
|
|
|
|
|
|
|
|
|
|
ZipFile.Open(symbolsPackage.FullName, ZipArchiveMode.Read)
|
|
|
|
|
.Entries
|
|
|
|
|
.Should().Contain(e => e.FullName == "lib/netstandard1.5/MyLibrary.dll")
|
|
|
|
|
.And.Contain(e => e.FullName == "lib/netstandard1.5/MyLibrary.pdb");
|
2016-04-07 22:59:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-26 22:22:09 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void PackWorksWithLocalProjectJson()
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var testInstance = TestAssets.Get("TestAppSimple")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithRestoreFiles();
|
2016-04-26 22:22:09 +00:00
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
new PackCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
2016-04-26 22:22:09 +00:00
|
|
|
|
.Execute()
|
2016-10-28 01:46:43 +00:00
|
|
|
|
.Should().Pass();
|
2016-04-26 22:22:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-03 22:46:16 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void HasServiceableFlagWhenArgumentPassed()
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var testInstance = TestAssets.Get("TestLibraryWithConfiguration")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithRestoreFiles()
|
|
|
|
|
.WithBuildFiles();
|
|
|
|
|
|
|
|
|
|
var packCommand = new PackCommand(configuration: "Debug", serviceable: true)
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root);
|
2016-06-03 22:46:16 +00:00
|
|
|
|
|
|
|
|
|
var result = packCommand.Execute();
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-06-03 22:46:16 +00:00
|
|
|
|
result.Should().Pass();
|
|
|
|
|
|
2016-11-04 19:56:21 +00:00
|
|
|
|
var outputDir = testInstance.Root.GetDirectory("bin", "Debug");
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
|
|
outputDir.Should().Exist()
|
|
|
|
|
.And.HaveFile("TestLibraryWithConfiguration.1.0.0.nupkg");
|
|
|
|
|
|
|
|
|
|
var outputPackage = outputDir.GetFile("TestLibraryWithConfiguration.1.0.0.nupkg");
|
|
|
|
|
|
|
|
|
|
var zip = ZipFile.Open(outputPackage.FullName, ZipArchiveMode.Read);
|
2016-06-03 22:46:16 +00:00
|
|
|
|
|
2016-08-10 06:00:26 +00:00
|
|
|
|
zip.Entries.Should().Contain(e => e.FullName == "TestLibraryWithConfiguration.nuspec");
|
2016-06-03 22:46:16 +00:00
|
|
|
|
|
2016-08-10 06:00:26 +00:00
|
|
|
|
var manifestReader = new StreamReader(zip.Entries.First(e => e.FullName == "TestLibraryWithConfiguration.nuspec").Open());
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-06-03 22:46:16 +00:00
|
|
|
|
var nuspecXml = XDocument.Parse(manifestReader.ReadToEnd());
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-06-03 22:46:16 +00:00
|
|
|
|
var node = nuspecXml.Descendants().Single(e => e.Name.LocalName == "serviceable");
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-06-03 22:46:16 +00:00
|
|
|
|
Assert.Equal("true", node.Value);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-16 18:20:23 +00:00
|
|
|
|
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
|
|
|
|
|
{
|
|
|
|
|
// copy all the files to temp dir
|
|
|
|
|
foreach (var file in Directory.EnumerateFiles(projectDir))
|
|
|
|
|
{
|
|
|
|
|
tempDir.CopyFile(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetProjectPath(TempDirectory projectDir)
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(projectDir.Path, "project.json");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|