diff --git a/src/Microsoft.DotNet.TestFramework/project.json b/src/Microsoft.DotNet.TestFramework/project.json index 3bda54ee8..bd0a4ff26 100644 --- a/src/Microsoft.DotNet.TestFramework/project.json +++ b/src/Microsoft.DotNet.TestFramework/project.json @@ -1,19 +1,21 @@ { "version": "1.0.0-*", "description": "Microsoft.DotNet.TestFramework Class Library", - "authors": [ "sridhper" ], - "tags": [ "" ], + "authors": [ + "sridhper" + ], + "tags": [ + "" + ], "projectUrl": "", "licenseUrl": "", - "dependencies": { "Microsoft.DotNet.Cli.Utils": "1.0.0-*", "NETStandard.Library": "1.0.0-rc2-23811" }, - "frameworks": { - "dnxcore50": { - "imports": "portable-net45+win8" - } + "dnxcore50": { + "imports": "portable-net45+win8" + } } } diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/ProjectUtils.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/ProjectUtils.cs new file mode 100644 index 000000000..3b812ed28 --- /dev/null +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/ProjectUtils.cs @@ -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; + } + } +} diff --git a/test/dotnet-publish.Tests/Microsoft.DotNet.Tools.Publish.Tests.cs b/test/dotnet-publish.Tests/Microsoft.DotNet.Tools.Publish.Tests.cs index 0ce93eb1d..7972f7a91 100644 --- a/test/dotnet-publish.Tests/Microsoft.DotNet.Tools.Publish.Tests.cs +++ b/test/dotnet-publish.Tests/Microsoft.DotNet.Tools.Publish.Tests.cs @@ -15,6 +15,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests public class PublishTests : TestBase { private readonly string _testProjectsRoot; + private readonly Func _getProjectJson = ProjectUtils.GetProjectJson; public PublishTests() { @@ -46,7 +47,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests .WithLockFiles() .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); var publishCommand = new PublishCommand(testRoot, output: outputDir); @@ -73,7 +74,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests .WithLockFiles() .WithBuildArtifacts(); - var testProject = Path.Combine(instance.TestRoot, "project.json"); + var testProject = _getProjectJson(instance.TestRoot, "TestAppWithContents"); var publishCommand = new PublishCommand(testProject); publishCommand.Execute().Should().Pass(); @@ -85,7 +86,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests { 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); publishCommand.Execute().Should().Fail(); } @@ -93,11 +94,11 @@ namespace Microsoft.DotNet.Tools.Publish.Tests [Fact] public void LibraryPublishTest() { - TestInstance instance = TestAssetsManager.CreateTestInstance(Path.Combine("TestAppWithLibrary", "TestLibrary")) + TestInstance instance = TestAssetsManager.CreateTestInstance(Path.Combine("TestAppWithLibrary")) .WithLockFiles() .WithBuildArtifacts(); - var testProject = Path.Combine(instance.TestRoot, "project.json"); + var testProject = _getProjectJson(instance.TestRoot, "TestLibrary"); var publishCommand = new PublishCommand(testProject); publishCommand.Execute().Should().Pass(); @@ -115,9 +116,8 @@ namespace Microsoft.DotNet.Tools.Publish.Tests .WithLockFiles() .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"); publishCommand.Execute().Should().Pass(); @@ -149,7 +149,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests .WithLockFiles() .WithBuildArtifacts(); - var testProject = Path.Combine(instance.TestRoot, "TestApp", "project.json"); + var testProject = _getProjectJson(instance.TestRoot, "TestApp"); var publishCommand = new PublishCommand(testProject); publishCommand.Execute().Should().Pass(); @@ -170,7 +170,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests TestInstance instance = TestAssetsManager.CreateTestInstance("CompileFail") .WithLockFiles(); - var testProject = Path.Combine(instance.TestRoot, "project.json"); + var testProject = _getProjectJson(instance.TestRoot, "CompileFail"); var publishCommand = new PublishCommand(testProject); publishCommand.Execute().Should().Fail(); @@ -184,7 +184,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests .WithLockFiles() .WithBuildArtifacts(); - var testProject = Path.Combine(instance.TestRoot, "TestApp", "project.json"); + var testProject = _getProjectJson(instance.TestRoot, "TestApp"); var publishCommand = new PublishCommand(testProject); var result = publishCommand.ExecuteWithCapturedOutput();