Skip to content

Commit 27dc54f

Browse files
committed
Added ConfigureAwait(false) (#169)
1 parent 7565965 commit 27dc54f

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/MyTested.AspNetCore.Mvc.Core/Builders/Controllers/ControllerActionCallBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public IActionResultTestBuilder<TActionResult> Calling<TActionResult>(Expression
4343
{
4444
var actionInfo = this.GetAndValidateActionResult(actionCall);
4545
var actionResult = default(TActionResult);
46+
actionInfo.ActionResult.ConfigureAwait(false);
4647

4748
try
4849
{
@@ -86,6 +87,7 @@ public IVoidActionResultTestBuilder Calling(Expression<Action<TController>> acti
8687
public IVoidActionResultTestBuilder Calling(Expression<Func<TController, Task>> actionCall)
8788
{
8889
var actionInfo = this.GetAndValidateActionResult(actionCall);
90+
actionInfo.ActionResult.ConfigureAwait(false);
8991

9092
try
9193
{

src/MyTested.AspNetCore.Mvc.Core/Internal/Formatters/FormattersHelper.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ public static TModel ReadFromStream<TModel>(Stream stream, string contentType, E
5454
return formatter;
5555
});
5656

57-
var result = AsyncHelper.RunSync(() => inputFormatter.ReadAsync(inputFormatterContext)).Model;
57+
var task = inputFormatter.ReadAsync(inputFormatterContext);
58+
task.ConfigureAwait(false);
59+
60+
var result = AsyncHelper.RunSync(() => task).Model;
5861

5962
try
6063
{
@@ -91,7 +94,10 @@ public static Stream WriteToStream<TBody>(TBody value, string contentType, Encod
9194
return formatter;
9295
});
9396

94-
AsyncHelper.RunSync(() => outputFormatter.WriteAsync(outputFormatterCanWriteContext));
97+
var task = outputFormatter.WriteAsync(outputFormatterCanWriteContext);
98+
task.ConfigureAwait(false);
99+
100+
AsyncHelper.RunSync(() => task);
95101

96102
// copy memory stream because formatters close the original one
97103
return new MemoryStream(((MemoryStream)httpContext.Response.Body).ToArray());

src/MyTested.AspNetCore.Mvc.Core/Internal/Routes/InternalRouteResolver.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ public static ResolvedRouteContext Resolve(IServiceProvider services, IRouter ro
8383

8484
try
8585
{
86-
AsyncHelper.RunSync(() => modelBindingActionInvoker.InvokeAsync());
86+
var task = modelBindingActionInvoker.InvokeAsync();
87+
task.ConfigureAwait(false);
88+
AsyncHelper.RunSync(() => task);
8789
}
8890
catch (Exception ex)
8991
{
@@ -117,7 +119,10 @@ public static RouteData ResolveRouteData(IRouter router, RouteContext routeConte
117119
return null;
118120
}
119121

120-
AsyncHelper.RunSync(() => router.RouteAsync(routeContext));
122+
var task = router.RouteAsync(routeContext);
123+
task.ConfigureAwait(false);
124+
125+
AsyncHelper.RunSync(() => task);
121126

122127
var routeData = routeContext.RouteData;
123128
routeContext.HttpContext.SetRouteData(routeData);

0 commit comments

Comments
 (0)