Adding End to End test for cache and filtered publish

This commit is contained in:
Rama Krishnan Raghupathy 2017-02-13 17:56:25 -08:00
parent 4fdc72890a
commit c20e106d75
10 changed files with 315 additions and 8 deletions

View file

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26206.0
@ -206,6 +206,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.DotNet.Cli.Sln.In
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.DotNet.Cli.Sln.Internal.Tests", "test\Microsoft.DotNet.Cli.Sln.Internal.Tests\Microsoft.DotNet.Cli.Sln.Internal.Tests.csproj", "{56F1E090-B80F-4BDF-8991-4B0F9B5B8C9A}"
EndProject
Project("{13B669BE-BB05-4DDF-9536-439F39A36129}") = "dotnet-cache.Tests", "test\dotnet-cache.Tests\dotnet-cache.Tests.csproj", "{CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -1491,19 +1493,25 @@ Global
{56F1E090-B80F-4BDF-8991-4B0F9B5B8C9A}.RelWithDebInfo|x64.Build.0 = Debug|x86
{56F1E090-B80F-4BDF-8991-4B0F9B5B8C9A}.RelWithDebInfo|x86.ActiveCfg = Debug|x86
{56F1E090-B80F-4BDF-8991-4B0F9B5B8C9A}.RelWithDebInfo|x86.Build.0 = Debug|x86
{CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}.Debug|x64.ActiveCfg = Debug|x64
{CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}.Debug|x64.Build.0 = Debug|x64
{CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}.Debug|x86.ActiveCfg = Debug|x86
{CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}.Debug|x86.Build.0 = Debug|x86
{CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}.Release|Any CPU.Build.0 = Release|Any CPU
{CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}.Release|x64.ActiveCfg = Release|x64
{CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}.Release|x64.Build.0 = Release|x64
{CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}.Release|x86.ActiveCfg = Release|x86
{CACA427D-5A71-45E6-88DC-3E2DB6C4D52D}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{1AB5B24B-B317-4142-A5D1-A6E84F15BA34} = {ADA7052B-884B-4776-8B8D-D04191D0AA70}
{FD7D515A-D10F-4F49-B8AE-21CF7ED071AE} = {89905EC4-BC0F-443B-8ADF-691321F10108}
{8E3354BD-827F-41B7-9EE6-6BE1F1EDD8E9} = {89905EC4-BC0F-443B-8ADF-691321F10108}
{FF498306-2DE2-47F6-8C35-3CF0589CF2B8} = {89905EC4-BC0F-443B-8ADF-691321F10108}
{27B12960-ABB0-4903-9C60-5E9157E659C8} = {89905EC4-BC0F-443B-8ADF-691321F10108}
{8A2FA2D8-0DA1-4814-B5C1-2ECEAA613EB1} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3}
{19AC02B7-6D2C-4C2B-A410-9D4A59CE0E47} = {89905EC4-BC0F-443B-8ADF-691321F10108}
{2BDC1BC2-867E-47C0-BAD0-ADE897F07F78} = {89905EC4-BC0F-443B-8ADF-691321F10108}
{48A62BA4-D798-46A2-AB49-8A8471CF8165} = {1AB5B24B-B317-4142-A5D1-A6E84F15BA34}
{7C3D62C6-1D71-4C45-872F-7583F2AB304A} = {1AB5B24B-B317-4142-A5D1-A6E84F15BA34}
{79B4932C-3D57-494B-95AF-E5624F9D2F01} = {1AB5B24B-B317-4142-A5D1-A6E84F15BA34}
@ -1558,5 +1566,6 @@ Global
{F2D1A7DA-B3EB-4CA7-BAA9-A18CEC398853} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3}
{C98C7C2E-2C29-4A40-958C-60561ED77791} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
{56F1E090-B80F-4BDF-8991-4B0F9B5B8C9A} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{CACA427D-5A71-45E6-88DC-3E2DB6C4D52D} = {FF498306-2DE2-47F6-8C35-3CF0589CF2B8}
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NewtonSoft.Json" Version="9.0.1" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,19 @@
using System;
using System.Collections;
using Newtonsoft.Json.Linq;
class Program
{
public static void Main(string[] args)
{
ArrayList argList = new ArrayList(args);
JObject jObject = new JObject();
foreach (string arg in argList)
{
jObject[arg] = arg;
}
Console.WriteLine(jObject.ToString());
}
}

View file

@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version ="9.0.1"/>
</ItemGroup>
</Project>

View file

@ -29,6 +29,8 @@ namespace Microsoft.DotNet.TestFramework
private bool _built = false;
public static string CurrentRuntimeFrameworkVersion = new Muxer().SharedFxVersion;
public TestAssetInstance(TestAssetInfo testAssetInfo, DirectoryInfo root)
{
if (testAssetInfo == null)
@ -170,7 +172,7 @@ namespace Microsoft.DotNet.TestFramework
project.Root.Add(propertyGroup);
}
propertyGroup.Add(new XElement(ns + "RuntimeFrameworkVersion", new Muxer().SharedFxVersion));
propertyGroup.Add(new XElement(ns + "RuntimeFrameworkVersion", CurrentRuntimeFrameworkVersion));
});
}

View file

@ -72,6 +72,8 @@ Project("{13B669BE-BB05-4DDF-9536-439F39A36129}") = "dotnet-sln-remove.Tests", "
EndProject
Project("{13B669BE-BB05-4DDF-9536-439F39A36129}") = "dotnet-add-package.Tests", "dotnet-add-package.Tests\dotnet-add-package.Tests.csproj", "{3501AB72-3E05-45EE-9000-9515F5A139AC}"
EndProject
Project("{13B669BE-BB05-4DDF-9536-439F39A36129}") = "dotnet-cache.Tests", "dotnet-cache.Tests\dotnet-cache.Tests.csproj", "{7CA9ECD0-9284-496B-890F-94B63ECB37EC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -242,6 +244,18 @@ Global
{3501AB72-3E05-45EE-9000-9515F5A139AC}.Release|x64.Build.0 = Release|x64
{3501AB72-3E05-45EE-9000-9515F5A139AC}.Release|x86.ActiveCfg = Release|x86
{3501AB72-3E05-45EE-9000-9515F5A139AC}.Release|x86.Build.0 = Release|x86
{7CA9ECD0-9284-496B-890F-94B63ECB37EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7CA9ECD0-9284-496B-890F-94B63ECB37EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7CA9ECD0-9284-496B-890F-94B63ECB37EC}.Debug|x64.ActiveCfg = Debug|x64
{7CA9ECD0-9284-496B-890F-94B63ECB37EC}.Debug|x64.Build.0 = Debug|x64
{7CA9ECD0-9284-496B-890F-94B63ECB37EC}.Debug|x86.ActiveCfg = Debug|x86
{7CA9ECD0-9284-496B-890F-94B63ECB37EC}.Debug|x86.Build.0 = Debug|x86
{7CA9ECD0-9284-496B-890F-94B63ECB37EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7CA9ECD0-9284-496B-890F-94B63ECB37EC}.Release|Any CPU.Build.0 = Release|Any CPU
{7CA9ECD0-9284-496B-890F-94B63ECB37EC}.Release|x64.ActiveCfg = Release|x64
{7CA9ECD0-9284-496B-890F-94B63ECB37EC}.Release|x64.Build.0 = Release|x64
{7CA9ECD0-9284-496B-890F-94B63ECB37EC}.Release|x86.ActiveCfg = Release|x86
{7CA9ECD0-9284-496B-890F-94B63ECB37EC}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -0,0 +1,98 @@
// 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 Microsoft.DotNet.Cli.Utils;
using NuGet.Frameworks;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
public sealed class CacheCommand : TestCommand
{
private string _profileProject;
private string _framework;
private string _output;
private string _runtime;
private string _frameworkVersion;
private string _intermediateWorkingDirectory;
public CacheCommand()
: base("dotnet")
{
}
public CacheCommand WithEntries(string profileProject)
{
_profileProject = profileProject;
return this;
}
public CacheCommand WithFramework(string framework)
{
_framework = framework;
return this;
}
public CacheCommand WithFramework(NuGetFramework framework)
{
return WithFramework(framework.GetShortFolderName());
}
public CacheCommand WithOutput(string output)
{
_output = output;
return this;
}
public CacheCommand WithRuntime(string runtime)
{
_runtime = runtime;
return this;
}
public CacheCommand WithRuntimeFrameworkVersion(string frameworkVersion)
{
_frameworkVersion = frameworkVersion;
return this;
}
public CacheCommand WithIntermediateWorkingDirectory(string intermediateWorkingDirectory)
{
_intermediateWorkingDirectory = intermediateWorkingDirectory;
return this;
}
public override CommandResult Execute(string args = "")
{
args = $"cache {BuildArgs()} {args}";
return base.Execute(args);
}
public override CommandResult ExecuteWithCapturedOutput(string args = "")
{
args = $"cache {BuildArgs()} {args}";
return base.ExecuteWithCapturedOutput(args);
}
private string BuildArgs()
{
return string.Join(" ",
ProfileProjectOption,
FrameworkOption,
OutputOption,
IntermediateWorkingDirectoryOption,
RuntimeOption,
FrameworkVersionOption);
}
private string ProfileProjectOption => string.IsNullOrEmpty(_profileProject) ? "" : $"--entries {_profileProject}";
private string FrameworkOption => string.IsNullOrEmpty(_framework) ? "" : $"-f {_framework}";
private string OutputOption => string.IsNullOrEmpty(_output) ? "" : $"-o {_output}";
private string RuntimeOption => string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}";
private string FrameworkVersionOption => string.IsNullOrEmpty(_frameworkVersion) ? "" : $" --framework-version {_frameworkVersion}";
private string IntermediateWorkingDirectoryOption => string.IsNullOrEmpty(_intermediateWorkingDirectory)? "" : $" -w {_intermediateWorkingDirectory}";
}
}

View file

@ -11,6 +11,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private string _framework;
private string _output;
private string _runtime;
private string _profileproj;
public PublishCommand()
: base("dotnet")
@ -40,6 +41,12 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
return this;
}
public PublishCommand WithProFileProject(string profileproj)
{
_profileproj = profileproj;
return this;
}
public override CommandResult Execute(string args = "")
{
args = $"publish {BuildArgs()} {args}";
@ -57,6 +64,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
return string.Join(" ",
FrameworkOption,
OutputOption,
ProfileProjOption,
RuntimeOption);
}
@ -65,5 +73,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private string OutputOption => string.IsNullOrEmpty(_output) ? "" : $"-o {_output}";
private string RuntimeOption => string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}";
private string ProfileProjOption => string.IsNullOrEmpty(_profileproj) ? "" : $"--filter {_profileproj}";
}
}

View file

@ -0,0 +1,107 @@
// 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;
using System.Diagnostics;
using System.Runtime.InteropServices;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Cli.Publish.Tests
{
public class GivenDotnetPublishPublisheswithCacheProjects : TestBase
{
private static string _tfm = "netcoreapp2.0";
private static string _frameworkVersion = Microsoft.DotNet.TestFramework.TestAssetInstance.CurrentRuntimeFrameworkVersion;
[Fact]
public void ItPublishesARunnablePortableApp()
{
var testAppName = "NewtonSoftDependentProject";
var profileProjectName = "NewtonsoftFilterProfile";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles()
.UseCurrentRuntimeFrameworkVersion();
var testProjectDirectory = testInstance.Root.ToString();
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
var localAssemblyCache = Path.Combine(testProjectDirectory, "localAssemblyCache");
var intermediateWorkingDirectory = Path.Combine(testProjectDirectory, "workingDirectory");
var profileProject = Path.Combine(TestAssetsManager.AssetsRoot, profileProjectName, $"{profileProjectName}.xml");
new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should().Pass();
new CacheCommand()
.WithEntries(profileProject)
.WithFramework(_tfm)
.WithRuntime(rid)
.WithOutput(localAssemblyCache)
.WithRuntimeFrameworkVersion(_frameworkVersion)
.WithIntermediateWorkingDirectory(intermediateWorkingDirectory)
.Execute($"--preserve-working-dir")
.Should().Pass();
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
new PublishCommand()
.WithFramework(_tfm)
.WithWorkingDirectory(testProjectDirectory)
.WithProFileProject(profileProject)
.Execute()
.Should().Pass();
var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, _tfm, "publish", $"{testAppName}.dll");
new TestCommand("dotnet")
.WithEnvironmentVariable("DOTNET_SHARED_PACKAGES", localAssemblyCache)
.ExecuteWithCapturedOutput(outputDll)
.Should().Pass()
.And.HaveStdOutContaining("{}");
}
[Fact]
public void AppFailsDueToMissingCache()
{
var testAppName = "NewtonSoftDependentProject";
var profileProjectName = "NewtonsoftFilterProfile";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles()
.UseCurrentRuntimeFrameworkVersion();
var testProjectDirectory = testInstance.Root.ToString();
var profileProject = Path.Combine(TestAssetsManager.AssetsRoot, profileProjectName, $"{profileProjectName}.xml");
new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should().Pass();
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
new PublishCommand()
.WithFramework(_tfm)
.WithWorkingDirectory(testProjectDirectory)
.WithProFileProject(profileProject)
.Execute()
.Should().Pass();
var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, _tfm, "publish", $"{testAppName}.dll");
new TestCommand("dotnet")
.ExecuteWithCapturedOutput(outputDll)
.Should().Fail()
.And.HaveStdErrContaining("assembly specified in the dependencies manifest was not found -- package: 'newtonsoft.json',");
}
}
}

View file

@ -0,0 +1,33 @@
<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>$(CliTargetFramework)</TargetFramework>
<RuntimeFrameworkVersion>$(CLI_SharedFrameworkVersion)</RuntimeFrameworkVersion>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssemblyName>dotnet-cache.Tests</AssemblyName>
<PackageTargetFallback>$(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">
</ProjectReference>
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj">
</ProjectReference>
<ProjectReference Include="..\..\src\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj">
</ProjectReference>
</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="xunit">
<Version>2.2.0-beta4-build3444</Version>
</PackageReference>
</ItemGroup>
</Project>