dotnet list p2ps -> dotnet list reference
This commit is contained in:
parent
528d37bda5
commit
7042e85292
22 changed files with 19 additions and 19 deletions
217
test/dotnet-list-reference.Tests/GivenDotnetListReference.cs
Normal file
217
test/dotnet-list-reference.Tests/GivenDotnetListReference.cs
Normal file
|
@ -0,0 +1,217 @@
|
|||
// 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.Build.Construction;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Msbuild.Tests.Utilities;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.List.Reference.Tests
|
||||
{
|
||||
public class GivenDotnetListReference : TestBase
|
||||
{
|
||||
private const string HelpText = @".NET Core Project-to-Project dependency viewer
|
||||
|
||||
Usage: dotnet list <PROJECT> reference [options]
|
||||
|
||||
Arguments:
|
||||
<PROJECT> The project file to operate on. If a file is not specified, the command will search the current directory for one.
|
||||
|
||||
Options:
|
||||
-h|--help Show help information";
|
||||
|
||||
const string FrameworkNet451Arg = "-f net451";
|
||||
const string ConditionFrameworkNet451 = "== 'net451'";
|
||||
const string FrameworkNetCoreApp10Arg = "-f netcoreapp1.0";
|
||||
const string ConditionFrameworkNetCoreApp10 = "== 'netcoreapp1.0'";
|
||||
|
||||
[Theory]
|
||||
[InlineData("--help")]
|
||||
[InlineData("-h")]
|
||||
public void WhenHelpOptionIsPassedItPrintsUsage(string helpArg)
|
||||
{
|
||||
var cmd = new ListReferenceCommand().Execute(helpArg);
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData("unknownCommandName")]
|
||||
public void WhenNoCommandIsPassedItPrintsError(string commandName)
|
||||
{
|
||||
var cmd = new DotnetCommand()
|
||||
.ExecuteWithCapturedOutput($"list {commandName}");
|
||||
cmd.Should().Fail();
|
||||
cmd.StdErr.Should().Be("Required command was not provided.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenTooManyArgumentsArePassedItPrintsError()
|
||||
{
|
||||
var cmd = new AddReferenceCommand()
|
||||
.WithProject("one two three")
|
||||
.Execute("proj.csproj");
|
||||
cmd.ExitCode.Should().NotBe(0);
|
||||
cmd.StdErr.Should().Be("Unrecognized command or argument 'two'");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("idontexist.csproj")]
|
||||
[InlineData("ihave?inv@lid/char\\acters")]
|
||||
public void WhenNonExistingProjectIsPassedItPrintsErrorAndUsage(string projName)
|
||||
{
|
||||
var setup = Setup();
|
||||
|
||||
var cmd = new ListReferenceCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(projName)
|
||||
.Execute($"\"{setup.ValidRefCsprojPath}\"");
|
||||
cmd.ExitCode.Should().NotBe(0);
|
||||
cmd.StdErr.Should().Be($"Could not find project or directory `{projName}`.");
|
||||
cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenBrokenProjectIsPassedItPrintsErrorAndUsage()
|
||||
{
|
||||
string projName = "Broken/Broken.csproj";
|
||||
var setup = Setup();
|
||||
|
||||
var cmd = new ListReferenceCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.WithProject(projName)
|
||||
.Execute($"\"{setup.ValidRefCsprojPath}\"");
|
||||
cmd.ExitCode.Should().NotBe(0);
|
||||
cmd.StdErr.Should().Be("Project `Broken/Broken.csproj` is invalid.");
|
||||
cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenMoreThanOneProjectExistsInTheDirectoryItPrintsErrorAndUsage()
|
||||
{
|
||||
var setup = Setup();
|
||||
|
||||
var workingDir = Path.Combine(setup.TestRoot, "MoreThanOne");
|
||||
var cmd = new ListReferenceCommand()
|
||||
.WithWorkingDirectory(workingDir)
|
||||
.Execute($"\"{setup.ValidRefCsprojRelToOtherProjPath}\"");
|
||||
cmd.ExitCode.Should().NotBe(0);
|
||||
cmd.StdErr.Should().Be($"Found more than one project in `{workingDir + Path.DirectorySeparatorChar}`. Please specify which one to use.");
|
||||
cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenNoProjectsExistsInTheDirectoryItPrintsErrorAndUsage()
|
||||
{
|
||||
var setup = Setup();
|
||||
|
||||
var cmd = new ListReferenceCommand()
|
||||
.WithWorkingDirectory(setup.TestRoot)
|
||||
.Execute($"\"{setup.ValidRefCsprojPath}\"");
|
||||
cmd.ExitCode.Should().NotBe(0);
|
||||
cmd.StdErr.Should().Be($"Could not find any project in `{setup.TestRoot + Path.DirectorySeparatorChar}`.");
|
||||
cmd.StdOut.Should().BeVisuallyEquivalentTo(HelpText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenNoProjectReferencesArePresentInTheProjectItPrintsError()
|
||||
{
|
||||
var lib = NewLib();
|
||||
|
||||
var cmd = new ListReferenceCommand()
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute();
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().Be($"There are no Project to Project references in project {lib.CsProjPath}. ;; Project to Project is the type of the item being requested (project, package, p2p) and {lib.CsProjPath} is the object operated on (a project file or a solution file). ");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItPrintsSingleReference()
|
||||
{
|
||||
const string OutputText = @"Project reference(s)
|
||||
--------------------
|
||||
..\ItPrintsSingleReferenceref\ItPrintsSingleReferenceref.csproj";
|
||||
|
||||
var lib = NewLib("ItPrintsSingleReference", "lib");
|
||||
string ref1 = NewLib("ItPrintsSingleReference", "ref").CsProjPath;
|
||||
AddValidRef(ref1, lib);
|
||||
|
||||
var cmd = new ListReferenceCommand()
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute();
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().BeVisuallyEquivalentTo(OutputText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItPrintsMultipleReferences()
|
||||
{
|
||||
const string OutputText = @"Project reference(s)
|
||||
--------------------
|
||||
..\ItPrintsSingleReferenceref1\ItPrintsSingleReferenceref1.csproj
|
||||
..\ItPrintsSingleReferenceref2\ItPrintsSingleReferenceref2.csproj
|
||||
..\ItPrintsSingleReferenceref3\ItPrintsSingleReferenceref3.csproj";
|
||||
|
||||
var lib = NewLib("ItPrintsSingleReference", "lib");
|
||||
string ref1 = NewLib("ItPrintsSingleReference", "ref1").CsProjPath;
|
||||
string ref2 = NewLib("ItPrintsSingleReference", "ref2").CsProjPath;
|
||||
string ref3 = NewLib("ItPrintsSingleReference", "ref3").CsProjPath;
|
||||
|
||||
AddValidRef(ref1, lib);
|
||||
AddValidRef(ref2, lib);
|
||||
AddValidRef(ref3, lib);
|
||||
|
||||
var cmd = new ListReferenceCommand()
|
||||
.WithProject(lib.CsProjPath)
|
||||
.Execute();
|
||||
cmd.Should().Pass();
|
||||
cmd.StdOut.Should().BeVisuallyEquivalentTo(OutputText);
|
||||
}
|
||||
|
||||
private TestSetup Setup([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(Setup), string identifier = "")
|
||||
{
|
||||
return new TestSetup(
|
||||
TestAssets.Get(TestSetup.TestGroup, TestSetup.ProjectName)
|
||||
.CreateInstance(callingMethod: callingMethod, identifier: identifier)
|
||||
.WithSourceFiles()
|
||||
.Root
|
||||
.FullName);
|
||||
}
|
||||
|
||||
private ProjDir NewDir([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
|
||||
{
|
||||
return new ProjDir(TestAssetsManager.CreateTestDirectory(callingMethod: callingMethod, identifier: identifier).Path);
|
||||
}
|
||||
|
||||
private ProjDir NewLib([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
|
||||
{
|
||||
var dir = NewDir(callingMethod: callingMethod, identifier: identifier);
|
||||
|
||||
try
|
||||
{
|
||||
new NewCommand()
|
||||
.WithWorkingDirectory(dir.Path)
|
||||
.ExecuteWithCapturedOutput("-t Lib")
|
||||
.Should().Pass();
|
||||
}
|
||||
catch (System.ComponentModel.Win32Exception e)
|
||||
{
|
||||
throw new Exception($"Intermittent error in `dotnet new` occurred when running it in dir `{dir.Path}`\nException:\n{e}");
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
private void AddValidRef(string path, ProjDir proj)
|
||||
{
|
||||
new AddReferenceCommand()
|
||||
.WithProject(proj.CsProjPath)
|
||||
.Execute($"\"{path}\"")
|
||||
.Should().Pass();
|
||||
}
|
||||
}
|
||||
}
|
1
test/dotnet-list-reference.Tests/MSBuild.exe
Normal file
1
test/dotnet-list-reference.Tests/MSBuild.exe
Normal file
|
@ -0,0 +1 @@
|
|||
https://github.com/Microsoft/msbuild/issues/927
|
1
test/dotnet-list-reference.Tests/MSBuild.exe.config
Normal file
1
test/dotnet-list-reference.Tests/MSBuild.exe.config
Normal file
|
@ -0,0 +1 @@
|
|||
https://github.com/Microsoft/msbuild/issues/927
|
|
@ -0,0 +1,54 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp1.0</TargetFramework>
|
||||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
||||
<AssemblyName>dotnet-list-reference.Tests</AssemblyName>
|
||||
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dotnet5.4;portable-net451+win8</PackageTargetFallback>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.DotNet.Tools.Tests.Utilities\Microsoft.DotNet.Tools.Tests.Utilities.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj">
|
||||
<FromP2P>true</FromP2P>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj">
|
||||
<FromP2P>true</FromP2P>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj">
|
||||
<FromP2P>true</FromP2P>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Sln.Internal\Microsoft.DotNet.Cli.Sln.Internal.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.ProjectJsonMigration\Microsoft.DotNet.ProjectJsonMigration.csproj" />
|
||||
<ProjectReference Include="..\Msbuild.Tests.Utilities\Msbuild.Tests.Utilities.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
|
||||
<Reference Include="System.Runtime">
|
||||
<FromP2P>true</FromP2P>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk">
|
||||
<Version>15.0.0-preview-20161024-02</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="xunit.runner.visualstudio">
|
||||
<Version>2.2.0-beta4-build1194</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NETCore.App">
|
||||
<Version>1.0.3</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Runtime.Serialization.Primitives">
|
||||
<Version>4.1.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="xunit">
|
||||
<Version>2.2.0-beta4-build3444</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="FluentAssertions">
|
||||
<Version>4.0.0</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
</Project>
|
Loading…
Add table
Add a link
Reference in a new issue