Skip to content

Commit

Permalink
fix async issues, add async tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed May 4, 2018
1 parent 3ad06ad commit b2731b2
Show file tree
Hide file tree
Showing 4 changed files with 394 additions and 5 deletions.
60 changes: 60 additions & 0 deletions src/FluentCommand.EntityFactory/DataCommandExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace FluentCommand
Expand Down Expand Up @@ -64,5 +65,64 @@ public static TEntity QuerySingle<TEntity>(this IDataQuery dataQuery)
return dataQuery.QuerySingle(ReaderFactory.EntityFactory<TEntity>);
}



/// <summary>
/// Executes the command against the connection and converts the results to dynamic objects asynchronously.
/// </summary>
/// <param name="dataQuery">The <see cref="IDataQueryAsync"/> for this extension method.</param>
/// <param name="cancellationToken">The cancellation instruction.</param>
/// <returns>
/// An <see cref="T:System.Collections.Generic.IEnumerable`1" /> of dynamic objects.
/// </returns>
public static Task<IEnumerable<dynamic>> QueryAsync(this IDataQueryAsync dataQuery, CancellationToken cancellationToken = default(CancellationToken))
{
return dataQuery.QueryAsync(ReaderFactory.DynamicFactory, cancellationToken);
}

/// <summary>
/// Executes the command against the connection and converts the results to <typeparamref name="TEntity" /> objects asynchronously.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <param name="dataQuery">The <see cref="IDataQueryAsync"/> for this extension method.</param>
/// <param name="cancellationToken">The cancellation instruction.</param>
/// <returns>
/// An <see cref="T:System.Collections.Generic.IEnumerable`1" /> of <typeparamref name="TEntity" /> objects.
/// </returns>
public static Task<IEnumerable<TEntity>> QueryAsync<TEntity>(this IDataQueryAsync dataQuery, CancellationToken cancellationToken = default(CancellationToken))
where TEntity : class, new()
{
return dataQuery.QueryAsync(ReaderFactory.EntityFactory<TEntity>, cancellationToken);
}


/// <summary>
/// Executes the query and returns the first row in the result as a dynamic object asynchronously.
/// </summary>
/// <param name="dataQuery">The <see cref="IDataQueryAsync"/> for this extension method.</param>
/// <param name="cancellationToken">The cancellation instruction.</param>
/// <returns>
/// A instance of a dynamic object if row exists; otherwise null.
/// </returns>
public static Task<dynamic> QuerySingleAsync(this IDataQueryAsync dataQuery, CancellationToken cancellationToken = default(CancellationToken))
{
return dataQuery.QuerySingleAsync(ReaderFactory.DynamicFactory, cancellationToken);
}

/// <summary>
/// Executes the query and returns the first row in the result as a <typeparamref name="TEntity" /> object asynchronously.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <param name="dataQuery">The <see cref="IDataQueryAsync"/> for this extension method.</param>
/// <param name="cancellationToken">The cancellation instruction.</param>
/// <returns>
/// A instance of <typeparamref name="TEntity" /> if row exists; otherwise null.
/// </returns>
public static Task<TEntity> QuerySingleAsync<TEntity>(this IDataQueryAsync dataQuery, CancellationToken cancellationToken = default(CancellationToken))
where TEntity : class, new()
{
return dataQuery.QuerySingleAsync(ReaderFactory.EntityFactory<TEntity>, cancellationToken);
}

}
}
16 changes: 16 additions & 0 deletions src/FluentCommand/DataCommandExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
using FluentCommand.Extensions;

namespace FluentCommand
Expand Down Expand Up @@ -165,5 +167,19 @@ public static TValue QueryValue<TValue>(this IDataQuery dataQuery)
return dataQuery.QueryValue<TValue>(null);
}

/// <summary>
/// Executes the query and returns the first column of the first row in the result set returned by the query asynchronously. All other columns and rows are ignored.
/// </summary>
/// <typeparam name="TValue">The type of the value.</typeparam>
/// <param name="dataQuery">The <see cref="IDataQuery"/> for this extension method.</param>
/// <param name="cancellationToken">The cancellation instruction.</param>
/// <returns>
/// The value of the first column of the first row in the result set.
/// </returns>
public static Task<TValue> QueryValueAsync<TValue>(this IDataQueryAsync dataQuery, CancellationToken cancellationToken = default(CancellationToken))
{
return dataQuery.QueryValueAsync<TValue>(null, cancellationToken);
}

}
}

0 comments on commit b2731b2

Please sign in to comment.