protected override void Arrange() { base.Arrange(); authenticationMode = EmailTraceListener.Property("AuthenticationMode"); authenticationMode.Value = EmailAuthenticationMode.UserNameAndPassword; }
public void MessageIsSetWhenUsingJsonFormatter() { LoggingConfiguration loggingConfiguration = BuildProgrammaticConfigForTrace(); JsonLogFormatter jsonformatter = new JsonLogFormatter(JsonFormatting.Indented); EmailTraceListener emailListener = new EmailTraceListener(this.toaddress, this.fromaddress, "StartOfSubject", "EndOfSubject", this.smtpserver, jsonformatter); emailListener.Filter = new EventTypeFilter(SourceLevels.All); loggingConfiguration.AddLogSource("Email", SourceLevels.All, true, emailListener); loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(emailListener); string message = "Test JSON"; this.writer = new LogWriter(loggingConfiguration); this.writer.Write(message, "General"); this.writer.Dispose(); LogEntry logEntry = LogFileReader.GetLogEntryFromEmail(); Assert.IsTrue(logEntry.Message == message); }
public void JsonFormatterHeadersAreSetWhenSendingEmail() { DateTime messageTimestamp = DateTime.UtcNow; LoggingConfiguration loggingConfiguration = BuildProgrammaticConfigForTrace(); JsonLogFormatter jsonformatter = new JsonLogFormatter(JsonFormatting.Indented); EmailTraceListener emailListener = new EmailTraceListener(this.toaddress, this.fromaddress, "StartOfSubject", "EndOfSubject", this.smtpserver, jsonformatter); emailListener.Filter = new EventTypeFilter(SourceLevels.All); loggingConfiguration.AddLogSource("Email", SourceLevels.All, true, emailListener); loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(emailListener); string message = "Test JSON"; this.writer = new LogWriter(loggingConfiguration); this.writer.Write(message, "General"); this.writer.Dispose(); string emailText = LogFileReader.GetEmail(); string endOfHeader = "\r\n\r\n"; int index = emailText.IndexOf(endOfHeader); string header = emailText.Substring(0, index); Dictionary <string, string> emailDictionary = Regex.Split(header, "\r\n").Select(e => e.Split(':')).ToDictionary(line => line[0], line => line[1].Trim()); Assert.AreEqual("StartOfSubject Information EndOfSubject", emailDictionary["Subject"]); Assert.AreEqual(this.fromaddress, emailDictionary["From"]); Assert.AreEqual(this.toaddress, emailDictionary["To"]); }
public void CanCreatePoliciesForEmailTraceListenerWithFormatter() { EmailTraceListenerData listenerData = new EmailTraceListenerData("listener", "to address", "from address", "starter", "ender", "smtp", 25, "formatter"); listenerData.TraceOutputOptions = TraceOptions.Callstack | TraceOptions.ProcessId; listenerData.Filter = SourceLevels.Error; loggingSettings.TraceListeners.Add(listenerData); FormatterData formatterData = new TextFormatterData("formatter", "template"); loggingSettings.Formatters.Add(formatterData); using (var container = CreateContainer()) { EmailTraceListener createdObject = (EmailTraceListener)container.Resolve <TraceListener>("listener\u200cimplementation"); Assert.IsNotNull(createdObject); Assert.AreEqual(listenerData.TraceOutputOptions, createdObject.TraceOutputOptions); Assert.IsNotNull(createdObject.Filter); Assert.IsInstanceOfType(createdObject.Filter, typeof(EventTypeFilter)); Assert.AreEqual(listenerData.Filter, ((EventTypeFilter)createdObject.Filter).EventType); Assert.IsNotNull(createdObject.Formatter); Assert.AreSame(typeof(TextFormatter), createdObject.Formatter.GetType()); Assert.AreEqual("template", ((TextFormatter)createdObject.Formatter).Template); } }
public void CanCreatePoliciesForEmailTraceListenerWithFormatter() { EmailTraceListenerData listenerData = new EmailTraceListenerData("listener", "to address", "from address", "starter", "ender", "smtp", 25, "formatter"); listenerData.TraceOutputOptions = TraceOptions.Callstack | TraceOptions.ProcessId; listenerData.Filter = SourceLevels.Error; loggingSettings.TraceListeners.Add(listenerData); FormatterData formatterData = new TextFormatterData("formatter", "template"); loggingSettings.Formatters.Add(formatterData); container.AddExtension(new LoggingBlockExtension()); EmailTraceListener createdObject = (EmailTraceListener)container.Resolve <TraceListener>("listener"); Assert.IsNotNull(createdObject); Assert.AreEqual(listenerData.TraceOutputOptions, createdObject.TraceOutputOptions); Assert.IsNotNull(createdObject.Filter); Assert.IsInstanceOfType(createdObject.Filter, typeof(EventTypeFilter)); Assert.AreEqual(listenerData.Filter, ((EventTypeFilter)createdObject.Filter).EventType); Assert.IsNotNull(createdObject.Formatter); Assert.AreSame(typeof(TextFormatter), createdObject.Formatter.GetType()); Assert.AreEqual("template", ((TextFormatter)createdObject.Formatter).Template); // TODO test the actual values used to create the listener }
protected override void Arrange() { base.Arrange(); authenticationMode = EmailTraceListener.Property("AuthenticationMode"); authenticationMode.Value = EmailAuthenticationMode.WindowsCredentials; EmailTraceListener.Property("UserName").Value = "TestUser"; }
protected override void Arrange() { base.Arrange(); authenticationMode = EmailTraceListener.Property("AuthenticationMode"); authenticationMode.Value = EmailAuthenticationMode.UserNameAndPassword; EmailTraceListener.Property("UserName").Value = "TestUser"; LoggingSectionViewModel.ProtectionProviderProperty.Value = LoggingSectionViewModel.ProtectionProviderProperty.SuggestedValues.Last(); }
public void TestMailTraceListener() { var errorMessage = String.Format("Selective Claim Service Submit failed with the following exception:\r\n\r\n{0}", "This is a [TEST] error\r\n"); using (var listener = new EmailTraceListener("DISPFAIL_EMAIL")) { listener.Write(String.Format("Instance: {0}, CallID: {1}, Source Machine {2}.\r\n", GeneralUtility.InstanceFromRegistry, "000000007", GeneralUtility.MachineName)); listener.WriteLine(errorMessage); listener.Close(); } }
private void UpdateConfigForEmailNoEmailAuth(LoggingConfiguration loggingConfiguration) { if ((string.IsNullOrEmpty(this.fromaddress) || string.IsNullOrEmpty(this.toaddress) || string.IsNullOrEmpty(this.smtpserver))) { Assert.Inconclusive("Cannot run tests because SMTP server parameters are missing"); } else { EmailTraceListener emailListener = new EmailTraceListener(this.toaddress, this.fromaddress, "StartOfSubject", "EndOfSubject", this.smtpserver, this.smtpport, new TextFormatter()); emailListener.Filter = new EventTypeFilter(SourceLevels.All); loggingConfiguration.AddLogSource("Email", SourceLevels.All, true, emailListener); loggingConfiguration.SpecialSources.Unprocessed.Listeners.Add(emailListener); } }
/// <summary> /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. /// Builds an <see cref="EmailTraceListener"/> based on an instance of <see cref="EmailTraceListenerData"/>. /// </summary> /// <seealso cref="TraceListenerCustomFactory"/> /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param> /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="EmailTraceListenerData"/>.</param> /// <param name="configurationSource">The source for configuration objects.</param> /// <param name="reflectionCache">The cache to use retrieving reflection information.</param> /// <returns>A fully initialized instance of <see cref="EmailTraceListener"/>.</returns> public override TraceListener Assemble(IBuilderContext context, TraceListenerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { EmailTraceListenerData castedObjectConfiguration = (EmailTraceListenerData)objectConfiguration; ILogFormatter formatter = GetFormatter(context, castedObjectConfiguration.Formatter, configurationSource, reflectionCache); TraceListener createdObject = new EmailTraceListener( castedObjectConfiguration.ToAddress, castedObjectConfiguration.FromAddress, castedObjectConfiguration.SubjectLineStarter, castedObjectConfiguration.SubjectLineEnder, castedObjectConfiguration.SmtpServer, castedObjectConfiguration.SmtpPort, formatter); return createdObject; }
/// <summary> /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. /// Builds an <see cref="EmailTraceListener"/> based on an instance of <see cref="EmailTraceListenerData"/>. /// </summary> /// <seealso cref="TraceListenerCustomFactory"/> /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param> /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="EmailTraceListenerData"/>.</param> /// <param name="configurationSource">The source for configuration objects.</param> /// <param name="reflectionCache">The cache to use retrieving reflection information.</param> /// <returns>A fully initialized instance of <see cref="EmailTraceListener"/>.</returns> public override TraceListener Assemble(IBuilderContext context, TraceListenerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { EmailTraceListenerData castedObjectConfiguration = (EmailTraceListenerData)objectConfiguration; ILogFormatter formatter = GetFormatter(context, castedObjectConfiguration.Formatter, configurationSource, reflectionCache); TraceListener createdObject = new EmailTraceListener( castedObjectConfiguration.ToAddress, castedObjectConfiguration.FromAddress, castedObjectConfiguration.SubjectLineStarter, castedObjectConfiguration.SubjectLineEnder, castedObjectConfiguration.SmtpServer, castedObjectConfiguration.SmtpPort, formatter); return(createdObject); }
protected override void Act() { EmailTraceListener.Validate(); result = EmailTraceListener.ValidationResults.Where(e => e.Message.Contains("Supply a user name")).FirstOrDefault(); }
protected override void Act() { passwordProperty = EmailTraceListener.Property("Password"); }
protected override void Act() { EmailTraceListener.Validate(); result = EmailTraceListener.ValidationResults.Where(e => e.Message.Contains("user name and password are not needed")).FirstOrDefault(); }
protected override void Act() { EmailTraceListener.Validate(); }