This repository has been archived by the owner on May 1, 2024. 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.
Dealing w/ the proper async returns. Closes GH-5
- Loading branch information
1 parent
a8e74b5
commit b24bb54
Showing
12 changed files
with
427 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Jasper.Codegen; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace Jasper.Testing.Codegen | ||
{ | ||
public class HandlerGenerationTests: CompilationContext | ||
{ | ||
private AsyncMode theAsyncMode => new HandlerGeneration(theChain, new GenerationConfig("Something"), "input") | ||
.AsyncMode; | ||
|
||
[Fact] | ||
public void detects_that_it_is_all_sync() | ||
{ | ||
theChain.Call<MainInput>(x => x.DoSync()); | ||
|
||
theAsyncMode.ShouldBe(AsyncMode.ReturnCompletedTask); | ||
|
||
theChain.Call<MainInput>(x => x.Touch()); | ||
|
||
theAsyncMode.ShouldBe(AsyncMode.ReturnCompletedTask); | ||
} | ||
|
||
[Fact] | ||
public void detects_chain_as_async_task_if_multiple_asyncs() | ||
{ | ||
theChain.Call<MainInput>(x => x.DoSync()); | ||
theChain.Call<MainInput>(x => x.TouchAsync()); | ||
theChain.Call<MainInput>(x => x.DifferentAsync()); | ||
|
||
theAsyncMode.ShouldBe(AsyncMode.AsyncTask); | ||
} | ||
|
||
[Fact] | ||
public void use_async_task_if_one_async_that_is_not_last() | ||
{ | ||
theChain.Call<MainInput>(x => x.DoSync()); | ||
theChain.Call<MainInput>(x => x.TouchAsync()); | ||
|
||
theAsyncMode.ShouldBe(AsyncMode.ReturnFromLastNode); | ||
} | ||
} | ||
} |
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,51 @@ | ||
using System.Threading.Tasks; | ||
using Baseline.Reflection; | ||
using Jasper.Codegen; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace Jasper.Testing.Codegen | ||
{ | ||
public class ReflectionExtensionsTester | ||
{ | ||
[Fact] | ||
public void not_async() | ||
{ | ||
ReflectionHelper.GetMethod<ReflectionExtensionsTester>(x => x.Go()) | ||
.IsAsync().ShouldBeFalse(); | ||
|
||
ReflectionHelper.GetMethod<ReflectionExtensionsTester>(x => x.IsTrue()) | ||
.IsAsync().ShouldBeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void is_async() | ||
{ | ||
ReflectionHelper.GetMethod<ReflectionExtensionsTester>(x => x.DoAsync()) | ||
.IsAsync().ShouldBeTrue(); | ||
|
||
ReflectionHelper.GetMethod<ReflectionExtensionsTester>(x => x.IsTrueAsync()) | ||
.IsAsync().ShouldBeTrue(); | ||
} | ||
|
||
public void Go() | ||
{ | ||
|
||
} | ||
|
||
public bool IsTrue() | ||
{ | ||
return true; | ||
} | ||
|
||
public Task DoAsync() | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task<bool> IsTrueAsync() | ||
{ | ||
return Task.FromResult(true); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/Jasper.Testing/Codegen/simple_method_calls_in_handler_chain.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,62 @@ | ||
using System.Threading.Tasks; | ||
using Jasper.Codegen; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace Jasper.Testing.Codegen | ||
{ | ||
public class simple_method_calls_in_handler_chain : CompilationContext | ||
{ | ||
[Fact] | ||
public async Task generate_with_async_handler() | ||
{ | ||
theChain.Call<MainInput>(x => x.TouchAsync()); | ||
|
||
var input = await afterRunning(); | ||
|
||
input.WasTouched.ShouldBeTrue(); | ||
|
||
theGeneratedCode.ShouldContain("public Task Handle("); | ||
} | ||
|
||
[Fact] | ||
public async Task generate_with_multiple_async_handler() | ||
{ | ||
theChain.Call<MainInput>(x => x.TouchAsync()); | ||
theChain.Call<MainInput>(x => x.DifferentAsync()); | ||
|
||
var input = await afterRunning(); | ||
|
||
input.WasTouched.ShouldBeTrue(); | ||
|
||
theGeneratedCode.ShouldContain("public async Task Handle("); | ||
} | ||
|
||
[Fact] | ||
public async Task generate_with_sync_handler() | ||
{ | ||
theChain.Call<MainInput>(x => x.Touch()); | ||
|
||
var input = await afterRunning(); | ||
|
||
input.WasTouched.ShouldBeTrue(); | ||
|
||
theGeneratedCode.ShouldContain("return Task.CompletedTask;"); | ||
} | ||
|
||
|
||
[Fact] | ||
public async Task generate_with_mixed_sync_and_async_handler() | ||
{ | ||
theChain.Call<MainInput>(x => x.DifferentAsync()); | ||
theChain.Call<MainInput>(x => x.Touch()); | ||
|
||
var input = await afterRunning(); | ||
|
||
input.WasTouched.ShouldBeTrue(); | ||
input.DifferentWasCalled.ShouldBeTrue(); | ||
} | ||
|
||
|
||
} | ||
} |
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
Oops, something went wrong.