This repository has been archived by the owner on Feb 15, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
57 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/Publish/Microsoft.NET.Sdk.Publish.Tasks/WebJobsCommandGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace Microsoft.NET.Sdk.Publish.Tasks | ||
{ | ||
public static class WebJobsCommandGenerator | ||
{ | ||
public static string RunCommand(string targetPath, bool useAppHost, string executableExtension) | ||
{ | ||
string appName = Path.GetFileName(targetPath); | ||
|
||
string command = $"dotnet {appName}"; | ||
if (useAppHost || string.Equals(Path.GetExtension(targetPath), ".exe", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
command = Path.ChangeExtension(appName, !string.IsNullOrWhiteSpace(executableExtension) ? executableExtension : null); | ||
} | ||
|
||
return $"{command} %*"; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
test/Publish/Microsoft.NET.Sdk.Publish.Tasks.Tests/WebJobsCommandGeneratorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Microsoft.NET.Sdk.Publish.Tasks; | ||
using Xunit; | ||
|
||
|
||
namespace Microsoft.Net.Sdk.Publish.Tasks.Tests | ||
{ | ||
public class WebJobsCommandGeneratorTests | ||
{ | ||
[Theory] | ||
[InlineData("c:\\test\\WebApplication1.dll", false, ".exe", "dotnet WebApplication1.dll %*")] | ||
|
||
[InlineData("c:\\test\\WebApplication1.dll", true, ".exe", "WebApplication1.exe %*")] | ||
[InlineData("c:\\test\\WebApplication1.dll", true, "", "WebApplication1 %*")] | ||
|
||
[InlineData("c:\\test\\WebApplication1.exe", true, ".exe", "WebApplication1.exe %*")] | ||
[InlineData("c:\\test\\WebApplication1.exe", false, ".exe", "WebApplication1.exe %*")] | ||
|
||
[InlineData("c:\\test\\WebApplication1.dll", true, ".sh", "WebApplication1.sh %*")] | ||
[InlineData("c:\\test\\WebApplication1.dll", false, ".sh", "dotnet WebApplication1.dll %*")] | ||
public void WebJobsCommandGenerator_Generates_Correct_RunCmd(string targetPath, bool useAppHost, string executableExtension, string expected) | ||
{ | ||
// Arrange | ||
|
||
// Test | ||
string generatedRunCommand = WebJobsCommandGenerator.RunCommand(targetPath, useAppHost, executableExtension); | ||
|
||
// Assert | ||
Assert.Equal(expected, generatedRunCommand); | ||
} | ||
} | ||
} |