void IInterceptor.OnError(InterceptorErrorContext context) { StringBuilder logMessage = PrepareLogMessage(context); logMessage.AppendLine(Environment.NewLine); logMessage.AppendLine("*** EXCEPTION ***"); logMessage.AppendLine(context.Exception.ToString()); logMessage.Append("*** END OF EXCEPTION ***"); LogOnError(context, logMessage.ToString()); }
public void OnError(InterceptorErrorContext context) { foreach (IInterceptor interceptor in _configuration.Interceptors) { try { interceptor.OnError(context); } catch { //Interceptors shoud do not affect to query execution flow } } }
public void Constructor_ShouldPass_WhenAllRequiredParametersAreNotNull() { //ARRANGE var exception = new System.Exception(); //ACT var context = new InterceptorErrorContext( "testQuery", "test", typeof(string), InvokeMethod.Execute, A.Fake <IDbConnection>(), A.Fake <IDbCommand>(), A.Fake <IConfiguration>(), exception); //ASSERT Assert.AreSame(exception, context.Exception); }
public void LogOnError_ShouldWriteLineErrorMessage() { //ARRANGE var exception = new System.Exception(); var context = new InterceptorErrorContext( "testQuery", "test", typeof(string), InvokeMethod.Execute, A.Fake <IDbConnection>(), A.Fake <IDbCommand>(), A.Fake <IConfiguration>(), exception); //ACT ((IInterceptor)_consoleLoggerInterceptor).OnError(context); //ASSERT Assert.IsNotEmpty(_consoleOutput.ToString()); }
public void LogOnError_ShouldPrepareMessageNotIncludingParameters_WhenSqlCommandHasNotParameters() { //ASSERT var exception = new System.Exception("testExceptionMessage"); var command = new SqlCommand(); var context = new InterceptorErrorContext("testQuery", "test", typeof(string), InvokeMethod.Execute, A.Fake <IDbConnection>(), command, A.Fake <IConfiguration>(), exception); //ACT ((IInterceptor)_logger).OnError(context); //ASSERT Assert.AreEqual(1, _logger.OnErrorLog.Count); Assert.AreEqual(ExpectedMessageWithoutParametersAndWithError, _logger.OnErrorLog[0]); }
protected override void LogOnError(InterceptorErrorContext context, string logMessage) { OnErrorLog.Add(logMessage); }
protected virtual void LogOnError(InterceptorErrorContext context, string logMessage) { }
protected override void LogOnError(InterceptorErrorContext context, string logMessage) { Console.WriteLine(logMessage); }