public void QueryMultiple_executes_with_arguments() { // set-up ISqlQuery sqlQuery = A.Fake <ISqlQuery>(); SqlText sqlText = A.Fake <SqlText>(); ParameterCollection parameters = new ParameterCollection(); const string sql = "select 1"; A.CallTo(() => sqlText.Sql()).Returns(sql); A.CallTo(() => sqlText.Parameters).Returns(parameters); // call tolist because of the yield delayed evaluation sqlQuery.QueryMultiple <int, DateTime>(sqlText).ToList(); // assert A.CallTo(() => sqlQuery.QueryMultiple(sqlText.Sql(), sqlText.Parameters, CommandType.Text, A <int?> .Ignored, A <Action <IDbConnection> > .Ignored)).MustHaveHappenedOnceExactly(); }
/// <summary> /// Returns multiple recordsets for the provided types. /// </summary> /// <typeparam name="TFirst"></typeparam> /// <typeparam name="TSecond"></typeparam> /// <param name="sqlQuery"></param> /// <param name="sqlText"></param> /// <param name="onExecute"></param> /// <returns></returns> public static IEnumerable <IEnumerable> QueryMultiple <TFirst, TSecond>(this ISqlQuery sqlQuery, SqlText sqlText, Action <IDbConnection> onExecute = null) { using (IGridReader gridReader = sqlQuery.QueryMultiple(sqlText.Sql(), sqlText.Parameters, commandType: CommandType.Text, onExecute: onExecute)) { yield return(gridReader.Read <TFirst>()); yield return(gridReader.Read <TSecond>()); } }
/// <summary> /// Executes the <see cref="SqlText"/>. /// </summary> /// <param name="sqlExecute"></param> /// <param name="sqlText"></param> /// <returns></returns> public static int Execute(this ISqlExecute sqlExecute, SqlText sqlText) { string sql = sqlText.Sql(); if (string.IsNullOrEmpty(sql)) { return(0); } return(sqlExecute.Execute(sql, sqlText.Parameters, CommandType.Text)); }
/// <summary> /// Returns multiple recordsets for the provided types. /// </summary> /// <typeparam name="TFirst"></typeparam> /// <typeparam name="TSecond"></typeparam> /// <typeparam name="TThird"></typeparam> /// <param name="sqlQuery"></param> /// <param name="sqlText"></param> /// <returns></returns> public static IEnumerable <IEnumerable> QueryMultiple <TFirst, TSecond, TThird>(this ISqlQuery sqlQuery, SqlText sqlText) { using (IGridReader gridReader = sqlQuery.QueryMultiple(sqlText.Sql(), sqlText.Parameters, commandType: CommandType.Text)) { yield return(gridReader.Read <TFirst>()); yield return(gridReader.Read <TSecond>()); yield return(gridReader.Read <TThird>()); } }
/// <summary> /// Returns a query based on the <see cref="SqlText"/>. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sqlQuery"></param> /// <param name="sqlText"></param> /// <param name="onExecute"></param> /// <returns></returns> public static IEnumerable <T> Query <T>(this ISqlQuery sqlQuery, SqlText sqlText, Action <IDbConnection> onExecute = null) { string sql = sqlText.Sql(); if (string.IsNullOrEmpty(sql)) { return(Enumerable.Empty <T>()); } return(sqlQuery.Query <T>(sql, sqlText.Parameters, CommandType.Text, onExecute)); }
public void Execute_excutes_with_arguments() { ISqlExecute sqlExecute = A.Fake <ISqlExecute>(); SqlText sqlText = A.Fake <SqlText>(); ParameterCollection parameters = new ParameterCollection(); const string sql = "select 1"; A.CallTo(() => sqlText.Sql()).Returns(sql); A.CallTo(() => sqlText.Parameters).Returns(parameters); sqlExecute.Execute(sqlText); A.CallTo(() => sqlExecute.Execute(sql, parameters, CommandType.Text, null)).MustHaveHappenedOnceExactly(); }
public void Execute_excutes_with_arguments() { // set-up ISqlQuery sqlQuery = A.Fake <ISqlQuery>(); SqlText sqlText = A.Fake <SqlText>(); ParameterCollection parameters = new ParameterCollection(); const string sql = "select 1"; A.CallTo(() => sqlText.Sql()).Returns(sql); A.CallTo(() => sqlText.Parameters).Returns(parameters); // call sqlQuery.Query <DateTime>(sqlText); // assert A.CallTo(() => sqlQuery.Query <DateTime>(sql, parameters, CommandType.Text, null)).MustHaveHappenedOnceExactly(); }
public void QueryMultiple_executes_connection_callback() { // set-up ISqlQuery sqlQuery = A.Fake <ISqlQuery>(); SqlText sqlText = A.Fake <SqlText>(); const string sql = "select 1"; A.CallTo(() => sqlText.Sql()).Returns(sql); Action <IDbConnection> callback = A.Fake <Action <IDbConnection> >(); A.CallTo(() => sqlQuery.QueryMultiple(sql, A <object> .Ignored, CommandType.Text, A <int?> .Ignored, callback)).Invokes(() => callback(null)); // call tolist because of the yield delayed evaluation sqlQuery.QueryMultiple <string, int>(sqlText, callback).ToList(); // assert A.CallTo(() => callback(A <IDbConnection> .Ignored)).MustHaveHappenedOnceExactly(); }
public void Query_executes_connection_callback() { // set-up ISqlQuery sqlQuery = A.Fake <ISqlQuery>(); SqlText sqlText = A.Fake <SqlText>(); const string sql = "select 1"; A.CallTo(() => sqlText.Sql()).Returns(sql); Action <IDbConnection> callback = A.Fake <Action <IDbConnection> >(); A.CallTo(() => sqlQuery.Query <DateTime>(sql, A <object> .Ignored, CommandType.Text, callback)).Invokes(() => callback(null)); // call sqlQuery.Query <DateTime>(sqlText, callback); // assert A.CallTo(() => callback(A <IDbConnection> .Ignored)).MustHaveHappenedOnceExactly(); }
/// <summary> /// Returns dynamic query. /// </summary> /// <param name="sqlQuery"></param> /// <param name="sqlText"></param> /// <param name="onExecute"></param> /// <returns></returns> public static IEnumerable <dynamic> QueryDynamic(this ISqlQuery sqlQuery, SqlText sqlText, Action <IDbConnection> onExecute = null) { return(sqlQuery.Query <dynamic>(sqlText.Sql(), sqlText.Parameters, commandType: CommandType.Text, onExecute: onExecute)); }