Skip to content

Commit

Permalink
The Big Rename to avoid ambiguity between sync/async/cancellable over…
Browse files Browse the repository at this point in the history
…loads of operators.
  • Loading branch information
bartdesmet committed Feb 26, 2019
1 parent d2b8eea commit f2ce04b
Show file tree
Hide file tree
Showing 70 changed files with 5,396 additions and 5,320 deletions.
2,086 changes: 1,043 additions & 1,043 deletions Ix.NET/Source/System.Linq.Async.Queryable.Tests/AsyncQueryableTests.Generated.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@
</None>
</ItemGroup>

<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>

</Project>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<#@ output extension=".cs" #>
<#
var nullableParameterNames = new[] { "comparer" };
var exclude = new[] { "ForEach", "ForEachAsync", "ToEnumerable", "ToAsyncEnumerable", "ToObservable", "AsAsyncEnumerable", "WithCancellation" };
var exclude = new[] { "ForEachAsync", "ForEachAwaitAsync", "ForEachAwaitWithCancellationAsync", "ToEnumerable", "ToAsyncEnumerable", "ToObservable", "AsAsyncEnumerable", "WithCancellation" };

var toQuotedImpl = default(Func<Type, int, bool, string>);
toQuotedImpl = (t, i, b) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using System;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Xunit;

namespace Tests
{
public class AsyncEnumerableNamingTests
{
[Fact]
public static void AsyncEnumerable_MethodNames()
{
var methods = typeof(AsyncEnumerable).GetMethods(BindingFlags.Public | BindingFlags.Static);

//
// Async suffix
//

var asyncMethodsNoAsyncSuffix = (from m in methods
where IsTaskLike(m.ReturnType)
where !m.Name.EndsWith("Async")
select m.Name)
.ToArray();

Assert.Empty(asyncMethodsNoAsyncSuffix);

//
// Consistency of delegate types and Await[WithCancellation] naming convention
//

var methodsWithDelegateParameter = (from m in methods
where m.GetParameters().Any(p => IsAsyncDelegate(p.ParameterType))
select m)
.ToArray();

foreach (var m in methodsWithDelegateParameter)
{
var kinds = (from p in m.GetParameters()
where IsDelegate(p.ParameterType)
select GetDelegateKind(p.ParameterType))
.Distinct();

Assert.Single(kinds);

var suffix = IsTaskLike(m.ReturnType) ? "Async" : "";

switch (kinds.Single())
{
case DelegateKind.Async:
suffix = "Await" + suffix;
break;
case DelegateKind.AsyncCancel:
suffix = "AwaitWithCancellation" + suffix;
break;
}

Assert.EndsWith(suffix, m.Name);
}

static bool IsValueTask(Type t) => t == typeof(ValueTask) || (t.IsConstructedGenericType && t.GetGenericTypeDefinition() == typeof(ValueTask<>));
static bool IsTask(Type t) => typeof(Task).IsAssignableFrom(t);
static bool IsTaskLike(Type t) => IsTask(t) || IsValueTask(t);

static bool IsDelegate(Type t) => typeof(Delegate).IsAssignableFrom(t);
static bool TryGetInvoke(Type t, out MethodInfo m) => (m = t.GetMethod("Invoke")) != null;
static bool IsAsyncDelegate(Type t) => IsDelegate(t) && TryGetInvoke(t, out var i) && IsTaskLike(i.ReturnType);
static bool IsCancelableDelegate(Type t) => IsDelegate(t) && TryGetInvoke(t, out var i) && i.GetParameters().LastOrDefault()?.ParameterType == typeof(CancellationToken);
static DelegateKind GetDelegateKind(Type t) => IsAsyncDelegate(t) ? (IsCancelableDelegate(t) ? DelegateKind.AsyncCancel : DelegateKind.Async) : DelegateKind.Sync;
}

private enum DelegateKind
{
Sync,
Async,
AsyncCancel,
}
}
}
200 changes: 100 additions & 100 deletions Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/Aggregate.cs

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions Ix.NET/Source/System.Linq.Async.Tests/System/Linq/Operators/All.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,123 +13,123 @@ namespace Tests
public class All : AsyncEnumerableTests
{
[Fact]
public async Task AllAsync_Sync_Null()
public async Task AllAsync_Null()
{
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAsync<int>(default, x => true).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAsync(Return42, default(Func<int, bool>)).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAsync(Return42, default).AsTask());

await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAsync<int>(default, x => true, CancellationToken.None).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAsync(Return42, default(Func<int, bool>), CancellationToken.None).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAsync(Return42, default, CancellationToken.None).AsTask());
}

[Fact]
public async Task AllAsync_Sync_Simple_False()
public async Task AllAsync_Simple_False()
{
var res = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().AllAsync(x => x % 2 == 0);
Assert.False(await res);
}

[Fact]
public async Task AllAsync_Sync_Simple_True()
public async Task AllAsync_Simple_True()
{
var res = new[] { 2, 8, 4 }.ToAsyncEnumerable().AllAsync(x => x % 2 == 0);
Assert.True(await res);
}

[Fact]
public async Task AllAsync_Sync_Throw_Source()
public async Task AllAsync_Throw_Source()
{
var ex = new Exception("Bang!");
var res = Throw<int>(ex).AllAsync(x => x % 2 == 0);
await AssertThrowsAsync(res, ex);
}

[Fact]
public async Task AllAsync_Sync_Throw_Selector()
public async Task AllAsync_Throw_Selector()
{
var ex = new Exception("Bang!");
var res = new[] { 2, 8, 4 }.ToAsyncEnumerable().AllAsync(new Func<int, bool>(x => { throw ex; }));
await AssertThrowsAsync(res, ex);
}

[Fact]
public async Task AllAsync_Async_Null()
public async Task AllAwaitAsync_Null()
{
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAsync<int>(default, x => new ValueTask<bool>(true)).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAsync(Return42, default(Func<int, ValueTask<bool>>)).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAwaitAsync<int>(default, x => new ValueTask<bool>(true)).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAwaitAsync(Return42, default).AsTask());

await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAsync<int>(default, x => new ValueTask<bool>(true), CancellationToken.None).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAsync(Return42, default(Func<int, ValueTask<bool>>), CancellationToken.None).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAwaitAsync<int>(default, x => new ValueTask<bool>(true), CancellationToken.None).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAwaitAsync(Return42, default, CancellationToken.None).AsTask());
}

[Fact]
public async Task AllAsync_Async_Simple_False()
public async Task AllAwaitAsync_Simple_False()
{
var res = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().AllAsync(x => new ValueTask<bool>(x % 2 == 0));
var res = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().AllAwaitAsync(x => new ValueTask<bool>(x % 2 == 0));
Assert.False(await res);
}

[Fact]
public async Task AllAsync_Async_Simple_True()
public async Task AllAwaitAsync_Simple_True()
{
var res = new[] { 2, 8, 4 }.ToAsyncEnumerable().AllAsync(x => new ValueTask<bool>(x % 2 == 0));
var res = new[] { 2, 8, 4 }.ToAsyncEnumerable().AllAwaitAsync(x => new ValueTask<bool>(x % 2 == 0));
Assert.True(await res);
}

[Fact]
public async Task AllAsync_Async_Throw_Source()
public async Task AllAwaitAsync_Throw_Source()
{
var ex = new Exception("Bang!");
var res = Throw<int>(ex).AllAsync(x => new ValueTask<bool>(x % 2 == 0));
var res = Throw<int>(ex).AllAwaitAsync(x => new ValueTask<bool>(x % 2 == 0));
await AssertThrowsAsync(res, ex);
}

[Fact]
public async Task AllAsync_Async_Throw_Selector()
public async Task AllAwaitAsync_Throw_Selector()
{
var ex = new Exception("Bang!");
var res = new[] { 2, 8, 4 }.ToAsyncEnumerable().AllAsync(new Func<int, ValueTask<bool>>(x => { throw ex; }));
var res = new[] { 2, 8, 4 }.ToAsyncEnumerable().AllAwaitAsync(new Func<int, ValueTask<bool>>(x => { throw ex; }));
await AssertThrowsAsync(res, ex);
}

#if !NO_DEEP_CANCELLATION
[Fact]
public async Task AllAsync_AsyncCancel_Null()
public async Task AllAwaitWithCancellationAsync_Null()
{
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAsync<int>(default, (x, ct) => new ValueTask<bool>(true)).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAsync(Return42, default(Func<int, CancellationToken, ValueTask<bool>>)).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAwaitWithCancellationAsync<int>(default, (x, ct) => new ValueTask<bool>(true)).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAwaitWithCancellationAsync(Return42, default).AsTask());

await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAsync<int>(default, (x, ct) => new ValueTask<bool>(true), CancellationToken.None).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAsync(Return42, default(Func<int, CancellationToken, ValueTask<bool>>), CancellationToken.None).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAwaitWithCancellationAsync<int>(default, (x, ct) => new ValueTask<bool>(true), CancellationToken.None).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.AllAwaitWithCancellationAsync(Return42, default, CancellationToken.None).AsTask());
}

[Fact]
public async Task AllAsync_AsyncCancel_Simple_False()
public async Task AllAwaitWithCancellationAsync_Simple_False()
{
var res = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().AllAsync((x, ct) => new ValueTask<bool>(x % 2 == 0));
var res = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().AllAwaitWithCancellationAsync((x, ct) => new ValueTask<bool>(x % 2 == 0));
Assert.False(await res);
}

[Fact]
public async Task AllAsync_AsyncCancel_Simple_True()
public async Task AllAwaitWithCancellationAsync_Simple_True()
{
var res = new[] { 2, 8, 4 }.ToAsyncEnumerable().AllAsync((x, ct) => new ValueTask<bool>(x % 2 == 0));
var res = new[] { 2, 8, 4 }.ToAsyncEnumerable().AllAwaitWithCancellationAsync((x, ct) => new ValueTask<bool>(x % 2 == 0));
Assert.True(await res);
}

[Fact]
public async Task AllAsync_AsyncCancel_Throw_Source()
public async Task AllAwaitWithCancellationAsync_Throw_Source()
{
var ex = new Exception("Bang!");
var res = Throw<int>(ex).AllAsync((x, ct) => new ValueTask<bool>(x % 2 == 0));
var res = Throw<int>(ex).AllAwaitWithCancellationAsync((x, ct) => new ValueTask<bool>(x % 2 == 0));
await AssertThrowsAsync(res, ex);
}

[Fact]
public async Task AllAsync_AsyncCancel_Throw_Selector()
public async Task AllAwaitWithCancellationAsync_Throw_Selector()
{
var ex = new Exception("Bang!");
var res = new[] { 2, 8, 4 }.ToAsyncEnumerable().AllAsync(new Func<int, CancellationToken, ValueTask<bool>>((x, ct) => { throw ex; }));
var res = new[] { 2, 8, 4 }.ToAsyncEnumerable().AllAwaitWithCancellationAsync(new Func<int, CancellationToken, ValueTask<bool>>((x, ct) => { throw ex; }));
await AssertThrowsAsync(res, ex);
}
#endif
Expand Down
Loading

0 comments on commit f2ce04b

Please sign in to comment.