Permalink
Browse files

TaskSample - OneItemMatchesSyncReturns

  • Loading branch information...
bobbymcr committed May 23, 2018
1 parent 1aa7d15 commit 26d57846f14f3b9d2c3724217de1fb059033eee0

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,20 @@
// <copyright file="FuncTaskExtensions.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>
namespace TaskSample.Extensions
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
public static class FuncTaskExtensions
{
public static Task<T> FirstAsync<T>(this IEnumerable<Func<CancellationToken, Task<T>>> funcs, Predicate<T> pred)
{
return funcs.First()(CancellationToken.None);
}
}
}

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,31 @@
// <copyright file="FirstAsyncTest.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>
namespace TaskSample.Test
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using TaskSample.Extensions;
using Xunit;
public class FirstAsyncTest
{
[Fact]
public void OneItemMatchesSyncReturns()
{
IEnumerable<Func<CancellationToken, Task<string>>> funcs = new Func<CancellationToken, Task<string>>[]
{
t => Task.FromResult("good")
};
Task<string> task = funcs.FirstAsync(r => true);
task.IsCompletedSuccessfully.Should().BeTrue();
task.Result.Should().Be("good");
}
}
}

0 comments on commit 26d5784

Please sign in to comment.