From 6326776f8f84ac4b97272e2214cea4f2f365adb8 Mon Sep 17 00:00:00 2001 From: Oleksii Sachek Date: Mon, 27 Jan 2020 10:08:53 +0200 Subject: [PATCH 1/4] [827616] Added basic PublishToFolder test --- .../PublishToFolderBaseCommandHandler.cs | 31 ++++++---- .../MonoDevelop.AspNetCore.Tests.csproj | 1 + .../PublishToFolderTests.cs | 60 +++++++++++++++++++ 3 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishToFolderTests.cs diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs index 11d3350f8fb..92c703eff79 100644 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs @@ -13,6 +13,7 @@ using MonoDevelop.Core.ProgressMonitoring; using Xwt; using MonoDevelop.Core.Instrumentation; +using System.Threading; namespace MonoDevelop.AspNetCore.Commands { @@ -85,23 +86,20 @@ public async Task Publish (PublishCommandItem item) counterMetadata.SetFailure (); return; } - var dotnetPath = DotNetCoreRuntime.FileName; + progressMonitor.BeginTask ("dotnet publish", 1); - var process = Runtime.ProcessService.StartConsoleProcess ( - dotnetPath, + + int publishExitCode = await RunPublishCommand ( BuildArgs (item), item.Project.BaseDirectory, - consoleMonitor.Console); - - using (progressMonitor.CancellationToken.Register (process.Cancel)) { - await process.Task; - } + consoleMonitor.Console, + progressMonitor.CancellationToken); if (!progressMonitor.CancellationToken.IsCancellationRequested) { - if (process.ExitCode != 0) { + if (publishExitCode != 0) { counterMetadata.SetFailure (); - progressMonitor.ReportError (GettextCatalog.GetString ("dotnet publish returned: {0}", process.ExitCode)); - LoggingService.LogError ($"Unknown exit code returned from 'dotnet publish --output {item.Profile.PublishUrl}': {process.ExitCode}"); + progressMonitor.ReportError (GettextCatalog.GetString ("dotnet publish returned: {0}", publishExitCode)); + LoggingService.LogError ($"Unknown exit code returned from 'dotnet publish --output {item.Profile.PublishUrl}': {publishExitCode}"); } else { counterMetadata.SetSuccess (); OpenFolder (item.Profile.PublishUrl); @@ -125,6 +123,17 @@ public async Task Publish (PublishCommandItem item) } } + public async Task RunPublishCommand (string args, string wokingDirectory, OperationConsole console, CancellationToken сancellationToken) + { + var process = Runtime.ProcessService.StartConsoleProcess (DotNetCoreRuntime.FileName, args, wokingDirectory, console); + + using (сancellationToken.Register (process.Cancel)) { + await process.Task; + } + + return process.ExitCode; + } + void OpenFolder (string path) { if (!Uri.TryCreate (path, UriKind.Absolute, out var pathUri)) { diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests.csproj b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests.csproj index 9cc8f99e812..0bec0dec1ad 100644 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests.csproj +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests.csproj @@ -27,6 +27,7 @@ + diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishToFolderTests.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishToFolderTests.cs new file mode 100644 index 00000000000..27f2d0bf8e0 --- /dev/null +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishToFolderTests.cs @@ -0,0 +1,60 @@ +// +// PublishToFolderTests.cs +// +// Author: +// Oleksii Sachek +// +// Copyright (c) 2020 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System.Threading; +using System.Threading.Tasks; +using NUnit.Framework; +using UnitTests; +using MonoDevelop.AspNetCore.Commands; +using MonoDevelop.Projects; + +namespace MonoDevelop.AspNetCore.Tests +{ + [TestFixture] + public class PublishToFolderTests : TestBase + { + PublishToFolderCommandHandler publishToFolderCommandHandler; + + [SetUp] + public async Task SetUp () + { + publishToFolderCommandHandler = new PublishToFolderCommandHandler (); + await Simulate (); + } + + [Test] + [TestCase ("aspnetcore-empty-22", "aspnetcore-empty-22.sln", "publish --output bin/Release/netcoreapp/publish")] + public async Task PublishToFolder (string projectName, string projectItem, string publishArgs) + { + var projectFileName = Util.GetSampleProject (projectName, projectItem); + using var project = (DotNetProject)await Services.ProjectService.ReadSolutionItem (Util.GetMonitor (), projectFileName); + + int exitCode = await publishToFolderCommandHandler.RunPublishCommand (publishArgs, project.BaseDirectory, null, CancellationToken.None); + + Assert.AreEqual (0, exitCode, "Publish to Folder command exit code must be 0"); + } + } +} From 7e97698cdb5599d89f605ad47093ff8b4a2721b0 Mon Sep 17 00:00:00 2001 From: Oleksii Sachek Date: Mon, 27 Jan 2020 13:32:57 +0200 Subject: [PATCH 2/4] [827616] Make RunPublishCommand internal and fix PublishToFolder test cases --- .../PublishToFolderBaseCommandHandler.cs | 2 +- .../PublishToFolderTests.cs | 71 +++++++++++++++++-- .../MonoDevelop.AspNetCore.csproj | 3 + 3 files changed, 69 insertions(+), 7 deletions(-) diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs index 92c703eff79..1a03b1f2bc4 100644 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs @@ -123,7 +123,7 @@ public async Task Publish (PublishCommandItem item) } } - public async Task RunPublishCommand (string args, string wokingDirectory, OperationConsole console, CancellationToken сancellationToken) + internal async Task RunPublishCommand (string args, string wokingDirectory, OperationConsole console, CancellationToken сancellationToken) { var process = Runtime.ProcessService.StartConsoleProcess (DotNetCoreRuntime.FileName, args, wokingDirectory, console); diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishToFolderTests.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishToFolderTests.cs index 27f2d0bf8e0..f3da7b7ce93 100644 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishToFolderTests.cs +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishToFolderTests.cs @@ -24,11 +24,15 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System.IO; +using System.Text; +using System.Linq; using System.Threading; using System.Threading.Tasks; using NUnit.Framework; using UnitTests; using MonoDevelop.AspNetCore.Commands; +using MonoDevelop.Core.Execution; using MonoDevelop.Projects; namespace MonoDevelop.AspNetCore.Tests @@ -42,19 +46,74 @@ public class PublishToFolderTests : TestBase public async Task SetUp () { publishToFolderCommandHandler = new PublishToFolderCommandHandler (); - await Simulate (); } [Test] - [TestCase ("aspnetcore-empty-22", "aspnetcore-empty-22.sln", "publish --output bin/Release/netcoreapp/publish")] - public async Task PublishToFolder (string projectName, string projectItem, string publishArgs) + // .NET Core 2.2, regular + [TestCase ("aspnetcore-empty-22", "publish --output bin/Release/netcoreapp/publish")] + [TestCase ("aspnetcore-empty-22", "publish --configuration Debug --output bin/debug-22")] + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --output bin/release-22")] + // .NET Core 2.2, self-contained + // OSX + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime osx-x64 --output bin/release-22-self-contained-osx")] + // Windows + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime win-x64 --output bin/release-22-self-contained-win-x64")] + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime win-x86 --output bin/release-22-self-contained-win-x86")] + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime win-arm --output bin/release-22-self-contained-win-arm")] + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime win-arm64 --output bin/release-22self-contained-win-arm64")] + // Linux + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime linux-x64 --output bin/release-22-self-contained-linux-x64")] + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime linux-musl-x64 --output bin/release-22-self-contained-linux-musl-x64")] + [TestCase ("aspnetcore-empty-22", "publish --configuration Release --self-contained --runtime linux-arm --output bin/release-22-self-contained-linux-arm")] + // .NET Core 3.0, regular + [TestCase ("aspnetcore-empty-30", "publish --output bin/Release/netcoreapp/publish")] + [TestCase ("aspnetcore-empty-30", "publish --configuration Debug --output bin/debug-22")] + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --output bin/release-22")] + // .NET Core 3.0, self-contained + // OSX + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime osx-x64 --output bin/release-22-self-contained-osx")] + // Windows + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime win-x64 --output bin/release-22-self-contained-win-x64")] + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime win-x86 --output bin/release-22-self-contained-win-x86")] + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime win-arm --output bin/release-22-self-contained-win-arm")] + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime win-arm64 --output bin/release-22self-contained-win-arm64")] + // Linux + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime linux-x64 --output bin/release-22-self-contained-linux-x64")] + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime linux-musl-x64 --output bin/release-22-self-contained-linux-musl-x64")] + [TestCase ("aspnetcore-empty-30", "publish --configuration Release --self-contained --runtime linux-arm --output bin/release-22-self-contained-linux-arm")] + public async Task PublishToFolder (string solutionName, string publishArgs) { - var projectFileName = Util.GetSampleProject (projectName, projectItem); - using var project = (DotNetProject)await Services.ProjectService.ReadSolutionItem (Util.GetMonitor (), projectFileName); + var solutionFileName = Util.GetSampleProject (solutionName, $"{solutionName}.sln"); + var solution = (Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solutionFileName); + var project = (DotNetProject)solution.GetAllProjects ().Single (); + var operationConsole = new MockOperationConsole (); - int exitCode = await publishToFolderCommandHandler.RunPublishCommand (publishArgs, project.BaseDirectory, null, CancellationToken.None); + int exitCode = await publishToFolderCommandHandler.RunPublishCommand (publishArgs, project.BaseDirectory, operationConsole, CancellationToken.None); Assert.AreEqual (0, exitCode, "Publish to Folder command exit code must be 0"); } + + class MockOperationConsole : OperationConsole + { + readonly TextReader textReader = new MockTextReader (); + readonly TextWriter textWriter = new MockTextWriter (); + + public override TextReader In => textReader; + + public override TextWriter Out => textWriter; + + public override TextWriter Error => textWriter; + + public override TextWriter Log => textWriter; + + class MockTextReader : TextReader + { + } + + class MockTextWriter : TextWriter + { + public override Encoding Encoding => Encoding.Default; + } + } } } diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.csproj b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.csproj index eca7d6cbc08..dc94f9741bc 100644 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.csproj +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.csproj @@ -218,5 +218,8 @@ + + + From d901ecc8f91e9f460be5fb0cdeadc90972bbfbcc Mon Sep 17 00:00:00 2001 From: Oleksii Sachek Date: Mon, 27 Jan 2020 13:36:46 +0200 Subject: [PATCH 3/4] [827616] Reordered usings and removed unused ones --- .../PublishToFolderBaseCommandHandler.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs index 1a03b1f2bc4..2c6f8242127 100644 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Commands/PublishToFolderBaseCommandHandler.cs @@ -1,5 +1,5 @@ using System; -using System.Linq; +using System.Threading; using System.Threading.Tasks; using System.IO; using MonoDevelop.Components.Commands; @@ -12,8 +12,6 @@ using MonoDevelop.DotNetCore; using MonoDevelop.Core.ProgressMonitoring; using Xwt; -using MonoDevelop.Core.Instrumentation; -using System.Threading; namespace MonoDevelop.AspNetCore.Commands { From 3e5111413adda163d372daf3c2872cc3c520c3d5 Mon Sep 17 00:00:00 2001 From: Oleksii Sachek Date: Mon, 27 Jan 2020 13:39:03 +0200 Subject: [PATCH 4/4] [827616] Use IdeUnitTests mock for OperationConsole --- .../PublishToFolderTests.cs | 27 +------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishToFolderTests.cs b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishToFolderTests.cs index f3da7b7ce93..17d81e548f9 100644 --- a/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishToFolderTests.cs +++ b/main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore.Tests/MonoDevelop.AspNetCore.Tests/PublishToFolderTests.cs @@ -24,15 +24,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using System.IO; -using System.Text; using System.Linq; using System.Threading; using System.Threading.Tasks; +using IdeUnitTests; using NUnit.Framework; using UnitTests; using MonoDevelop.AspNetCore.Commands; -using MonoDevelop.Core.Execution; using MonoDevelop.Projects; namespace MonoDevelop.AspNetCore.Tests @@ -92,28 +90,5 @@ public async Task PublishToFolder (string solutionName, string publishArgs) Assert.AreEqual (0, exitCode, "Publish to Folder command exit code must be 0"); } - - class MockOperationConsole : OperationConsole - { - readonly TextReader textReader = new MockTextReader (); - readonly TextWriter textWriter = new MockTextWriter (); - - public override TextReader In => textReader; - - public override TextWriter Out => textWriter; - - public override TextWriter Error => textWriter; - - public override TextWriter Log => textWriter; - - class MockTextReader : TextReader - { - } - - class MockTextWriter : TextWriter - { - public override Encoding Encoding => Encoding.Default; - } - } } }