Skip to content

Commit b9c589c

Browse files
committed
Added task support
1 parent 3d46957 commit b9c589c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/DotNext.Tests/ResultTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,20 @@ public static void ResultToDelegate()
225225
private static TResult FromError<TError, TResult>(TError error)
226226
where TResult : struct, IResultMonad<int, TError, TResult>
227227
=> TResult.FromError(error);
228+
229+
[Fact]
230+
public static async Task ConvertToTask()
231+
{
232+
Result<int> result = 42;
233+
var task = (Task<int>)result;
234+
Equal(42, await task);
235+
236+
result = Result.FromException<int>(new OperationCanceledException(new CancellationToken(canceled: true)));
237+
task = (Task<int>)result;
238+
True(task.IsCanceled);
239+
240+
result = Result.FromException<int>(new Exception());
241+
task = (Task<int>)result;
242+
await ThrowsAsync<Exception>(Func.Constant(task));
243+
}
228244
}

0 commit comments

Comments
 (0)