public void MailTarget_UseSystemNetMailSettings_True_KeepOverridenFiles() { var configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var section = configuration.GetSection("system.net/mailSettings/smtp") as System.Net.Configuration.SmtpSection; section.From = null; var mmt = new MockMailTarget() { From = "*****@*****.**", To = "*****@*****.**", SmtpServer = "server1", SmtpPort = 27, Body = "${level} ${logger} ${message}", UseSystemNetMailSettings = true, MailSettings = section }; mmt.Initialize(null); mmt.ConfigureMailClient(); var exceptions = new List <Exception>(); mmt.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Debug, "MyLogger", "log message").WithContinuation(exceptions.Add)); Assert.Equal("'*****@*****.**'", mmt.From.ToString()); }
public void MailTarget_UseSystemNetMailSettings_True() { var inConfigVal = @"C:\config"; var mmt = new MockMailTarget(inConfigVal) { From = "*****@*****.**", To = "*****@*****.**", Subject = "Hello from NLog", Body = "${level} ${logger} ${message}", UseSystemNetMailSettings = true }; mmt.ConfigureMailClient(); Assert.Equal(mmt.SmtpClientPickUpDirectory, inConfigVal); }
public void MailTarget_UseSystemNetMailSettings_False_Override_ThrowsNLogRuntimeException_if_DeliveryMethodNotSpecified() { var inConfigVal = @"C:\config"; var mmt = new MockMailTarget(inConfigVal) { From = "*****@*****.**", To = "*****@*****.**", Subject = "Hello from NLog", SmtpPort = 27, Body = "${level} ${logger} ${message}", PickupDirectoryLocation = @"C:\TEMP", UseSystemNetMailSettings = false }; Assert.Throws <NLogRuntimeException>(() => mmt.ConfigureMailClient()); }
public void MailTarget_UseSystemNetMailSettings_False_Override_DeliveryMethod_SpecifiedDeliveryMethod() { var inConfigVal = @"C:\config"; var mmt = new MockMailTarget(inConfigVal) { From = "*****@*****.**", To = "*****@*****.**", Subject = "Hello from NLog", SmtpPort = 27, Body = "${level} ${logger} ${message}", PickupDirectoryLocation = @"C:\TEMP", UseSystemNetMailSettings = false, DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory }; mmt.ConfigureMailClient(); Assert.NotEqual(mmt.PickupDirectoryLocation, inConfigVal); }
public void MailTarget_UseSystemNetMailSettings_True_WithVirtualPath() { var inConfigVal = @"~/App_Data/Mail"; var mmt = new MockMailTarget(inConfigVal) { From = "*****@*****.**", To = "*****@*****.**", Subject = "Hello from NLog", Body = "${level} ${logger} ${message}", UseSystemNetMailSettings = false, PickupDirectoryLocation = inConfigVal, DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory }; mmt.ConfigureMailClient(); Assert.NotEqual(inConfigVal, mmt.SmtpClientPickUpDirectory); var separator = Path.DirectorySeparatorChar; Assert.Contains(string.Format("{0}App_Data{0}Mail", separator), mmt.SmtpClientPickUpDirectory); }
public void MailTarget_UseSystemNetMailSettings_True_WithVirtualPath() { var inConfigVal = @"~/App_Data/Mail"; var mmt = new MockMailTarget(inConfigVal) { From = "*****@*****.**", To = "*****@*****.**", Subject = "Hello from NLog", Body = "${level} ${logger} ${message}", UseSystemNetMailSettings = false, PickupDirectoryLocation = inConfigVal, DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory }; mmt.ConfigureMailClient(); Assert.NotEqual(inConfigVal, mmt.SmtpClientPickUpDirectory); var separator = Path.DirectorySeparatorChar; Assert.Contains(string.Format("{0}App_Data{0}Mail", separator), mmt.SmtpClientPickUpDirectory); }
public void MailTarget_UseSystemNetMailSettings_True() { var inConfigVal = @"C:\config"; var mmt = new MockMailTarget(inConfigVal) { From = "*****@*****.**", To = "*****@*****.**", Subject = "Hello from NLog", Body = "${level} ${logger} ${message}", UseSystemNetMailSettings = true }; mmt.ConfigureMailClient(); Assert.Equal(mmt.SmtpClientPickUpDirectory, inConfigVal); }
public void MailTarget_UseSystemNetMailSettings_False_Override_DeliveryMethod_SpecifiedDeliveryMethod() { var inConfigVal = @"C:\config"; var mmt = new MockMailTarget(inConfigVal) { From = "*****@*****.**", To = "*****@*****.**", Subject = "Hello from NLog", SmtpPort = 27, Body = "${level} ${logger} ${message}", PickupDirectoryLocation = @"C:\TEMP", UseSystemNetMailSettings = false, DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory }; mmt.ConfigureMailClient(); Assert.NotEqual(mmt.PickupDirectoryLocation, inConfigVal); }
public void MailTarget_UseSystemNetMailSettings_False_Override_ThrowsNLogRuntimeException_if_DeliveryMethodNotSpecified() { var inConfigVal = @"C:\config"; var mmt = new MockMailTarget(inConfigVal) { From = "*****@*****.**", To = "*****@*****.**", Subject = "Hello from NLog", SmtpPort = 27, Body = "${level} ${logger} ${message}", PickupDirectoryLocation = @"C:\TEMP", UseSystemNetMailSettings = false }; Assert.Throws<NLogRuntimeException>(() => mmt.ConfigureMailClient()); }