Skip to content

Commit

Permalink
DefaultIfEmpty unit test cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
bartdesmet committed Feb 20, 2019
1 parent 1960d68 commit a6574c0
Showing 1 changed file with 64 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void DefaultIfEmpty_Null()
}

[Fact]
public async Task DefaultIfEmpty1()
public async Task DefaultIfEmpty_Empty()
{
var xs = AsyncEnumerable.Empty<int>().DefaultIfEmpty();

Expand All @@ -30,7 +30,7 @@ public async Task DefaultIfEmpty1()
}

[Fact]
public async Task DefaultIfEmpty2()
public async Task DefaultIfEmpty_Value_Empty()
{
var xs = AsyncEnumerable.Empty<int>().DefaultIfEmpty(42);

Expand All @@ -40,7 +40,7 @@ public async Task DefaultIfEmpty2()
}

[Fact]
public async Task DefaultIfEmpty3()
public async Task DefaultIfEmpty_Single()
{
var xs = Return42.DefaultIfEmpty();

Expand All @@ -50,7 +50,7 @@ public async Task DefaultIfEmpty3()
}

[Fact]
public async Task DefaultIfEmpty4()
public async Task DefaultIfEmpty_Value_Single()
{
var xs = Return42.DefaultIfEmpty(24);

Expand All @@ -60,7 +60,20 @@ public async Task DefaultIfEmpty4()
}

[Fact]
public async Task DefaultIfEmpty5()
public async Task DefaultIfEmpty_Many()
{
var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().Select(x => x).DefaultIfEmpty();

var e = xs.GetAsyncEnumerator();
await HasNextAsync(e, 1);
await HasNextAsync(e, 2);
await HasNextAsync(e, 3);
await HasNextAsync(e, 4);
await NoNextAsync(e);
}

[Fact]
public async Task DefaultIfEmpty_Many_IList()
{
var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().DefaultIfEmpty();

Expand All @@ -73,7 +86,20 @@ public async Task DefaultIfEmpty5()
}

[Fact]
public async Task DefaultIfEmpty6()
public async Task DefaultIfEmpty_Value_IList()
{
var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().Select(x => x).DefaultIfEmpty(24);

var e = xs.GetAsyncEnumerator();
await HasNextAsync(e, 1);
await HasNextAsync(e, 2);
await HasNextAsync(e, 3);
await HasNextAsync(e, 4);
await NoNextAsync(e);
}

[Fact]
public async Task DefaultIfEmpty_Value_Many_IList()
{
var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().DefaultIfEmpty(24);

Expand All @@ -86,7 +112,7 @@ public async Task DefaultIfEmpty6()
}

[Fact]
public async Task DefaultIfEmpty7Async()
public async Task DefaultIfEmpty_Throws_Source()
{
var ex = new Exception("Bang!");
var xs = Throw<int>(ex).DefaultIfEmpty();
Expand All @@ -96,7 +122,7 @@ public async Task DefaultIfEmpty7Async()
}

[Fact]
public async Task DefaultIfEmpty8Async()
public async Task DefaultIfEmpty_Value_Throws_Source()
{
var ex = new Exception("Bang!");
var xs = Throw<int>(ex).DefaultIfEmpty(24);
Expand All @@ -106,7 +132,7 @@ public async Task DefaultIfEmpty8Async()
}

[Fact]
public async Task DefaultIfEmpty9()
public async Task DefaultIfEmpty_IAsyncIListProvider_ToArray_Empty()
{
var xs = AsyncEnumerable.Empty<int>().DefaultIfEmpty(42);

Expand All @@ -116,7 +142,7 @@ public async Task DefaultIfEmpty9()
}

[Fact]
public async Task DefaultIfEmpty10()
public async Task DefaultIfEmpty_Value_IAsyncIListProvider_ToArray_Empty()
{
var xs = AsyncEnumerable.Empty<int>().DefaultIfEmpty(42);

Expand All @@ -126,44 +152,59 @@ public async Task DefaultIfEmpty10()
}

[Fact]
public async Task DefaultIfEmpty11()
public async Task DefaultIfEmpty_IAsyncIListProvider_ToList()
{
var xs = AsyncEnumerable.Empty<int>().DefaultIfEmpty(42);
var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().DefaultIfEmpty();

Assert.Equal(1, await xs.CountAsync());
}
var res = new[] { 1, 2, 3, 4 };

Assert.True(res.SequenceEqual(await xs.ToArrayAsync()));
}

[Fact]
public async Task DefaultIfEmpty12()
public async Task DefaultIfEmpty_Value_IAsyncIListProvider_ToList()
{
var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().DefaultIfEmpty(24);

var res = new[] { 1, 2, 3, 4 };
var res = new List<int> { 1, 2, 3, 4 };

Assert.True(res.SequenceEqual(await xs.ToArrayAsync()));
Assert.True(res.SequenceEqual(await xs.ToListAsync()));
}

[Fact]
public async Task DefaultIfEmpty13()
public async Task DefaultIfEmpty_IAsyncIListProvider_Count_Empty()
{
var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().DefaultIfEmpty(24);
var xs = AsyncEnumerable.Empty<int>().DefaultIfEmpty(42);

var res = new List<int> { 1, 2, 3, 4 };
Assert.Equal(1, await xs.CountAsync());
}

Assert.True(res.SequenceEqual(await xs.ToListAsync()));
[Fact]
public async Task DefaultIfEmpty_Value_IAsyncIListProvider_Count()
{
var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().Where(x => x > 0).DefaultIfEmpty(24);

Assert.Equal(4, await xs.CountAsync());
}

[Fact]
public async Task DefaultIfEmpty_Value_IAsyncIListProvider_Count_IAsyncIListProvider()
{
var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().Select(x => x).DefaultIfEmpty(24);

Assert.Equal(4, await xs.CountAsync());
}

[Fact]
public async Task DefaultIfEmpty14()
public async Task DefaultIfEmpty_Value_IAsyncIListProvider_Count_IList()
{
var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().DefaultIfEmpty(24);

Assert.Equal(4, await xs.CountAsync());
}

[Fact]
public async Task DefaultIfEmpty15()
public async Task DefaultIfEmpty_SequenceIdentity()
{
var xs = new[] { 1, 2, 3, 4 }.ToAsyncEnumerable().DefaultIfEmpty(24);

Expand Down

0 comments on commit a6574c0

Please sign in to comment.