LCOV - code coverage report
Current view: top level - Cqrs.Sql/DataStores - SqlDataStoreExtensions.cs Hit Total Coverage
Test: doc-coverage.info Lines: 2 3 66.7 %
Date: 2017-07-26

          Line data    Source code
       1             : using System;
       2             : using System.Collections.Generic;
       3             : using System.Linq;
       4             : using System.Linq.Expressions;
       5             : using Cqrs.DataStores;
       6             : 
       7             : namespace Cqrs.Sql.DataStores
       8             : {
       9             :         public static class SqlDataStoreExtensions
      10           0 :         {
      11             :                 /// <summary>
      12             :                 /// Use this one
      13             :                 /// </summary>
      14           1 :                 public static IQueryable<TEntity> Where<TEntity, TDbEntity>(this IDataStore<TEntity> dataStore, Expression<Func<TEntity, bool>> predicate)
      15             :                         where TDbEntity : class, new()
      16             :                 {
      17             :                         var sqlDataStore = dataStore as SqlDataStore<TEntity, TDbEntity>;
      18             :                         if (sqlDataStore != null)
      19             :                         {
      20             :                                 Expression expression = sqlDataStore.ExpressionConverter.Visit(predicate);
      21             : 
      22             :                                 return new SqlDataStore<TEntity, TDbEntity>
      23             :                                 (
      24             :                                         sqlDataStore.DataContext,
      25             :                                         sqlDataStore.DataTable,
      26             :                                         sqlDataStore.DbEntityQuery.Where((Expression<Func<TDbEntity, bool>>)expression),
      27             :                                         sqlDataStore.EntityQuery.Where(predicate)
      28             :                                 );
      29             :                         }
      30             : 
      31             :                         return dataStore.Where(predicate);
      32             :                 }
      33             : 
      34             :                 /// <summary>
      35             :                 /// Use this one
      36             :                 /// </summary>
      37           1 :                 public static TEntity Single<TEntity, TDbEntity>(this IEnumerable<TEntity> dataStore)
      38             :                         where TDbEntity : class, new()
      39             :                         where TEntity : new()
      40             :                 {
      41             :                         var sqlDataStore = dataStore as SqlDataStore<TEntity, TDbEntity>;
      42             :                         if (sqlDataStore != null)
      43             :                         {
      44             :                                 TDbEntity result = sqlDataStore.DbEntityQuery.Single();
      45             :                                 var convertedResult = Converters.ConvertTo<TEntity>(result);
      46             :                                 return convertedResult;
      47             :                         }
      48             :                         return dataStore.Single();
      49             :                 }
      50             :         }
      51             : }

Generated by: LCOV version 1.10