public void Constructor_WithoutSubjectFormatString_RegistersDefaultSubjectFormatString() { // Act var provider = new MailLoggingProvider(ValidThreshold, ValidRecipient); // Assert Assert.AreEqual("{0}: {1}", provider.SubjectFormatString); }
public void Constructor_WithoutFallbackProvider_RegistersNoFallbackProvider() { // Act var provider = new MailLoggingProvider(ValidThreshold, ValidRecipient); // Assert Assert.IsNull(provider.FallbackProvider); }
public void BuildMailPriority_WithSeverityDebug_ReturnsMailPriorityNormal() { // Arrange var expectedPriority = MailPriority.Normal; // Act MailPriority actualPriority = MailLoggingProvider.DetermineMailPriority(LoggingEventType.Debug); // Assert Assert.AreEqual(expectedPriority, actualPriority); }
public void BuildMailPriority_WithSeverityCritical_ReturnsMailPriorityHigh() { // Arrange var expectedPriority = MailPriority.High; // Act MailPriority actualPriority = MailLoggingProvider.DetermineMailPriority(LoggingEventType.Critical); // Assert Assert.AreEqual(expectedPriority, actualPriority); }
public void BuildMailMessageSubject_SubjectFormatStringWithDateFormatItem_ReturnsDate() { string subjectFormatString = "{4}"; DateTime currentTime = new DateTime(2009, 11, 30, 18, 27, 12); var entryToFormat = new LogEntry(LoggingEventType.Debug, "Some message", null, null); // Act string subject = MailLoggingProvider.BuildMailMessageSubject(subjectFormatString, entryToFormat, currentTime); Assert.AreEqual("11/30/2009 18:27:12", subject); }
public void Initialize_ConfigurationWithoutDescription_SetsDefaultDescription() { // Arrange var expectedDescription = "Mail logging provider"; var provider = new MailLoggingProvider(); var validConfiguration = CreateValidConfiguration(); // Act provider.Initialize("Valid provider name", validConfiguration); // Assert Assert.AreEqual(expectedDescription, provider.Description); }
public void BuildMailMessageSubject_EntryWithLongMessage_TruncatesMessageAccordingly() { string subjectFormatString = "{1}"; string message = string.Join(",", Enumerable.Repeat("123456789_", 20).ToArray()); DateTime currentTime = new DateTime(2009, 11, 30, 18, 27, 12); var entryToFormat = new LogEntry(LoggingEventType.Debug, message, null, null); // Act string subject = MailLoggingProvider.BuildMailMessageSubject(subjectFormatString, entryToFormat, currentTime); Assert.IsFalse(subject.Contains(message)); Assert.IsTrue(subject.Contains(message.Substring(0, 100))); }
public void BuildMailMessageSubject_SubjectFormatStringWithExeptionTypeFormatItem_ReturnsExceptionType() { // Arrange string subjectFormatString = "{3}"; var expectedException = new InvalidOperationException(); var entry = new LogEntry(LoggingEventType.Debug, "Some message", null, expectedException); // Act string subject = MailLoggingProvider.BuildMailMessageSubject(subjectFormatString, entry, DateTime.MaxValue); // Assert Assert.AreEqual(expectedException.GetType().Name, subject); }
public void BuildMailMessageSubject_SubjectFormatStringWithSourceFormatItem_ReturnsSource() { // Arrange string subjectFormatString = "{2}"; var expectedSource = "Expected source"; var entry = new LogEntry(LoggingEventType.Debug, "Some message", expectedSource, null); // Act string subject = MailLoggingProvider.BuildMailMessageSubject(subjectFormatString, entry, DateTime.MaxValue); // Assert Assert.AreEqual(expectedSource, subject); }
public void BuildMailMessageSubject_SubjectFormatStringWithSeverityFormatItem_ReturnsSeverity() { // Arrange string subjectFormatString = "{0}"; var expectedSeverity = LoggingEventType.Critical; var entry = new LogEntry(expectedSeverity, "Some message", null, null); // Act string subject = MailLoggingProvider.BuildMailMessageSubject(subjectFormatString, entry, DateTime.MaxValue); // Assert Assert.AreEqual(expectedSeverity.ToString(), subject); }
public void Log_WithUninitializedProvider_ThrowsDescriptiveException() { // Arrange var provider = new MailLoggingProvider(); try { // Act provider.Log("Some message"); // Assert Assert.Fail("Exception expected."); } catch (InvalidOperationException ex) { Assert.IsTrue(ex.Message.Contains("The provider has not been initialized"), "A provider that hasn't been initialized correctly, should throw a descriptive " + "exception. Actual: " + ex.Message + Environment.NewLine + ex.StackTrace); Assert.IsTrue(ex.Message.Contains("MailLoggingProvider"), "The message should contain the type name of the unitialized provider. Actual: " + ex.Message); } }