Skip to content

Commit

Permalink
Fix build warning (#38)
Browse files Browse the repository at this point in the history
* Add task extensions to enumerate IEnumerable<T>s

* Fix build warning by checking count as well

* Add NuGet metadata to new package
  • Loading branch information
Tomas Lycken authored Nov 1, 2017
1 parent fd9ef32 commit 1b02e36
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ public async Task ReturnsEventsAccordingToQuery(string streamId, long expectedCo
public async Task ReturnsEventsWithMetadata(string streamId, long expectedCount)
{
var store = _fixture.BuildEventStore(_dbContext) as IEventStore<string, ExtraMetaStringEvent, IExtraMeta>;
var events = await store.Events(streamId, es => es.Where(e => e.ExtraMeta.StartsWith("Foo")));
var events = await store
.Events(streamId, es => es.Where(e => e.ExtraMeta.StartsWith("Foo")))
.ToReadOnlyCollection();

Assert.Equal(expectedCount, events.Count);
Assert.All(events, @event => Assert.StartsWith("Foo", @event.ExtraMeta));
}

Expand Down
22 changes: 22 additions & 0 deletions src/tlycken.Extensions/TaskExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using System.Linq;

// ReSharper disable once CheckNamespace
namespace System.Threading.Tasks
{
public static class TaskExtensions
{
/// <summary>
/// Appends a continuation to the task, which iterates the resulting <see cref="IEnumerable{T}"/> into a <see cref="List{T}"/>.
/// </summary>
public static Task<List<T>> ToList<T>(this Task<IEnumerable<T>> task)
=> task.ContinueWith(t => t.Result.ToList());

/// <summary>
/// Appends a continuation to the task, which iterates the resulting <see cref="IEnumerable{T}"/> into a <see cref="List{T}"/>
/// and returns it as an <see cref="IReadOnlyCollection{T}"/>.
/// </summary>
public static Task<IReadOnlyCollection<T>> ToReadOnlyCollection<T>(this Task<IEnumerable<T>> task)
=> task.ContinueWith(t => t.Result.ToList() as IReadOnlyCollection<T>);
}
}
13 changes: 13 additions & 0 deletions src/tlycken.Extensions/tlycken.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>

<Version>0.0.0</Version>
<PackageVersion>0.0.0</PackageVersion>

<Title>tlycken.Extensions</Title>
<Description>Extensions for the .NET Standard Library</Description>
<Authors>Tomas Lycken (@tlycken)</Authors>
<Copyright>2017 Tomas Lycken</Copyright>
<PackageProjectUrl>https://github.com/tlycken/RdbmsEventStore</PackageProjectUrl>
<RepositoryUrl>https://github.com/tlycken/RdbmsEventStore</RepositoryUrl>
<PackageLicenseUrl>https://github.com/tlycken/RdbmsEventStore/blob/master/LICENSE.md</PackageLicenseUrl>
<IncludeSymbols>True</IncludeSymbols>
<IncludeSource>True</IncludeSource>
</PropertyGroup>

</Project>

0 comments on commit 1b02e36

Please sign in to comment.