add test coverage
This commit is contained in:
parent
21993e0129
commit
9a8d158e09
6 changed files with 130 additions and 1 deletions
|
@ -0,0 +1,3 @@
|
||||||
|
public class Net452AndNetCoreApp10Lib
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
|
||||||
|
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<TargetFrameworks>net452;netcoreapp1.0</TargetFrameworks>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="**\*.cs" />
|
||||||
|
<EmbeddedResource Include="**\*.resx" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Sdk">
|
||||||
|
<Version>$(CLI_NETSDK_Version)</Version>
|
||||||
|
<PrivateAssets>All</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
|
||||||
|
<PackageReference Include="Microsoft.NETCore.App">
|
||||||
|
<Version>1.0.1</Version>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
|
@ -0,0 +1,3 @@
|
||||||
|
public class Net45Lib
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
|
||||||
|
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<TargetFrameworks>net45</TargetFrameworks>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="**\*.cs" />
|
||||||
|
<EmbeddedResource Include="**\*.resx" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Sdk">
|
||||||
|
<Version>$(CLI_NETSDK_Version)</Version>
|
||||||
|
<PrivateAssets>All</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
|
||||||
|
<PackageReference Include="Microsoft.NETCore.App">
|
||||||
|
<Version>1.0.1</Version>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
|
@ -180,7 +180,6 @@
|
||||||
public const string SpecifiedAliasExists = "Specified alias {0} already exists. Please specify a different alias.";
|
public const string SpecifiedAliasExists = "Specified alias {0} already exists. Please specify a different alias.";
|
||||||
public const string MandatoryParameterMissing = "Mandatory parameter {0} missing for template {1}. ";
|
public const string MandatoryParameterMissing = "Mandatory parameter {0} missing for template {1}. ";
|
||||||
|
|
||||||
/// compatibility
|
|
||||||
public const string ProjectNotCompatibleWithFramework = "Project `{0}` is not compatible with `{1}`.";
|
public const string ProjectNotCompatibleWithFramework = "Project `{0}` is not compatible with `{1}`.";
|
||||||
public const string ProjectDoesNotTargetFramework = "Project `{0}` does not target `{1}`.";
|
public const string ProjectDoesNotTargetFramework = "Project `{0}` does not target `{1}`.";
|
||||||
public const string ProjectCouldNotBeEvaluated = "Project `{0}` could not be evaluated. Evaluation failed with following error:\n{1}";
|
public const string ProjectCouldNotBeEvaluated = "Project `{0}` could not be evaluated. Evaluation failed with following error:\n{1}";
|
||||||
|
|
|
@ -642,5 +642,79 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
||||||
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojRelPath.Replace('/', '\\')).Should().Be(1);
|
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojRelPath.Replace('/', '\\')).Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ItCanAddRefWithCondOnCompatibleFramework()
|
||||||
|
{
|
||||||
|
var setup = Setup();
|
||||||
|
var lib = new ProjDir(setup.LibDir);
|
||||||
|
var net45lib = new ProjDir(Path.Combine(setup.TestRoot, "Net45Lib"));
|
||||||
|
|
||||||
|
int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
|
||||||
|
var cmd = new AddP2PCommand()
|
||||||
|
.WithProject(lib.CsProjPath)
|
||||||
|
.Execute($"{FrameworkNet451Arg} \"{net45lib.CsProjPath}\"");
|
||||||
|
cmd.Should().Pass();
|
||||||
|
cmd.StdOut.Should().Contain("added to the project");
|
||||||
|
var csproj = lib.CsProj();
|
||||||
|
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
|
||||||
|
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(net45lib.CsProjName, ConditionFrameworkNet451).Should().Be(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ItCanAddRefWithoutCondAndTargetingSupersetOfFrameworksAndOneOfReferencesCompatible()
|
||||||
|
{
|
||||||
|
var setup = Setup();
|
||||||
|
var lib = new ProjDir(setup.LibDir);
|
||||||
|
var net452netcoreapp10lib = new ProjDir(Path.Combine(setup.TestRoot, "Net452AndNetCoreApp10Lib"));
|
||||||
|
|
||||||
|
int noCondBefore = net452netcoreapp10lib.CsProj().NumberOfItemGroupsWithoutCondition();
|
||||||
|
var cmd = new AddP2PCommand()
|
||||||
|
.WithProject(net452netcoreapp10lib.CsProjPath)
|
||||||
|
.Execute($"\"{lib.CsProjPath}\"");
|
||||||
|
cmd.Should().Pass();
|
||||||
|
cmd.StdOut.Should().Contain("added to the project");
|
||||||
|
var csproj = net452netcoreapp10lib.CsProj();
|
||||||
|
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
|
||||||
|
csproj.NumberOfProjectReferencesWithIncludeContaining(lib.CsProjName).Should().Be(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("net45")]
|
||||||
|
[InlineData("net40")]
|
||||||
|
[InlineData("netcoreapp1.1")]
|
||||||
|
[InlineData("nonexistingframeworkname")]
|
||||||
|
public void WhenFrameworkSwitchIsNotMatchingAnyOfTargetedFrameworksItPrintsError(string framework)
|
||||||
|
{
|
||||||
|
var setup = Setup();
|
||||||
|
var lib = new ProjDir(setup.LibDir);
|
||||||
|
var net45lib = new ProjDir(Path.Combine(setup.TestRoot, "Net45Lib"));
|
||||||
|
|
||||||
|
var csProjContent = lib.CsProjContent();
|
||||||
|
var cmd = new AddP2PCommand()
|
||||||
|
.WithProject(lib.CsProjPath)
|
||||||
|
.Execute($"-f {framework} \"{net45lib.CsProjPath}\"");
|
||||||
|
cmd.Should().Fail();
|
||||||
|
cmd.StdErr.Should().Contain("does not target");
|
||||||
|
lib.CsProjContent().Should().BeEquivalentTo(csProjContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("")]
|
||||||
|
[InlineData("-f net45")]
|
||||||
|
public void WhenIncompatibleFrameworkDetectedItPrintsError(string frameworkArg)
|
||||||
|
{
|
||||||
|
var setup = Setup();
|
||||||
|
var lib = new ProjDir(setup.LibDir);
|
||||||
|
var net45lib = new ProjDir(Path.Combine(setup.TestRoot, "Net45Lib"));
|
||||||
|
|
||||||
|
var csProjContent = net45lib.CsProjContent();
|
||||||
|
var cmd = new AddP2PCommand()
|
||||||
|
.WithProject(net45lib.CsProjPath)
|
||||||
|
.Execute($"{frameworkArg} \"{lib.CsProjPath}\"");
|
||||||
|
cmd.Should().Fail();
|
||||||
|
cmd.StdErr.Should().Contain("is not compatible with");
|
||||||
|
net45lib.CsProjContent().Should().BeEquivalentTo(csProjContent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue