Address PR Feedback

This commit is contained in:
Sridhar Periyasamy 2016-02-12 16:57:32 -08:00
parent 5fb1eaa9c6
commit d7274af53a
3 changed files with 46 additions and 17 deletions

View file

@ -1,19 +1,21 @@
{ {
"version": "1.0.0-*", "version": "1.0.0-*",
"description": "Microsoft.DotNet.TestFramework Class Library", "description": "Microsoft.DotNet.TestFramework Class Library",
"authors": [ "sridhper" ], "authors": [
"tags": [ "" ], "sridhper"
],
"tags": [
""
],
"projectUrl": "", "projectUrl": "",
"licenseUrl": "", "licenseUrl": "",
"dependencies": { "dependencies": {
"Microsoft.DotNet.Cli.Utils": "1.0.0-*", "Microsoft.DotNet.Cli.Utils": "1.0.0-*",
"NETStandard.Library": "1.0.0-rc2-23811" "NETStandard.Library": "1.0.0-rc2-23811"
}, },
"frameworks": { "frameworks": {
"dnxcore50": { "dnxcore50": {
"imports": "portable-net45+win8" "imports": "portable-net45+win8"
} }
} }
} }

View file

@ -0,0 +1,27 @@
// 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.Linq;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
public class ProjectUtils
{
public static string GetProjectJson(string testRoot, string project)
{
// We assume that the project name same as the directory name with contains the project.json
// We can do better here by using ProjectReader to get the correct project name
string projectPath = Directory.GetFiles(testRoot, "project.json", SearchOption.AllDirectories)
.FirstOrDefault(pj => Directory.GetParent(pj).Name.Equals(project));
if (string.IsNullOrEmpty(projectPath))
{
throw new Exception($"Cannot file project '{project}' in '{testRoot}'");
}
return projectPath;
}
}
}

View file

@ -15,6 +15,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
public class PublishTests : TestBase public class PublishTests : TestBase
{ {
private readonly string _testProjectsRoot; private readonly string _testProjectsRoot;
private readonly Func<string, string, string> _getProjectJson = ProjectUtils.GetProjectJson;
public PublishTests() public PublishTests()
{ {
@ -46,7 +47,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
.WithLockFiles() .WithLockFiles()
.WithBuildArtifacts(); .WithBuildArtifacts();
string testRoot = Path.Combine(instance.TestRoot, "TestApp", "project.json"); string testRoot = _getProjectJson(instance.TestRoot, "TestApp");
outputDir = string.IsNullOrEmpty(outputDir) ? "" : Path.Combine(instance.TestRoot, outputDir); outputDir = string.IsNullOrEmpty(outputDir) ? "" : Path.Combine(instance.TestRoot, outputDir);
var publishCommand = new PublishCommand(testRoot, output: outputDir); var publishCommand = new PublishCommand(testRoot, output: outputDir);
@ -73,7 +74,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
.WithLockFiles() .WithLockFiles()
.WithBuildArtifacts(); .WithBuildArtifacts();
var testProject = Path.Combine(instance.TestRoot, "project.json"); var testProject = _getProjectJson(instance.TestRoot, "TestAppWithContents");
var publishCommand = new PublishCommand(testProject); var publishCommand = new PublishCommand(testProject);
publishCommand.Execute().Should().Pass(); publishCommand.Execute().Should().Pass();
@ -85,7 +86,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
{ {
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary"); TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary");
string testProject = Path.Combine(instance.TestRoot, "TestApp", "project.json"); string testProject = _getProjectJson(instance.TestRoot, "TestApp");
var publishCommand = new PublishCommand(testProject); var publishCommand = new PublishCommand(testProject);
publishCommand.Execute().Should().Fail(); publishCommand.Execute().Should().Fail();
} }
@ -93,11 +94,11 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[Fact] [Fact]
public void LibraryPublishTest() public void LibraryPublishTest()
{ {
TestInstance instance = TestAssetsManager.CreateTestInstance(Path.Combine("TestAppWithLibrary", "TestLibrary")) TestInstance instance = TestAssetsManager.CreateTestInstance(Path.Combine("TestAppWithLibrary"))
.WithLockFiles() .WithLockFiles()
.WithBuildArtifacts(); .WithBuildArtifacts();
var testProject = Path.Combine(instance.TestRoot, "project.json"); var testProject = _getProjectJson(instance.TestRoot, "TestLibrary");
var publishCommand = new PublishCommand(testProject); var publishCommand = new PublishCommand(testProject);
publishCommand.Execute().Should().Pass(); publishCommand.Execute().Should().Pass();
@ -115,9 +116,8 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
.WithLockFiles() .WithLockFiles()
.WithBuildArtifacts(); .WithBuildArtifacts();
var lesserTestLibDir = Path.Combine(instance.TestRoot, "TestLibraryLesser"); var lesserTestProject = _getProjectJson(instance.TestRoot, "TestLibraryLesser");
var lesserTestProject = Path.Combine(lesserTestLibDir, "project.json");
var publishCommand = new PublishCommand(lesserTestProject, "net451"); var publishCommand = new PublishCommand(lesserTestProject, "net451");
publishCommand.Execute().Should().Pass(); publishCommand.Execute().Should().Pass();
@ -149,7 +149,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
.WithLockFiles() .WithLockFiles()
.WithBuildArtifacts(); .WithBuildArtifacts();
var testProject = Path.Combine(instance.TestRoot, "TestApp", "project.json"); var testProject = _getProjectJson(instance.TestRoot, "TestApp");
var publishCommand = new PublishCommand(testProject); var publishCommand = new PublishCommand(testProject);
publishCommand.Execute().Should().Pass(); publishCommand.Execute().Should().Pass();
@ -170,7 +170,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
TestInstance instance = TestAssetsManager.CreateTestInstance("CompileFail") TestInstance instance = TestAssetsManager.CreateTestInstance("CompileFail")
.WithLockFiles(); .WithLockFiles();
var testProject = Path.Combine(instance.TestRoot, "project.json"); var testProject = _getProjectJson(instance.TestRoot, "CompileFail");
var publishCommand = new PublishCommand(testProject); var publishCommand = new PublishCommand(testProject);
publishCommand.Execute().Should().Fail(); publishCommand.Execute().Should().Fail();
@ -184,7 +184,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
.WithLockFiles() .WithLockFiles()
.WithBuildArtifacts(); .WithBuildArtifacts();
var testProject = Path.Combine(instance.TestRoot, "TestApp", "project.json"); var testProject = _getProjectJson(instance.TestRoot, "TestApp");
var publishCommand = new PublishCommand(testProject); var publishCommand = new PublishCommand(testProject);
var result = publishCommand.ExecuteWithCapturedOutput(); var result = publishCommand.ExecuteWithCapturedOutput();