Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

[827616] Add ASP.NET Core Publish To Folder unit tests #9605

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using MonoDevelop.Components.Commands;
Expand All @@ -12,7 +12,6 @@
using MonoDevelop.DotNetCore;
using MonoDevelop.Core.ProgressMonitoring;
using Xwt;
using MonoDevelop.Core.Instrumentation;

namespace MonoDevelop.AspNetCore.Commands
{
Expand Down Expand Up @@ -85,23 +84,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);
Expand All @@ -125,6 +121,17 @@ public async Task Publish (PublishCommandItem item)
}
}

internal async Task<int> 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)) {
Expand Down
Expand Up @@ -27,6 +27,7 @@
<Compile Include="MonoDevelop.AspNetCore.Tests\AspNetCoreExecutionCommandTests.cs" />
<Compile Include="MonoDevelop.AspNetCore.Tests\AspNetCoreProjectTests.cs" />
<Compile Include="MonoDevelop.AspNetCore.Tests\ScaffoldingTests.cs" />
<Compile Include="MonoDevelop.AspNetCore.Tests\PublishToFolderTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\external\guiunit\src\framework\GuiUnit_NET_4_5.csproj">
Expand Down
@@ -0,0 +1,94 @@
//
// PublishToFolderTests.cs
//
// Author:
// Oleksii Sachek <v-olsach@microsoft.com>
//
// 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.Linq;
using System.Threading;
using System.Threading.Tasks;
using IdeUnitTests;
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 ();
}

[Test]
// .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 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, operationConsole, CancellationToken.None);

Assert.AreEqual (0, exitCode, "Publish to Folder command exit code must be 0");
}
}
}
Expand Up @@ -218,5 +218,8 @@
<Folder Include="MonoDevelop.AspNetCore.Scaffolding\Fields\" />
<Folder Include="MonoDevelop.AspNetCore.Scaffolding\Configuration\" />
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="MonoDevelop.AspNetCore.Tests" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>