Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Source/MorseCode.ITask/MorseCode.ITask.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">--------------------------------------------------------------------------------------------------------------------&#xD;
&lt;copyright file="$FILENAME$" company="MorseCode Software"&gt;&#xD;
Copyright (c) $CURRENT_YEAR$ MorseCode Software&#xD;
&lt;copyright file="${File.FileName}" company="MorseCode Software"&gt;&#xD;
Copyright (c) ${CurrentDate.Year} MorseCode Software&#xD;
&lt;/copyright&gt;&#xD;
&lt;summary&gt;&#xD;
The MIT License (MIT)&#xD;
&#xD;
Copyright (c) $CURRENT_YEAR$ MorseCode Software&#xD;
Copyright (c) ${CurrentDate.Year} MorseCode Software&#xD;
&#xD;
Permission is hereby granted, free of charge, to any person obtaining a copy&#xD;
of this software and associated documentation files (the "Software"), to deal&#xD;
Expand All @@ -27,4 +27,5 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE&#x
SOFTWARE.&#xD;
&lt;/summary&gt;&#xD;
--------------------------------------------------------------------------------------------------------------------</s:String>
<s:Int64 x:Key="/Default/Environment/SearchAndNavigation/DefaultOccurencesGroupingIndex/@EntryValue">6</s:Int64></wpf:ResourceDictionary>
<s:Int64 x:Key="/Default/Environment/SearchAndNavigation/DefaultOccurencesGroupingIndex/@EntryValue">6</s:Int64>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EFeature_002EServices_002ECodeCleanup_002EFileHeader_002EFileHeaderSettingsMigrate/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
171 changes: 170 additions & 1 deletion Source/MorseCode.ITask/Tests/TaskInterfaceAsyncMethodBuilderTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using NUnit.Framework;
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework.Legacy;

namespace MorseCode.ITask.Tests
{
[TestFixture]
public class TaskInterfaceAsyncMethodBuilderTests
{
private const string StackTraceRedactionPattern = "\\w__[\\w_]+(?=[()<>.])|(?<=\\(\\)) in [^\r\n]+";

[Test]
public async Task TaskInterfaceAsyncMethodBuilderTask()
{
Expand All @@ -18,6 +23,88 @@ async ITask TaskInterfaceAsyncMethodBuilderTaskMethodAsync()
await Task.Delay(50).ConfigureAwait(false);
}

[Test]
[SetUICulture("")]
public void TaskInterfaceAsyncMethodBuilderTaskWithException()
{
var exception = Assert.ThrowsAsync<Exception>(async () =>
await TaskInterfaceAsyncMethodBuilderTaskWithExceptionMethodAsync().ConfigureAwait(false));
Assert.AreEqual("Test-Case Exception", exception.Message);
var redactedStackTrace = Regex.Replace(exception.StackTrace, StackTraceRedactionPattern, "");
#if NET6_0_OR_GREATER
Assert.AreEqual(
"""
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.TaskInterfaceAsyncMethodBuilderTaskWithExceptionMethodAsync()
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.<TaskInterfaceAsyncMethodBuilderTaskWithException>()
at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter)
at NUnit.Framework.Internal.AsyncToSyncAdapter.Await[TResult](TestExecutionContext context, Func`1 invoke)
at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(TestExecutionContext context, Func`1 invoke)
at NUnit.Framework.Assert.ThrowsAsync(IResolveConstraint expression, AsyncTestDelegate code, String message, Object[] args)
""",
redactedStackTrace);
#else
StringAssert.StartsWith(
"""
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.<TaskInterfaceAsyncMethodBuilderTaskWithExceptionMethodAsync>.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
at MorseCode.ITask.ConfiguredTaskAwaiterWrapper.MorseCode.ITask.IAwaiter.GetResult()
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.<<TaskInterfaceAsyncMethodBuilderTaskWithException>>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
""",
redactedStackTrace);
#endif
}

[Test]
[SetUICulture("")]
public void TaskInterfaceAsyncMethodBuilderTaskWithExceptionNoConfigure()
{
var exception = Assert.ThrowsAsync<Exception>(async () =>
await TaskInterfaceAsyncMethodBuilderTaskWithExceptionMethodAsync());
Assert.AreEqual("Test-Case Exception", exception.Message);
var redactedStackTrace = Regex.Replace(exception.StackTrace, StackTraceRedactionPattern, "");
#if NET6_0_OR_GREATER
Assert.AreEqual(
"""
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.TaskInterfaceAsyncMethodBuilderTaskWithExceptionMethodAsync()
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.<TaskInterfaceAsyncMethodBuilderTaskWithExceptionNoConfigure>()
at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter)
at NUnit.Framework.Internal.AsyncToSyncAdapter.Await[TResult](TestExecutionContext context, Func`1 invoke)
at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(TestExecutionContext context, Func`1 invoke)
at NUnit.Framework.Assert.ThrowsAsync(IResolveConstraint expression, AsyncTestDelegate code, String message, Object[] args)
""",
redactedStackTrace);
#else
StringAssert.StartsWith(
"""
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.<TaskInterfaceAsyncMethodBuilderTaskWithExceptionMethodAsync>.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at MorseCode.ITask.TaskAwaiterWrapper.MorseCode.ITask.IAwaiter.GetResult()
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.<<TaskInterfaceAsyncMethodBuilderTaskWithExceptionNoConfigure>>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
""",
redactedStackTrace);
#endif
}

async ITask TaskInterfaceAsyncMethodBuilderTaskWithExceptionMethodAsync()
{
await Task.Delay(50).ConfigureAwait(false);
throw new Exception("Test-Case Exception");
}

[Test]
public async Task TaskInterfaceAsyncMethodBuilderResultTask()
{
Expand All @@ -35,5 +122,87 @@ async ITask<int> TaskInterfaceAsyncMethodBuilderResultTaskMethodAsync()
}));
return results.Length;
}

[Test]
[SetUICulture("")]
public void TaskInterfaceAsyncMethodBuilderResultTaskWithException()
{
var exception = Assert.ThrowsAsync<Exception>(async () =>
await TaskInterfaceAsyncMethodBuilderResultTaskWithExceptionMethodAsync().ConfigureAwait(false));
Assert.AreEqual("Test-Case Exception", exception.Message);
var redactedStackTrace = Regex.Replace(exception.StackTrace, StackTraceRedactionPattern, "");
#if NET6_0_OR_GREATER
Assert.AreEqual(
"""
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.TaskInterfaceAsyncMethodBuilderResultTaskWithExceptionMethodAsync()
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.<TaskInterfaceAsyncMethodBuilderResultTaskWithException>()
at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter)
at NUnit.Framework.Internal.AsyncToSyncAdapter.Await[TResult](TestExecutionContext context, Func`1 invoke)
at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(TestExecutionContext context, Func`1 invoke)
at NUnit.Framework.Assert.ThrowsAsync(IResolveConstraint expression, AsyncTestDelegate code, String message, Object[] args)
""",
redactedStackTrace);
#else
StringAssert.StartsWith(
"""
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.<TaskInterfaceAsyncMethodBuilderResultTaskWithExceptionMethodAsync>.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at MorseCode.ITask.ConfiguredTaskAwaiterWrapper`1.MorseCode.ITask.IAwaiter<TResult>.GetResult()
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.<<TaskInterfaceAsyncMethodBuilderResultTaskWithException>>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
""",
redactedStackTrace);
#endif
}

[Test]
[SetUICulture("")]
public void TaskInterfaceAsyncMethodBuilderResultTaskWithExceptionNoConfigure()
{
var exception = Assert.ThrowsAsync<Exception>(async () =>
await TaskInterfaceAsyncMethodBuilderResultTaskWithExceptionMethodAsync());
Assert.AreEqual("Test-Case Exception", exception.Message);
var redactedStackTrace = Regex.Replace(exception.StackTrace, StackTraceRedactionPattern, "");
#if NET6_0_OR_GREATER
Assert.AreEqual(
"""
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.TaskInterfaceAsyncMethodBuilderResultTaskWithExceptionMethodAsync()
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.<TaskInterfaceAsyncMethodBuilderResultTaskWithExceptionNoConfigure>()
at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
at NUnit.Framework.Internal.MessagePumpStrategy.NoMessagePumpStrategy.WaitForCompletion(AwaitAdapter awaiter)
at NUnit.Framework.Internal.AsyncToSyncAdapter.Await[TResult](TestExecutionContext context, Func`1 invoke)
at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(TestExecutionContext context, Func`1 invoke)
at NUnit.Framework.Assert.ThrowsAsync(IResolveConstraint expression, AsyncTestDelegate code, String message, Object[] args)
""",
redactedStackTrace);
#else
StringAssert.StartsWith(
"""
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.<TaskInterfaceAsyncMethodBuilderResultTaskWithExceptionMethodAsync>.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at MorseCode.ITask.TaskAwaiterWrapper`1.MorseCode.ITask.IAwaiter<TResult>.GetResult()
at MorseCode.ITask.Tests.TaskInterfaceAsyncMethodBuilderTests.<<TaskInterfaceAsyncMethodBuilderResultTaskWithExceptionNoConfigure>>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
""",
redactedStackTrace);
#endif
}

async ITask<int> TaskInterfaceAsyncMethodBuilderResultTaskWithExceptionMethodAsync()
{
await Task.Delay(50).ConfigureAwait(false);
throw new Exception("Test-Case Exception");
}
}
}
18 changes: 11 additions & 7 deletions Source/MorseCode.ITask/Tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp1.0;netcoreapp2.0;net45</TargetFrameworks>
<TargetFrameworks>net8.0;net10.0;net462</TargetFrameworks>
<AssemblyName>MorseCode.ITask.Tests</AssemblyName>
<RootNamespace>MorseCode.ITask.Tests</RootNamespace>
<LangVersion>14</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -12,12 +13,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coveralls.io" Version="1.4.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="NUnit.Console" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="OpenCover" Version="4.6.519" />
<PackageReference Include="coverlet.collector" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="NUnit" Version="4.5.1" />
<PackageReference Include="NUnit.Console" Version="3.22.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.1.0" />
<PackageReference Include="OpenCover" Version="4.7.1221" />
</ItemGroup>

<ItemGroup>
Expand Down
28 changes: 15 additions & 13 deletions Source/MorseCode.ITask/_Root/AsyncMethodBuilderAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
namespace System.Runtime.CompilerServices
{
sealed class AsyncMethodBuilderAttribute : Attribute
{
public Type BuilderType { get; }

public AsyncMethodBuilderAttribute(
Type builderType)
{
BuilderType = builderType;
}
}
}
#if !NETSTANDARD2_1_OR_GREATER && !NETCOREAPP1_1_OR_GREATER
namespace System.Runtime.CompilerServices
{
sealed class AsyncMethodBuilderAttribute : Attribute
{
public Type BuilderType { get; }

public AsyncMethodBuilderAttribute(
Type builderType)
{
BuilderType = builderType;
}
}
}
#endif
3 changes: 3 additions & 0 deletions Source/MorseCode.ITask/_Root/AwaiterInterfaceWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public void UnsafeOnCompleted(Action continuation)
/// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
/// <exception cref="System.Threading.Tasks.TaskCanceledException">The task was canceled.</exception>
/// <exception cref="System.Exception">The task completed in a Faulted state.</exception>
#if NET6_0_OR_GREATER
[System.Diagnostics.StackTraceHidden]
#endif
public void GetResult()
{
this.awaiter.GetResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public void UnsafeOnCompleted(Action continuation)
/// <exception cref="System.NullReferenceException">The awaiter was not properly initialized.</exception>
/// <exception cref="System.Threading.Tasks.TaskCanceledException">The task was canceled.</exception>
/// <exception cref="System.Exception">The task completed in a Faulted state.</exception>
#if NET6_0_OR_GREATER
[System.Diagnostics.StackTraceHidden]
#endif
public TResult GetResult()
{
return this.awaiter.GetResult();
Expand Down
3 changes: 3 additions & 0 deletions Source/MorseCode.ITask/_Root/ConfiguredTaskAwaiterWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ void ICriticalNotifyCompletion.UnsafeOnCompleted(Action continuation)
this.taskAwaiter.UnsafeOnCompleted(continuation);
}

#if NET6_0_OR_GREATER
[System.Diagnostics.StackTraceHidden]
#endif
void IAwaiter.GetResult()
{
this.taskAwaiter.GetResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ void ICriticalNotifyCompletion.UnsafeOnCompleted(Action continuation)
this.taskAwaiter.UnsafeOnCompleted(continuation);
}

#if NET6_0_OR_GREATER
[System.Diagnostics.StackTraceHidden]
#endif
TResult IAwaiter<TResult>.GetResult()
{
return this.taskAwaiter.GetResult();
Expand Down
3 changes: 3 additions & 0 deletions Source/MorseCode.ITask/_Root/TaskAwaiterWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ void ICriticalNotifyCompletion.UnsafeOnCompleted(Action continuation)
this.taskAwaiter.UnsafeOnCompleted(continuation);
}

#if NET6_0_OR_GREATER
[System.Diagnostics.StackTraceHidden]
#endif
void IAwaiter.GetResult()
{
this.taskAwaiter.GetResult();
Expand Down
3 changes: 3 additions & 0 deletions Source/MorseCode.ITask/_Root/TaskAwaiterWrapper{TResult}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ void ICriticalNotifyCompletion.UnsafeOnCompleted(Action continuation)
this.taskAwaiter.UnsafeOnCompleted(continuation);
}

#if NET6_0_OR_GREATER
[System.Diagnostics.StackTraceHidden]
#endif
TResult IAwaiter<TResult>.GetResult()
{
return this.taskAwaiter.GetResult();
Expand Down
Loading