diff --git a/src/Volo.Abp/Volo/Abp/Threading/AsyncHelper.cs b/src/Volo.Abp/Volo/Abp/Threading/AsyncHelper.cs
index 7ce2e52109..a63d7704c2 100644
--- a/src/Volo.Abp/Volo/Abp/Threading/AsyncHelper.cs
+++ b/src/Volo.Abp/Volo/Abp/Threading/AsyncHelper.cs
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using System.Threading.Tasks;
+using JetBrains.Annotations;
using Nito.AsyncEx;
namespace Volo.Abp.Threading
@@ -14,7 +15,7 @@ namespace Volo.Abp.Threading
/// Checks if given method is an async method.
///
/// A method to check
- public static bool IsAsyncMethod(MethodInfo method)
+ public static bool IsAsyncMethod([NotNull] this MethodInfo method)
{
return method.ReturnType == typeof(Task) ||
(method.ReturnType.GetTypeInfo().IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task<>));
diff --git a/test/Volo.Abp.Tests/Volo/Abp/Threading/AsyncHelper_Tests.cs b/test/Volo.Abp.Tests/Volo/Abp/Threading/AsyncHelper_Tests.cs
index 69ec91a0cc..bc64357509 100644
--- a/test/Volo.Abp.Tests/Volo/Abp/Threading/AsyncHelper_Tests.cs
+++ b/test/Volo.Abp.Tests/Volo/Abp/Threading/AsyncHelper_Tests.cs
@@ -1,4 +1,6 @@
-using System.Threading.Tasks;
+using System.Reflection;
+using System.Threading.Tasks;
+using JetBrains.Annotations;
using Shouldly;
using Xunit;
@@ -9,24 +11,49 @@ namespace Volo.Abp.Threading
[Fact]
public void RunSync_Test_Without_Return_Value()
{
- AsyncHelper.RunSync(MyTaskWithoutReturnValue);
+ AsyncHelper.RunSync(MyTaskWithoutReturnValueAsync);
}
[Fact]
public void RunSync_Test_With_Return_Value()
{
- AsyncHelper.RunSync(() => MyTaskWithReturnValue(42)).ShouldBe(42);
+ AsyncHelper.RunSync(() => MyTaskWithReturnValueAsync(42)).ShouldBe(42);
}
- private static async Task MyTaskWithoutReturnValue()
+ [Fact]
+ public void IsAsync_Should_Work()
+ {
+ GetType().GetMethod(
+ "MyTaskWithoutReturnValueAsync",
+ BindingFlags.NonPublic | BindingFlags.Static
+ ).IsAsyncMethod().ShouldBe(true);
+
+ GetType().GetMethod(
+ "MyTaskWithReturnValueAsync",
+ BindingFlags.NonPublic | BindingFlags.Static
+ ).IsAsyncMethod().ShouldBe(true);
+
+ GetType().GetMethod(
+ "MyTaskWithReturnValue2",
+ BindingFlags.NonPublic | BindingFlags.Instance
+ ).IsAsyncMethod().ShouldBe(false);
+ }
+
+ private static async Task MyTaskWithoutReturnValueAsync()
{
await Task.Delay(1);
}
- private static async Task MyTaskWithReturnValue(int aNumber)
+ private static async Task MyTaskWithReturnValueAsync(int aNumber)
{
await Task.Delay(1);
return aNumber;
}
+
+ [UsedImplicitly]
+ private int MyTaskWithReturnValue2(int aNumber)
+ {
+ return aNumber;
+ }
}
}