From 78433197b366e5607d6988052acbb5d11026cb11 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Mon, 29 Feb 2016 10:46:13 -0800 Subject: [PATCH 1/4] Add tests to capture issue 1568 --- .../src/BrokenProjectFileSample/project.json | 9 ++++ .../IncorrectGlobalJson/global.json | 3 ++ .../src/Project1/NuGet.Config | 9 ++++ .../src/Project1/Program.cs | 12 +++++ .../src/Project1/project.json | 14 ++++++ .../DthTests.cs | 49 +++++++++++++++++++ 6 files changed, 96 insertions(+) create mode 100644 TestAssets/ProjectModelServer/DthTestProjects/src/BrokenProjectFileSample/project.json create mode 100644 TestAssets/ProjectModelServer/IncorrectGlobalJson/global.json create mode 100755 TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/NuGet.Config create mode 100755 TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/Program.cs create mode 100755 TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/project.json diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/BrokenProjectFileSample/project.json b/TestAssets/ProjectModelServer/DthTestProjects/src/BrokenProjectFileSample/project.json new file mode 100644 index 000000000..891039f78 --- /dev/null +++ b/TestAssets/ProjectModelServer/DthTestProjects/src/BrokenProjectFileSample/project.json @@ -0,0 +1,9 @@ +{ + "version": "1.0.0-*", + "dependencies": { + " + }, + "frameworks": { + [] + } +} \ No newline at end of file diff --git a/TestAssets/ProjectModelServer/IncorrectGlobalJson/global.json b/TestAssets/ProjectModelServer/IncorrectGlobalJson/global.json new file mode 100644 index 000000000..6663ba432 --- /dev/null +++ b/TestAssets/ProjectModelServer/IncorrectGlobalJson/global.json @@ -0,0 +1,3 @@ +{ + "projects": ["src"]] +} \ No newline at end of file diff --git a/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/NuGet.Config b/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/NuGet.Config new file mode 100755 index 000000000..e80222c1f --- /dev/null +++ b/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/NuGet.Config @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/Program.cs b/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/Program.cs new file mode 100755 index 000000000..51233cffa --- /dev/null +++ b/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace ConsoleApplication +{ + public class Program + { + public static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/project.json b/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/project.json new file mode 100755 index 000000000..8c87d36c9 --- /dev/null +++ b/TestAssets/ProjectModelServer/IncorrectGlobalJson/src/Project1/project.json @@ -0,0 +1,14 @@ +{ + "version": "1.0.0-*", + "compilationOptions": { + "emitEntryPoint": true + }, + + "dependencies": { + "NETStandard.Library": "1.0.0-rc2-23811" + }, + + "frameworks": { + "dnxcore50": { } + } +} diff --git a/test/dotnet-projectmodel-server.Tests/DthTests.cs b/test/dotnet-projectmodel-server.Tests/DthTests.cs index 639fd2d49..61d6faa79 100644 --- a/test/dotnet-projectmodel-server.Tests/DthTests.cs +++ b/test/dotnet-projectmodel-server.Tests/DthTests.cs @@ -9,6 +9,7 @@ using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.Extensions.Logging; using Microsoft.Extensions.PlatformAbstractions; +using Microsoft.DotNet.TestFramework; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Xunit; @@ -286,5 +287,53 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests } } } + + [Fact] + public void InvalidProjectJson() + { + using (var server = new DthTestServer(_loggerFactory)) + using (var client = new DthTestClient(server)) + { + client.Initialize(Path.Combine(_testAssetsManager.AssetsRoot, "EmptyLibrary")); + client.Initialize(Path.Combine(_testAssetsManager.AssetsRoot, "BrokenProjectFileSample")); + + // Error for invalid project.json + var messages = client.DrainAllMessages(); + messages.Single(msg => msg.MessageType == MessageTypes.Error) + .Payload.AsJObject() + .AssertProperty("Path", v => v.Contains("BrokenProjectFileSample")); + + // Successfully initialize the other project + messages.Single(msg => msg.MessageType == MessageTypes.ProjectInformation) + .Payload.AsJObject() + .AssertProperty("Name", v => string.Equals(v, "EmptyLibrary", StringComparison.Ordinal)); + + // Successfully initialize another project afterwards + client.Initialize(Path.Combine(_testAssetsManager.AssetsRoot, "EmptyConsoleApp")); + messages = client.DrainAllMessages(); + messages.Single(msg => msg.MessageType == MessageTypes.ProjectInformation) + .Payload.AsJObject() + .AssertProperty("Name", v => string.Equals(v, "EmptyConsoleApp", StringComparison.Ordinal)); + } + } + + [Fact] + public void InvalidGlobalJson() + { + var testAssetsPath = Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer"); + var assetsManager = new TestAssetsManager(testAssetsPath); + var testSource = assetsManager.CreateTestInstance("IncorrectGlobalJson"); + + using (var server = new DthTestServer(_loggerFactory)) + using (var client = new DthTestClient(server)) + { + client.Initialize(Path.Combine(testSource.TestRoot, "src", "Project1")); + + var messages = client.DrainAllMessages(); + messages.ContainsMessage(MessageTypes.Error) + .Single().Payload.AsJObject() + .AssertProperty("Path", v => v.Contains("InvalidGlobalJson")); + } + } } } From bcd656daec655a9359c0f1e418718f41ee4dcd2f Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Mon, 29 Feb 2016 19:55:01 -0800 Subject: [PATCH 2/4] Fix logging error --- .../commands/dotnet-projectmodel-server/ProjectManager.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/dotnet/commands/dotnet-projectmodel-server/ProjectManager.cs b/src/dotnet/commands/dotnet-projectmodel-server/ProjectManager.cs index 7da25727e..428f80df4 100644 --- a/src/dotnet/commands/dotnet-projectmodel-server/ProjectManager.cs +++ b/src/dotnet/commands/dotnet-projectmodel-server/ProjectManager.cs @@ -122,10 +122,8 @@ namespace Microsoft.DotNet.ProjectModel.Server } catch (Exception ex) { - // TODO: review error handing logic - - _log.LogError($"Error occurred: {ex}"); - + _log.LogError("Error occurs: {0}", ex.ToString()); + var error = new ErrorMessage { Message = ex.Message From 9f8906fdacb1fd8f86acdeeefbc00f37d8e0e746 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Mon, 29 Feb 2016 22:09:38 -0800 Subject: [PATCH 3/4] Update dotnet projectmodel tests --- .../src/EmptyLibrary/project-update.json | 2 +- .../DthTestProjects/src/EmptyLibrary/project.json | 2 +- .../src/FailReleaseProject/project.json | 2 +- .../project.json | 0 scripts/dotnet-cli-build/TestTargets.cs | 12 ++++++++---- .../FileFormatException.cs | 2 +- test/dotnet-projectmodel-server.Tests/DthTests.cs | 10 ++++++---- 7 files changed, 18 insertions(+), 12 deletions(-) rename TestAssets/ProjectModelServer/{DthTestProjects/src/BrokenProjectFileSample => IncorrectProjectJson}/project.json (100%) diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/project-update.json b/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/project-update.json index 9aaa9064d..ebe3e29af 100644 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/project-update.json +++ b/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/project-update.json @@ -3,7 +3,7 @@ "frameworks": { "dnxcore50": { "dependencies":{ - "System.Runtime": "4.0.21-beta-*", + "NETStandard.Library": "1.0.0-rc2-23811", "System.Console": "4.0.0-beta-*" } } diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/project.json b/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/project.json index 6e615135d..d3ff05ba2 100644 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/project.json +++ b/TestAssets/ProjectModelServer/DthTestProjects/src/EmptyLibrary/project.json @@ -4,7 +4,7 @@ "frameworks": { "dnxcore50": { "dependencies":{ - "System.Runtime": "4.0.21-*" + "NETStandard.Library": "1.0.0-rc2-23811" } } } diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/FailReleaseProject/project.json b/TestAssets/ProjectModelServer/DthTestProjects/src/FailReleaseProject/project.json index 60da6b421..ac54eee2f 100644 --- a/TestAssets/ProjectModelServer/DthTestProjects/src/FailReleaseProject/project.json +++ b/TestAssets/ProjectModelServer/DthTestProjects/src/FailReleaseProject/project.json @@ -2,7 +2,7 @@ "frameworks": { "dnxcore50": { "dependencies": { - "System.Runtime": "4.0.21-*" + "NETStandard.Library": "1.0.0-rc2-23811" } } }, diff --git a/TestAssets/ProjectModelServer/DthTestProjects/src/BrokenProjectFileSample/project.json b/TestAssets/ProjectModelServer/IncorrectProjectJson/project.json similarity index 100% rename from TestAssets/ProjectModelServer/DthTestProjects/src/BrokenProjectFileSample/project.json rename to TestAssets/ProjectModelServer/IncorrectProjectJson/project.json diff --git a/scripts/dotnet-cli-build/TestTargets.cs b/scripts/dotnet-cli-build/TestTargets.cs index 0036c397d..f02c700d0 100644 --- a/scripts/dotnet-cli-build/TestTargets.cs +++ b/scripts/dotnet-cli-build/TestTargets.cs @@ -73,14 +73,18 @@ namespace Microsoft.DotNet.Cli.Build CleanNuGetTempCache(); var dotnet = DotNetCli.Stage2; + dotnet.Restore("--fallbacksource", Dirs.TestPackages) .WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects")) .Execute().EnsureSuccessful(); - + // The 'ProjectModelServer' directory contains intentionally-unresolved dependencies, so don't check for success. Also, suppress the output - dotnet.Restore().WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "ProjectModelServer")) - .CaptureStdErr() - .CaptureStdOut() + dotnet.Restore() + .WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "ProjectModelServer", "DthTestProjects")) + .Execute(); + + dotnet.Restore() + .WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "ProjectModelServer", "DthUpdateSearchPathSample")) .Execute(); return c.Success(); diff --git a/src/Microsoft.DotNet.ProjectModel/FileFormatException.cs b/src/Microsoft.DotNet.ProjectModel/FileFormatException.cs index 4d723677a..0e9c5d11f 100644 --- a/src/Microsoft.DotNet.ProjectModel/FileFormatException.cs +++ b/src/Microsoft.DotNet.ProjectModel/FileFormatException.cs @@ -24,7 +24,7 @@ namespace Microsoft.DotNet.ProjectModel public override string ToString() { - return $"{Path}({Line},{Column}): Error: {base.ToString()}"; + return string.Format("{0}({1},{2}): {3}", Path, Line, Column, base.Message); } internal static FileFormatException Create(Exception exception, string filePath) diff --git a/test/dotnet-projectmodel-server.Tests/DthTests.cs b/test/dotnet-projectmodel-server.Tests/DthTests.cs index 61d6faa79..07d7ddf49 100644 --- a/test/dotnet-projectmodel-server.Tests/DthTests.cs +++ b/test/dotnet-projectmodel-server.Tests/DthTests.cs @@ -4,12 +4,10 @@ using System; using System.IO; using System.Linq; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.Extensions.Logging; using Microsoft.Extensions.PlatformAbstractions; -using Microsoft.DotNet.TestFramework; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Xunit; @@ -291,17 +289,21 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests [Fact] public void InvalidProjectJson() { + var testAssetsPath = Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer"); + var assetsManager = new TestAssetsManager(testAssetsPath); + var testSource = assetsManager.CreateTestInstance("IncorrectProjectJson").TestRoot; + using (var server = new DthTestServer(_loggerFactory)) using (var client = new DthTestClient(server)) { client.Initialize(Path.Combine(_testAssetsManager.AssetsRoot, "EmptyLibrary")); - client.Initialize(Path.Combine(_testAssetsManager.AssetsRoot, "BrokenProjectFileSample")); + client.Initialize(testSource); // Error for invalid project.json var messages = client.DrainAllMessages(); messages.Single(msg => msg.MessageType == MessageTypes.Error) .Payload.AsJObject() - .AssertProperty("Path", v => v.Contains("BrokenProjectFileSample")); + .AssertProperty("Path", v => v.Contains("IncorrectProjectJson")); // Successfully initialize the other project messages.Single(msg => msg.MessageType == MessageTypes.ProjectInformation) From 4dff646f5dfa53d2af94c7727172032ca907263e Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Tue, 1 Mar 2016 15:18:00 -0800 Subject: [PATCH 4/4] Update ProjectManager error message --- src/Microsoft.DotNet.ProjectModel/FileFormatException.cs | 4 ++-- .../commands/dotnet-projectmodel-server/ProjectManager.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectModel/FileFormatException.cs b/src/Microsoft.DotNet.ProjectModel/FileFormatException.cs index 0e9c5d11f..b65ed5ea9 100644 --- a/src/Microsoft.DotNet.ProjectModel/FileFormatException.cs +++ b/src/Microsoft.DotNet.ProjectModel/FileFormatException.cs @@ -23,8 +23,8 @@ namespace Microsoft.DotNet.ProjectModel public int Column { get; private set; } public override string ToString() - { - return string.Format("{0}({1},{2}): {3}", Path, Line, Column, base.Message); + { + return $"{Path}({Line},{Column}): Error: {base.ToString()}"; } internal static FileFormatException Create(Exception exception, string filePath) diff --git a/src/dotnet/commands/dotnet-projectmodel-server/ProjectManager.cs b/src/dotnet/commands/dotnet-projectmodel-server/ProjectManager.cs index 428f80df4..823c93d90 100644 --- a/src/dotnet/commands/dotnet-projectmodel-server/ProjectManager.cs +++ b/src/dotnet/commands/dotnet-projectmodel-server/ProjectManager.cs @@ -122,7 +122,7 @@ namespace Microsoft.DotNet.ProjectModel.Server } catch (Exception ex) { - _log.LogError("Error occurs: {0}", ex.ToString()); + _log.LogError("A unexpected exception occurred: {0}", ex.ToString()); var error = new ErrorMessage {