-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #328 from atc-net/feature/IEnumerable-extensions
Feature/i enumerable extensions
- Loading branch information
Showing
11 changed files
with
290 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<div style='text-align: right'> | ||
|
||
[References](Index.md) - [References extended](IndexExtended.md) | ||
</div> | ||
|
||
# Atc.Factories | ||
|
||
<br /> | ||
|
||
## AsyncEnumerableFactory | ||
Provides factory methods for creating instances of `System.Collections.Generic.IAsyncEnumerable`1`. | ||
|
||
>```csharp | ||
>public static class AsyncEnumerableFactory | ||
>``` | ||
### Static Methods | ||
#### EmptyAsyncEnumerable | ||
>```csharp | ||
>IAsyncEnumerable<T> EmptyAsyncEnumerable() | ||
>``` | ||
><b>Summary:</b> Returns an empty `System.Collections.Generic.IAsyncEnumerable`1`. | ||
> | ||
><b>Returns:</b> An empty `System.Collections.Generic.IAsyncEnumerable`1`. | ||
<hr /><div style='text-align: right'><i>Generated by MarkdownCodeDoc version 1.2</i></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Atc.Factories; | ||
|
||
/// <summary> | ||
/// Provides factory methods for creating instances of <see cref="IAsyncEnumerable{T}"/>. | ||
/// </summary> | ||
public static class AsyncEnumerableFactory | ||
{ | ||
/// <summary> | ||
/// Returns an empty <see cref="IAsyncEnumerable{T}"/>. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the elements in the sequence.</typeparam> | ||
/// <returns>An empty <see cref="IAsyncEnumerable{T}"/>.</returns> | ||
public static async IAsyncEnumerable<T> Empty<T>() | ||
{ | ||
await Task.CompletedTask; | ||
yield break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// ReSharper disable PossibleMultipleEnumeration | ||
namespace Atc.Tests.Factories; | ||
|
||
public class AsyncEnumerableFactoryTests | ||
{ | ||
[Fact] | ||
public async Task Empty_ReturnsEmptySequence() | ||
{ | ||
// Arrange | ||
var result = new List<int>(); | ||
|
||
// Act | ||
await foreach (var item in AsyncEnumerableFactory.Empty<int>()) | ||
{ | ||
result.Add(item); | ||
} | ||
|
||
// Assert | ||
Assert.Empty(result); | ||
} | ||
|
||
[Fact] | ||
public async Task Empty_ReturnsEmptySequence_ForReferenceType() | ||
{ | ||
// Arrange | ||
var result = new List<string>(); | ||
|
||
// Act | ||
await foreach (var item in AsyncEnumerableFactory.Empty<string>()) | ||
{ | ||
result.Add(item); | ||
} | ||
|
||
// Assert | ||
Assert.Empty(result); | ||
} | ||
|
||
[Fact] | ||
public async Task Empty_ReturnsEmptySequence_WhenEnumeratedMultipleTimes() | ||
{ | ||
// Arrange & Act | ||
var emptyEnumerable = AsyncEnumerableFactory.Empty<int>(); | ||
var firstResult = new List<int>(); | ||
var secondResult = new List<int>(); | ||
|
||
await foreach (var item in emptyEnumerable) | ||
{ | ||
firstResult.Add(item); | ||
} | ||
|
||
await foreach (var item in emptyEnumerable) | ||
{ | ||
secondResult.Add(item); | ||
} | ||
|
||
// Assert | ||
Assert.Empty(firstResult); | ||
Assert.Empty(secondResult); | ||
} | ||
|
||
[Fact] | ||
public async Task Empty_ReturnsEmptySequence_WithDifferentTypes() | ||
{ | ||
// Arrange | ||
var intResult = new List<int>(); | ||
|
||
// Act & Assert | ||
await foreach (var item in AsyncEnumerableFactory.Empty<int>()) | ||
{ | ||
intResult.Add(item); | ||
} | ||
|
||
var stringResult = new List<string>(); | ||
await foreach (var item in AsyncEnumerableFactory.Empty<string>()) | ||
{ | ||
stringResult.Add(item); | ||
} | ||
|
||
var customTypeResult = new List<LogKeyValueItem>(); | ||
await foreach (var item in AsyncEnumerableFactory.Empty<LogKeyValueItem>()) | ||
{ | ||
customTypeResult.Add(item); | ||
} | ||
|
||
Assert.Empty(intResult); | ||
Assert.Empty(stringResult); | ||
Assert.Empty(customTypeResult); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters