You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
abp/test/Volo.Abp.Tests/Volo/Abp/Threading/AsyncHelper_Tests.cs

60 lines
1.5 KiB

using System.Reflection;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Shouldly;
using Xunit;
namespace Volo.Abp.Threading
{
public class AsyncHelper_Tests
{
[Fact]
public void RunSync_Test_Without_Return_Value()
{
AsyncHelper.RunSync(MyTaskWithoutReturnValueAsync);
}
[Fact]
public void RunSync_Test_With_Return_Value()
{
AsyncHelper.RunSync(() => MyTaskWithReturnValueAsync(42)).ShouldBe(42);
}
[Fact]
public void IsAsync_Should_Work()
{
GetType().GetMethod(
"MyTaskWithoutReturnValueAsync",
BindingFlags.NonPublic | BindingFlags.Static
).IsAsync().ShouldBe(true);
GetType().GetMethod(
"MyTaskWithReturnValueAsync",
BindingFlags.NonPublic | BindingFlags.Static
).IsAsync().ShouldBe(true);
GetType().GetMethod(
"MyTaskWithReturnValue2",
BindingFlags.NonPublic | BindingFlags.Instance
).IsAsync().ShouldBe(false);
}
private static async Task MyTaskWithoutReturnValueAsync()
{
await Task.Delay(1);
}
private static async Task<int> MyTaskWithReturnValueAsync(int aNumber)
{
await Task.Delay(1);
return aNumber;
}
[UsedImplicitly]
private int MyTaskWithReturnValue2(int aNumber)
{
return aNumber;
}
}
}