-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from Cysharp/feature/ReturnValueAsExitCode
Treat the return value as the exit code.
- Loading branch information
Showing
4 changed files
with
151 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using Xunit; | ||
|
||
[assembly: CollectionBehavior(DisableTestParallelization = true)] |
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,114 @@ | ||
using FluentAssertions; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace MicroBatchFramework.Tests | ||
{ | ||
public class ExitCodeTest | ||
{ | ||
public class ExitCodeTestBatch : BatchBase | ||
{ | ||
[Command(nameof(NoExitCode))] | ||
public void NoExitCode() | ||
{ | ||
} | ||
|
||
[Command(nameof(NoExitCodeException))] | ||
public void NoExitCodeException() | ||
{ | ||
throw new Exception(); | ||
} | ||
|
||
[Command(nameof(NoExitCodeWithTask))] | ||
public Task NoExitCodeWithTask() | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
[Command(nameof(ExitCode))] | ||
public int ExitCode() | ||
{ | ||
return 12345; | ||
} | ||
|
||
[Command(nameof(ExitCodeException))] | ||
public int ExitCodeException() | ||
{ | ||
throw new Exception(); | ||
} | ||
|
||
[Command(nameof(ExitCodeWithTask))] | ||
public Task<int> ExitCodeWithTask() | ||
{ | ||
return Task.FromResult(54321); | ||
} | ||
|
||
[Command(nameof(ExitCodeWithTaskException))] | ||
public Task<int> ExitCodeWithTaskException() | ||
{ | ||
throw new Exception(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task NoExitCode() | ||
{ | ||
Environment.ExitCode = 0; | ||
await new HostBuilder().RunBatchEngineAsync<ExitCodeTestBatch>(new[] { nameof(NoExitCode) }); | ||
Assert.Equal(0, Environment.ExitCode); | ||
} | ||
|
||
[Fact] | ||
public async Task NoExitCodeWithTask() | ||
{ | ||
Environment.ExitCode = 0; | ||
await new HostBuilder().RunBatchEngineAsync<ExitCodeTestBatch>(new[] { nameof(NoExitCodeWithTask) }); | ||
Assert.Equal(0, Environment.ExitCode); | ||
} | ||
|
||
[Fact] | ||
public async Task NoExitCodeException() | ||
{ | ||
Environment.ExitCode = 0; | ||
await new HostBuilder().RunBatchEngineAsync<ExitCodeTestBatch>(new[] { nameof(NoExitCodeException) }); | ||
Assert.Equal(1, Environment.ExitCode); | ||
} | ||
|
||
[Fact] | ||
public async Task ExitCode() | ||
{ | ||
Environment.ExitCode = 0; | ||
await new HostBuilder().RunBatchEngineAsync<ExitCodeTestBatch>(new[] { nameof(ExitCode) }); | ||
Assert.Equal(12345, Environment.ExitCode); | ||
} | ||
|
||
[Fact] | ||
public async Task ExitCodeException() | ||
{ | ||
Environment.ExitCode = 0; | ||
await new HostBuilder().RunBatchEngineAsync<ExitCodeTestBatch>(new[] { nameof(ExitCodeException) }); | ||
Assert.Equal(1, Environment.ExitCode); | ||
} | ||
|
||
[Fact] | ||
public async Task ExitCodeWithTask() | ||
{ | ||
Environment.ExitCode = 0; | ||
await new HostBuilder().RunBatchEngineAsync<ExitCodeTestBatch>(new[] { nameof(ExitCodeWithTask) }); | ||
Assert.Equal(54321, Environment.ExitCode); | ||
} | ||
|
||
[Fact] | ||
public async Task ExitCodeWithTaskException() | ||
{ | ||
Environment.ExitCode = 0; | ||
await new HostBuilder().RunBatchEngineAsync<ExitCodeTestBatch>(new[] { nameof(ExitCodeWithTaskException) }); | ||
Assert.Equal(1, Environment.ExitCode); | ||
} | ||
|
||
} | ||
} |