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