public void IfErrorHandlerSetsShouldRetryToTrueSendToLogProviderIsCalled() { IErrorHandler errorHandler = DelegateErrorHandler.New(error => { if (error.FailureCount < 2) { error.ShouldRetry = true; } }); var logProcessor = new TestLogProcessor(); var exception = new Exception(); var logProvider = new Mock <ILogProvider>().Object; var logEntry = new LogEntry(); logProcessor.Unlock().HandleError(exception, logProvider, logEntry, errorHandler, 1, "Oops: {0}", new object[] { 123 }); logProcessor.SendToLogProviderInvocations.Count.Should().Be(1); var sendToLogProviderInvocation = logProcessor.SendToLogProviderInvocations[0]; sendToLogProviderInvocation.LogProvider.Should().BeSameAs(logProvider); sendToLogProviderInvocation.LogEntry.Should().BeSameAs(logEntry); sendToLogProviderInvocation.ErrorHandler.Should().BeSameAs(errorHandler); sendToLogProviderInvocation.FailureCount.Should().Be(1); }
public void IfRetriedSendToLogProviderThrowsHandleErrorIsCalled() { IErrorHandler errorHandler = DelegateErrorHandler.New(error => { if (error.FailureCount < 2) { error.ShouldRetry = true; } }); var logProcessor = new TestLogProcessor(sendToLogProviderShouldThrow: true); var exception = new Exception(); var logProvider = new Mock <ILogProvider>().Object; var logEntry = new LogEntry(); logProcessor.Unlock().HandleError(exception, logProvider, logEntry, errorHandler, 1, "Oops: {0}", new object[] { 123 }); logProcessor.HandleErrorInvocations.Count.Should().Be(2); var invocation1 = logProcessor.HandleErrorInvocations[0]; var invocation2 = logProcessor.HandleErrorInvocations[1]; // Original HandleError call invocation1.Exception.Should().BeSameAs(exception); invocation1.LogProvider.Should().BeSameAs(logProvider); invocation1.LogEntry.Should().BeSameAs(logEntry); invocation1.FailureCount.Should().Be(1); invocation1.ErrorMessageFormat.Should().Be("Oops: {0}"); // Resend HandleError call invocation2.Exception.Should().NotBeSameAs(exception); invocation2.Exception.Message.Should().Be("error."); invocation2.LogProvider.Should().BeSameAs(logProvider); invocation2.LogEntry.Should().BeSameAs(logEntry); invocation2.FailureCount.Should().Be(2); invocation2.ErrorMessageFormat.Should().Be("Error while re-sending log entry {0} to log provider {1}."); }
public void HandleErrorInvokesErrorHandlerCallbackWhenProvided() { Error capturedError = null; IErrorHandler errorHandler = DelegateErrorHandler.New(error => { capturedError = error; }); var logProcessor = new TestLogProcessor(); var exception = new Exception(); var logProvider = new Mock <ILogProvider>().Object; var logEntry = new LogEntry(); logProcessor.Unlock().HandleError(exception, logProvider, logEntry, errorHandler, 321, "Oops: {0}", new object[] { 123 }); capturedError.Should().NotBeNull(); capturedError.Exception.Should().BeSameAs(exception); capturedError.LogProvider.Should().BeSameAs(logProvider); capturedError.LogEntry.Should().BeSameAs(logEntry); capturedError.FailureCount.Should().Be(321); capturedError.Message.Should().Be("Oops: 123"); }