Add a test case for a desktop app using Command.CreateDotnet, expecting to fail

This commit is contained in:
Bryan 2016-04-18 17:46:27 -07:00
parent bc8b0c065f
commit 56194a8e12
9 changed files with 142 additions and 18 deletions

View file

@ -0,0 +1,21 @@
using System;
using Microsoft.DotNet.Cli.Utils;
using System.IO;
namespace DesktopAppWhichCallsDotnet
{
public class Program
{
public static int Main(string[] args)
{
var projectPath = args[0];
return Command.CreateDotNet("build", new string[] {})
.WorkingDirectory(Path.GetDirectoryName(projectPath))
.ForwardStdErr()
.ForwardStdOut()
.Execute()
.ExitCode;
}
}
}

View file

@ -0,0 +1,12 @@
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.DotNet.Cli.Utils": "1.0.0-*"
},
"compilationOptions": {
"emitEntryPoint": true
},
"frameworks": {
"net451": {}
}
}

View file

@ -0,0 +1,12 @@
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

View file

@ -0,0 +1,12 @@
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": "1.0.0-rc2-*"
},
"frameworks": {
"netcoreapp1.0": { }
}
}

View file

@ -59,7 +59,10 @@ namespace Microsoft.DotNet.Cli.Build
[Target(nameof(RestoreTestAssetPackages), nameof(BuildTestAssetPackages))]
public static BuildTargetResult SetupTestPackages(BuildTargetContext c) => c.Success();
[Target(nameof(RestoreTestAssetProjects), nameof(RestoreDesktopTestAssetProjects), nameof(BuildTestAssetProjects))]
[Target(nameof(RestoreTestAssetProjects),
nameof(RestoreDesktopTestAssetProjects),
nameof(BuildTestAssetProjects),
nameof(BuildDesktopTestAssetProjects))]
public static BuildTargetResult SetupTestProjects(BuildTargetContext c) => c.Success();
[Target]
@ -236,25 +239,22 @@ namespace Microsoft.DotNet.Cli.Build
[Target]
public static BuildTargetResult BuildTestAssetProjects(BuildTargetContext c)
{
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects"));
var testAssetsRoot = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects");
var dotnet = DotNetCli.Stage2;
var nobuildFileName = ".noautobuild";
string testProjectsRoot = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects");
var projects = Directory.GetFiles(testProjectsRoot, "project.json", SearchOption.AllDirectories)
.Where(p => !ConditionalTestAssets.Where(s => !s.Skip() && p.EndsWith(Path.Combine(s.Path, "project.json"))).Any())
.Where(p => !File.Exists(Path.Combine(Path.GetDirectoryName(p), nobuildFileName)));
var framework = "netcoreapp1.0";
foreach (var project in projects)
{
c.Info($"Building: {project}");
dotnet.Build("--framework", "netcoreapp1.0")
.WorkingDirectory(Path.GetDirectoryName(project))
.Execute()
.EnsureSuccessful();
}
return BuildTestAssets(c, testAssetsRoot, dotnet, framework);
}
return c.Success();
[Target]
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult BuildDesktopTestAssetProjects(BuildTargetContext c)
{
var testAssetsRoot = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "DesktopTestProjects");
var dotnet = DotNetCli.Stage2;
var framework = "net451";
return BuildTestAssets(c, testAssetsRoot, dotnet, framework);
}
[Target]
@ -359,6 +359,28 @@ namespace Microsoft.DotNet.Cli.Build
return c.Success();
}
private static BuildTargetResult BuildTestAssets(BuildTargetContext c, string testAssetsRoot, DotNetCli dotnet, string framework)
{
CleanBinObj(c, testAssetsRoot);
var nobuildFileName = ".noautobuild";
var projects = Directory.GetFiles(testAssetsRoot, "project.json", SearchOption.AllDirectories)
.Where(p => !ConditionalTestAssets.Where(s => !s.Skip() && p.EndsWith(Path.Combine(s.Path, "project.json"))).Any())
.Where(p => !File.Exists(Path.Combine(Path.GetDirectoryName(p), nobuildFileName)));
foreach (var project in projects)
{
c.Info($"Building: {project}");
dotnet.Build("--framework", framework)
.WorkingDirectory(Path.GetDirectoryName(project))
.Execute()
.EnsureSuccessful();
}
return c.Success();
}
private static Dictionary<string, string> LoadVsVars(BuildTargetContext c)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))

View file

@ -27,7 +27,8 @@ namespace Microsoft.DotNet.Cli.Utils
FileName = commandSpec.Path,
Arguments = commandSpec.Args,
RedirectStandardError = true,
RedirectStandardOutput = true
RedirectStandardOutput = true,
UseShellExecute = false
};
_stdOut = new StreamForwarder();

View file

@ -0,0 +1,44 @@
// 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.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Linq;
using Xunit;
using Moq;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using System.Threading;
using FluentAssertions;
using NuGet.Frameworks;
namespace Microsoft.DotNet.Cli.Utils.Tests
{
public class GivenADesktopAppWhichUsesCommandCreateDotnet : TestBase
{
[WindowsOnlyFact]
public void It_calls_dotnet_build_on_a_project_successfully()
{
var testAssetsManager = GetTestGroupTestAssetsManager("DesktopTestProjects");
var testInstance = testAssetsManager
.CreateTestInstance("DesktopAppWhichCallsDotnet")
.WithLockFiles()
.WithBuildArtifacts();
var testProjectAssetManager = GetTestGroupTestAssetsManager("TestProjects");
var testInstanceToBuild = testProjectAssetManager
.CreateTestInstance("TestAppSimple")
.WithLockFiles();
var testProject = Path.Combine(testInstance.TestRoot, "project.json");
var testProjectToBuild = Path.Combine(testInstanceToBuild.TestRoot, "project.json");
new RunCommand(testProject).Execute(testProjectToBuild).Should().Pass();
}
}
}