public void Log_WithFailingImplementationAndConfiguredFallbackProvider_LogsOriginalFailureToFallbackProvider() { // Arrange var failingProvider = new ThrowingLoggingProvider(); failingProvider.Initialize("Failing provider name", new NameValueCollection()); var fallbackProvider = new MemoryLoggingProvider(); failingProvider.FallbackProvider = fallbackProvider; failingProvider.ExceptionToThrowFromLogInternal = new InvalidOperationException(); var expectedEntry = new LogEntry(LoggingEventType.Error, "The event could not be logged with provider 'Failing provider name'.", "CuttingEdge.Logging.Tests.Unit.LoggingProviderBaseTests+ThrowingLoggingProvider", failingProvider.ExceptionToThrowFromLogInternal); // Act failingProvider.Log("Valid message"); // Assert var loggedEntry = fallbackProvider.GetLoggedEntries().Last(); AssertHelper.LogEntriesAreEqual(expectedEntry, loggedEntry); }
private static MemoryLoggingProvider CreateInitializedMemoryLogger(string name) { var provider = new MemoryLoggingProvider(); provider.Initialize(name, new NameValueCollection()); return(provider); }
public void Initialize_WithValidArguments_Succeeds() { // Arrange var provider = new MemoryLoggingProvider(); var validConfiguration = CreateValidConfiguration(); // Act provider.Initialize("Valid name", validConfiguration); }
public void Initialize_WithNullConfiguration_ThrowsException() { // Arrange var provider = new MemoryLoggingProvider(); NameValueCollection invalidConfiguration = null; // Act provider.Initialize("Valid name", invalidConfiguration); }
private static MemoryLoggingProvider CreateInitializedMemoryLoggingProvider() { var provider = new MemoryLoggingProvider(); var validConfiguration = CreateValidConfiguration(); provider.Initialize("MemoryLoggingProvider", validConfiguration); return(provider); }
public void Log_InitializedProvider_Succeeds() { // Arrange var provider = new MemoryLoggingProvider(); provider.Initialize("Valid name", CreateValidConfiguration()); // Act provider.Log("Some message"); }
public void Add_WithValidArgument_Succeeds() { // Arrange var collection = new LoggingProviderCollection(); var validProvider = new MemoryLoggingProvider(); validProvider.Initialize("Valid provider name", new NameValueCollection()); // Act collection.Add(validProvider); }
public void Initialize_ConfigurationWithUnrecognizedAttributes_ThrowsException() { // Arrange var provider = new MemoryLoggingProvider(); var configurationWithUnrecognizedAttribute = CreateValidConfiguration(); configurationWithUnrecognizedAttribute.Add("unknown attribute", "some value"); // Act provider.Initialize("Valid name", configurationWithUnrecognizedAttribute); }
public void FallbackProvider_ConstructorSuppliedWithFallbackProvider_ReturnsThatInstance() { // Arrange var expectedFallbackProvider = new MemoryLoggingProvider(); // Act var provider = CreateValidXmlFileLogger(expectedFallbackProvider); // Assert Assert.AreEqual(expectedFallbackProvider, provider.FallbackProvider); }
public void Log_WithValidEntry_AddsEntryToCollection() { // Arrange MemoryLoggingProvider provider = CreateInitializedMemoryLoggingProvider(); LogEntry expectedEntry = new LogEntry(LoggingEventType.Critical, "Valid message", null, null); // Act ((ILogger)provider).Log(expectedEntry); // Assert Assert.AreEqual(expectedEntry, provider.GetLoggedEntries().First()); }
public void Log_ProviderInitializedWithDebugThresholdThroughConstructor_LogsMessage() { // Arrange var expectedMessage = "Hello"; var provider = new MemoryLoggingProvider(LoggingEventType.Debug); // Act provider.Log(expectedMessage); // Assert Assert.AreEqual(1, provider.GetLoggedEntries().Length, "Message not logged"); }
public void Log_CodeConfiguredFailingProvider_LogsToFallbackProvider() { // Arrange var fallbackProvider = new MemoryLoggingProvider(); var provider = new FailingWindowsEventLogLoggingProvider(fallbackProvider); // Act provider.Log("Message"); // Assert Assert.AreEqual(2, fallbackProvider.GetLoggedEntries().Length, "Two messages are expected to be logged."); }
public void Log_ProviderInitializedWithCriticalThresholdThroughConstructor_DoesNotLogMessage() { // Arrange var expectedMessage = "Hello"; var provider = new MemoryLoggingProvider(LoggingEventType.Critical); // Act provider.Log(expectedMessage); // Assert Assert.AreEqual(0, provider.GetLoggedEntries().Length, "Message was expected not to be logged"); }
public void Log_CodeConfiguredFailingProvider_LogsToFallbackProvider() { // Arrange var fallbackProvider = new MemoryLoggingProvider(LoggingEventType.Debug); var provider = new FailingSqlLoggingProvider(fallbackProvider); // Act provider.Log("Test"); // Assert Assert.AreEqual(2, fallbackProvider.GetLoggedEntries().Length, "To events were expected to be logged."); }
public void Initialize_ConfigurationWithoutDescription_SetsDefaultDescription() { // Arrange var expectedDescription = "Memory logging provider"; var provider = new MemoryLoggingProvider(); var validConfiguration = CreateValidConfiguration(); // Act provider.Initialize("Valid provider name", validConfiguration); // Assert Assert.AreEqual(expectedDescription, provider.Description); }
public void Clear_OnANonEmptyProvivder_ResultsInAnEmptyLoggedEntriesCollection() { // Arrange MemoryLoggingProvider provider = CreateInitializedMemoryLoggingProvider(); provider.Log("Valid message"); int expectedNumberOfEntriesAfterCallingClear = 0; // Act provider.Clear(); // Assert Assert.AreEqual(expectedNumberOfEntriesAfterCallingClear, provider.GetLoggedEntries().Length); }
public void Log_CodeConfiguredFailingProvider_LogsToFallbackProvider() { // Arrange var fallbackProvider = new MemoryLoggingProvider(); var provider = new FakeAspNetSqlLoggingProvider(fallbackProvider); provider.ExceptionToThrowFromLogInternal = new Exception(); // Act provider.Log("Message"); // Assert Assert.AreEqual(2, fallbackProvider.GetLoggedEntries().Length, "Logging failed."); }
public void Initialize_ConfigurationWithCustomDescription_SetsSpecifiedDescription() { // Arrange var expectedDescription = "My memory logger"; var provider = new MemoryLoggingProvider(); var validConfiguration = CreateValidConfiguration(); validConfiguration["description"] = expectedDescription; // Act provider.Initialize("Valid provider name", validConfiguration); // Assert Assert.AreEqual(expectedDescription, provider.Description); }
public void Log_WithProviderInitializedWithCustomConstructor_LogsToAllSuppliedProviders() { // Arrange var provider1 = new MemoryLoggingProvider(); var provider2 = new MemoryLoggingProvider(); var provider = new CompositeLoggingProvider(LoggingEventType.Debug, null, provider1, provider2); // Act provider.Log("Test"); // Assert Assert.AreEqual(1, provider1.GetLoggedEntries().Count(), "CompositeLoggingProvider did not log."); Assert.AreEqual(1, provider2.GetLoggedEntries().Count(), "CompositeLoggingProvider did not log."); }
public void Log_ProviderInitializedWithDefaultConstructor_LogsSuccesfully() { // Arrange string expectedMessage = "Some message"; var provider = new MemoryLoggingProvider(); // Act // In contrast with most other providers, this provider should succeed in logging the event when // it was created with the default constructor, and not initialized with Initialize(string, NVC). // This behavior is different, because the the only initialization argument the provider needs is // the severity, which will be retain its default value of 'Debug' when not set. provider.Log(LoggingEventType.Debug, expectedMessage); // Arrange Assert.AreEqual(1, provider.GetLoggedEntries().Length, "The provider did not log."); }
public void Log_WithFailingImplementationAndConfiguredFallbackProvider_LogsEventToFallbackProvider() { // Arrange var failingProvider = new ThrowingLoggingProvider(); var fallbackProvider = new MemoryLoggingProvider(); failingProvider.FallbackProvider = fallbackProvider; failingProvider.ExceptionToThrowFromLogInternal = new InvalidOperationException(); var entryToLog = new LogEntry(LoggingEventType.Critical, "Valid message", null, null); // Act ((ILogger)failingProvider).Log(entryToLog); // Assert var loggedEntry = fallbackProvider.GetLoggedEntries().First(); Assert.AreEqual(entryToLog, loggedEntry); }
public void Log_WithValidEntry_ReturnsAnUniqueNumberPerCall() { // Arrange MemoryLoggingProvider provider = CreateInitializedMemoryLoggingProvider(); // Act int id0 = (int)provider.Log("Valid message"); int id1 = (int)provider.Log("Valid message"); int id2 = (int)provider.Log("Valid message"); int id3 = (int)provider.Log("Valid message"); int id4 = (int)provider.Log("Valid message"); // Assert Assert.AreEqual(0, id0); Assert.AreEqual(1, id1); Assert.AreEqual(2, id2); Assert.AreEqual(3, id3); Assert.AreEqual(4, id4); }