public void Constructor_ShouldInitializePropertiesWithCorrectlyValues() { //ARRANGE const string query = "testQuery"; const int parameters = 43; Type resultType = typeof(double); const InvokeMethod invokeMethod = InvokeMethod.Execute; IDbConnection connection = A.Fake <IDbConnection>(); IDbCommand command = A.Fake <IDbCommand>(); IConfiguration configuration = A.Fake <IConfiguration>(); //ACT var context = new AdoExecutorContext(query, parameters, resultType, invokeMethod, connection, command, configuration); //ASSERT Assert.AreEqual(query, context.Query); Assert.AreEqual(parameters, context.Parameters); Assert.AreEqual(resultType, context.ResultType); Assert.AreEqual(invokeMethod, context.InvokeMethod); Assert.AreSame(connection, context.Connection); Assert.AreSame(command, context.Command); Assert.AreSame(configuration, context.Configuration); CollectionAssert.IsEmpty(context.Bag); }
public bool CanProcess(AdoExecutorContext context) { if (context.Parameters is IDataParameter) { return(true); } if (context.Parameters is IEnumerable <IDataParameter> ) { return(true); } return(false); }
public void ParametersType_ShouldBeNull_WhenParametersValueIsNull() { //ACT var context = new AdoExecutorContext( "testQuery", null, typeof(string), InvokeMethod.Select, A.Fake <IDbConnection>(), A.Fake <IDbCommand>(), A.Fake <IConfiguration>()); //ASSERT Assert.IsNull(context.ParametersType); }
public void ExtractParameter(AdoExecutorContext context) { var parameters = context.Parameters as IEnumerable <IDataParameter>; if (parameters != null) { foreach (var dataParameter in parameters) { context.Command.Parameters.Add(dataParameter); } } else { var dataParameter = (IDataParameter)context.Parameters; context.Command.Parameters.Add(dataParameter); } }
public void ParametersType_ShouldSetParameterType_WhenParametersValueIsNotNull() { //ARRANGE const string value = "test"; Type expectedType = typeof(string); //ACT var context = new AdoExecutorContext( "testQuery", value, typeof(string), InvokeMethod.Select, A.Fake <IDbConnection>(), A.Fake <IDbCommand>(), A.Fake <IConfiguration>()); //ASSERT Assert.AreEqual(expectedType, context.ParametersType); }
public void LogOnEntry_ShouldPrepareMessageNotIncludingParameters_WhenSqlCommandHasNotParameters() { //ASSERT var command = new SqlCommand(); var context = new AdoExecutorContext("testQuery", "test", typeof(string), InvokeMethod.Execute, A.Fake <IDbConnection>(), command, A.Fake <IConfiguration>()); //ACT ((IInterceptor)_logger).OnEntry(context); //ASSERT Assert.AreEqual(1, _logger.OnEntryLog.Count); Assert.AreEqual(ExpectedMessageWithoutParameters, _logger.OnEntryLog[0]); }
protected virtual StringBuilder PrepareLogMessage(AdoExecutorContext context) { var result = new StringBuilder(); result.AppendLine("*** QUERY ***"); result.AppendLine(context.Query); result.Append("*** END OF QUERY ***"); if (context.Command.Parameters.Count > 0) { result.AppendLine(Environment.NewLine); result.AppendLine("*** PARAMETERS ***"); foreach (IDbDataParameter parameter in context.Command.Parameters) { result.AppendLine(string.Format("Name: {0}, Value: {1}, DbType: {2}", parameter.ParameterName, parameter.Value, parameter.DbType)); } result.Append("*** END OF PARAMETERS ***"); } return(result); }
protected override void LogOnEntry(AdoExecutorContext context, string logMessage) { OnEntryLog.Add(logMessage); }
protected virtual void LogOnEntry(AdoExecutorContext context, string logMessage) { }
void IInterceptor.OnEntry(AdoExecutorContext context) { StringBuilder logMessage = PrepareLogMessage(context); LogOnEntry(context, logMessage.ToString()); }