2017-01-21 08:11:18 +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 FluentAssertions;
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
2017-06-14 03:29:44 +00:00
|
|
|
using Microsoft.DotNet.Tools.Add.PackageReference;
|
2017-01-21 08:11:18 +00:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using Xunit;
|
2017-02-01 05:31:02 +00:00
|
|
|
using Xunit.Abstractions;
|
2017-01-21 08:11:18 +00:00
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Package.Add.Tests
|
|
|
|
{
|
|
|
|
public class GivenDotnetPackageAdd : TestBase
|
|
|
|
{
|
2017-02-01 05:31:02 +00:00
|
|
|
private readonly ITestOutputHelper _output;
|
|
|
|
|
|
|
|
public GivenDotnetPackageAdd(ITestOutputHelper output)
|
|
|
|
{
|
|
|
|
_output = output;
|
|
|
|
}
|
2017-01-21 08:11:18 +00:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenValidPackageIsPassedBeforeVersionItGetsAdded()
|
|
|
|
{
|
|
|
|
var testAsset = "TestAppSimple";
|
|
|
|
var projectDirectory = TestAssets
|
|
|
|
.Get(testAsset)
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.Root
|
|
|
|
.FullName;
|
|
|
|
|
|
|
|
var packageName = "Newtonsoft.Json";
|
|
|
|
var packageVersion = "9.0.1";
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
.ExecuteWithCapturedOutput($"add package {packageName} --version {packageVersion}");
|
|
|
|
cmd.Should().Pass();
|
|
|
|
cmd.StdOut.Should().Contain($"PackageReference for package '{packageName}' version '{packageVersion}' " +
|
|
|
|
$"added to file '{projectDirectory + Path.DirectorySeparatorChar + testAsset}.csproj'.");
|
|
|
|
cmd.StdErr.Should().BeEmpty();
|
|
|
|
}
|
|
|
|
|
2017-02-01 05:31:02 +00:00
|
|
|
[Fact]
|
|
|
|
public void
|
|
|
|
WhenValidProjectAndPackageArePassedItGetsAdded()
|
|
|
|
{
|
|
|
|
var testAsset = "TestAppSimple";
|
|
|
|
var projectDirectory = TestAssets
|
|
|
|
.Get(testAsset)
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.Root
|
|
|
|
.FullName;
|
|
|
|
|
|
|
|
var csproj = $"{projectDirectory + Path.DirectorySeparatorChar + testAsset}.csproj";
|
|
|
|
var packageName = "Newtonsoft.Json";
|
|
|
|
var packageVersion = "9.0.1";
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
.ExecuteWithCapturedOutput($"add {csproj} package {packageName} --version {packageVersion}");
|
|
|
|
|
|
|
|
_output.WriteLine($"[STDOUT] {cmd.StdOut}\n[STDERR]{cmd.StdErr}\n");
|
|
|
|
|
|
|
|
cmd.Should().Pass();
|
|
|
|
|
|
|
|
cmd.StdOut.Should()
|
|
|
|
.Contain($"PackageReference for package \'{packageName}\' version \'{packageVersion}\' added to file '{csproj}'.");
|
|
|
|
|
|
|
|
cmd.StdErr.Should().BeEmpty();
|
|
|
|
}
|
|
|
|
|
2017-01-21 08:11:18 +00:00
|
|
|
[Fact]
|
|
|
|
public void WhenValidPackageIsPassedAfterVersionItGetsAdded()
|
|
|
|
{
|
|
|
|
var testAsset = "TestAppSimple";
|
|
|
|
var projectDirectory = TestAssets
|
|
|
|
.Get(testAsset)
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.Root
|
|
|
|
.FullName;
|
|
|
|
|
|
|
|
var packageName = "Newtonsoft.Json";
|
|
|
|
var packageVersion = "9.0.1";
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
.ExecuteWithCapturedOutput($"add package --version {packageVersion} {packageName}");
|
|
|
|
cmd.Should().Pass();
|
|
|
|
cmd.StdOut.Should().Contain($"PackageReference for package '{packageName}' version '{packageVersion}' " +
|
|
|
|
$"added to file '{projectDirectory + Path.DirectorySeparatorChar + testAsset}.csproj'.");
|
|
|
|
cmd.StdErr.Should().BeEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenValidPackageIsPassedWithFrameworkItGetsAdded()
|
|
|
|
{
|
|
|
|
var testAsset = "TestAppSimple";
|
|
|
|
var projectDirectory = TestAssets
|
|
|
|
.Get(testAsset)
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.Root
|
|
|
|
.FullName;
|
|
|
|
|
|
|
|
var packageName = "Newtonsoft.Json";
|
|
|
|
var packageVersion = "9.0.1";
|
2017-08-18 22:36:01 +00:00
|
|
|
var framework = "netcoreapp2.1";
|
2017-01-21 08:11:18 +00:00
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
.ExecuteWithCapturedOutput($"add package {packageName} --version {packageVersion} --framework {framework}");
|
|
|
|
cmd.Should().Pass();
|
|
|
|
cmd.StdOut.Should().Contain($"PackageReference for package '{packageName}' version '{packageVersion}' " +
|
|
|
|
$"added to file '{projectDirectory + Path.DirectorySeparatorChar + testAsset}.csproj'.");
|
|
|
|
cmd.StdErr.Should().BeEmpty();
|
|
|
|
}
|
|
|
|
|
2017-05-12 20:23:47 +00:00
|
|
|
[Fact]
|
|
|
|
public void WhenValidPackageIsPassedMSBuildDoesNotPrintVersionHeader()
|
|
|
|
{
|
|
|
|
var testAsset = "TestAppSimple";
|
|
|
|
var projectDirectory = TestAssets
|
|
|
|
.Get(testAsset)
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.Root
|
|
|
|
.FullName;
|
|
|
|
|
|
|
|
var packageName = "Newtonsoft.Json";
|
|
|
|
var packageVersion = "9.0.1";
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
.ExecuteWithCapturedOutput($"add package {packageName} --version {packageVersion}");
|
|
|
|
cmd.Should().Pass();
|
|
|
|
cmd.StdOut.Should().NotContain("Microsoft (R) Build Engine version");
|
|
|
|
cmd.StdErr.Should().BeEmpty();
|
|
|
|
}
|
|
|
|
|
2017-01-21 08:11:18 +00:00
|
|
|
[Fact]
|
|
|
|
public void WhenMultiplePackagesArePassedCommandFails()
|
|
|
|
{
|
|
|
|
var projectDirectory = TestAssets
|
|
|
|
.Get("TestAppSimple")
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.Root
|
|
|
|
.FullName;
|
|
|
|
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
.ExecuteWithCapturedOutput($"add package package1 package2 package3");
|
|
|
|
cmd.Should().Fail();
|
2017-06-14 03:29:44 +00:00
|
|
|
cmd.StdErr.Should().Contain(LocalizableStrings.SpecifyExactlyOnePackageReference);
|
2017-01-21 08:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void WhenNoPackageisPassedCommandFails()
|
|
|
|
{
|
|
|
|
var projectDirectory = TestAssets
|
|
|
|
.Get("TestAppSimple")
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.Root
|
|
|
|
.FullName;
|
|
|
|
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
.ExecuteWithCapturedOutput($"add package");
|
|
|
|
cmd.Should().Fail();
|
2017-06-14 03:29:44 +00:00
|
|
|
cmd.StdErr.Should().Contain(LocalizableStrings.SpecifyExactlyOnePackageReference);
|
2017-01-21 08:11:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|