Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
        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());
        }