• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# MockMailTarget类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MockMailTarget的典型用法代码示例。如果您正苦于以下问题:C# MockMailTarget类的具体用法?C# MockMailTarget怎么用?C# MockMailTarget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MockMailTarget类属于命名空间,在下文中一共展示了MockMailTarget类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SimpleEmailTest

        public void SimpleEmailTest()
        {
            var mmt = new MockMailTarget
            {
                From = "[email protected]",
                To = "[email protected]",
                CC = "[email protected];[email protected]",
                Bcc = "[email protected];[email protected]",
                Subject = "Hello from NLog",
                SmtpServer = "server1",
                SmtpPort = 27,
                Body = "${level} ${logger} ${message}"
            };

            mmt.Initialize(null);

            var exceptions = new List<Exception>();
            mmt.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "MyLogger", "log message 1").WithContinuation(exceptions.Add));
            Assert.Null(exceptions[0]);

            Assert.Equal(1, mmt.CreatedMocks.Count);

            var mock = mmt.CreatedMocks[0];
            Assert.Equal(1, mock.MessagesSent.Count);
            Assert.Equal("server1", mock.Host);
            Assert.Equal(27, mock.Port);
            Assert.False(mock.EnableSsl);
            Assert.Null(mock.Credentials);

            var msg = mock.MessagesSent[0];
            Assert.Equal("Hello from NLog", msg.Subject);
            Assert.Equal("[email protected]", msg.From.Address);
            Assert.Equal(1, msg.To.Count);
            Assert.Equal("[email protected]", msg.To[0].Address);
            Assert.Equal(2, msg.CC.Count);
            Assert.Equal("[email protected]", msg.CC[0].Address);
            Assert.Equal("[email protected]server.com", msg.CC[1].Address);
            Assert.Equal(2, msg.Bcc.Count);
            Assert.Equal("[email protected]", msg.Bcc[0].Address);
            Assert.Equal("[email protected]", msg.Bcc[1].Address);
            Assert.Equal(msg.Body, "Info MyLogger log message 1");
        }
开发者ID:Xharze,项目名称:NLog,代码行数:42,代码来源:MailTargetTests.cs


示例2: MailTarget_WithValidToAndEmptyBcc_SendsMail

        public void MailTarget_WithValidToAndEmptyBcc_SendsMail()
        {
            var mmt = new MockMailTarget
            {
                From = "[email protected]",
                To = "[email protected]",
                Bcc = "",
                Subject = "Hello from NLog",
                SmtpServer = "server1",
                SmtpPort = 27,
                Body = "${level} ${logger} ${message}",
            };
            mmt.Initialize(null);

            var exceptions = new List<Exception>();
            mmt.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "MyLogger", "log message 1").WithContinuation(exceptions.Add));

            Assert.Null(exceptions[0]);
            Assert.Equal(1, mmt.CreatedMocks.Count);
            Assert.Equal(1, mmt.CreatedMocks[0].MessagesSent.Count);
        }
开发者ID:Xharze,项目名称:NLog,代码行数:21,代码来源:MailTargetTests.cs


示例3: MailTarget_WithInvalidPriority_SendsMailWithNormalPriority

        public void MailTarget_WithInvalidPriority_SendsMailWithNormalPriority()
        {
            var mmt = new MockMailTarget
            {
                From = "[email protected]",
                To = "[email protected]",
                Subject = "Hello from NLog",
                SmtpServer = "server1",
                Priority = "invalidPriority"
            };
            mmt.Initialize(null);

            mmt.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "MyLogger", "log message 1").WithContinuation(_ => { }));

            var messageSent = mmt.CreatedMocks[0].MessagesSent[0];
            Assert.Equal(MailPriority.Normal, messageSent.Priority);
        }
开发者ID:Xharze,项目名称:NLog,代码行数:17,代码来源:MailTargetTests.cs


示例4: CustomHeaderAndFooter

        public void CustomHeaderAndFooter()
        {
            var mmt = new MockMailTarget
            {
                From = "[email protected]",
                To = "[email protected]",
                SmtpServer = "server1",
                AddNewLines = true,
                Layout = "${message}",
                Header = "First event: ${logger}",
                Footer = "Last event: ${logger}",
            };

            mmt.Initialize(null);

            var exceptions = new List<Exception>();
            mmt.WriteAsyncLogEvents(
                new LogEventInfo(LogLevel.Info, "MyLogger1", "log message 1").WithContinuation(exceptions.Add),
                new LogEventInfo(LogLevel.Debug, "MyLogger2", "log message 2").WithContinuation(exceptions.Add),
                new LogEventInfo(LogLevel.Error, "MyLogger3", "log message 3").WithContinuation(exceptions.Add));
            Assert.Null(exceptions[0]);

            Assert.Equal(1, mmt.CreatedMocks.Count);

            var mock = mmt.CreatedMocks[0];
            Assert.Equal(1, mock.MessagesSent.Count);
            var msg = mock.MessagesSent[0];
            string expectedBody = "First event: MyLogger1\nlog message 1\nlog message 2\nlog message 3\nLast event: MyLogger3\n";
            Assert.Equal(expectedBody, msg.Body);
        }
开发者ID:Xharze,项目名称:NLog,代码行数:30,代码来源:MailTargetTests.cs


示例5: NoReplaceNewlinesWithBreakInHtmlMail

        public void NoReplaceNewlinesWithBreakInHtmlMail()
        {
            var mmt = new MockMailTarget
            {
                From = "[email protected]",
                To = "[email protected]",
                Subject = "Hello from NLog",
                SmtpServer = "server1",
                Body = "${level}${newline}${logger}${newline}${message}",
                Html = true,
                ReplaceNewlineWithBrTagInHtml = false
            };

            mmt.Initialize(null);

            var exceptions = new List<Exception>();
            mmt.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "MyLogger", "log message 1").WithContinuation(exceptions.Add));

            var messageSent = mmt.CreatedMocks[0].MessagesSent[0];
            Assert.True(messageSent.IsBodyHtml);
            var lines = messageSent.Body.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            Assert.True(lines.Length == 3);
        }
开发者ID:Xharze,项目名称:NLog,代码行数:23,代码来源:MailTargetTests.cs


示例6: MailTarget_WithoutSubject_SendsMessageWithDefaultSubject

        public void MailTarget_WithoutSubject_SendsMessageWithDefaultSubject()
        {
            var mmt = new MockMailTarget
            {
                From = "[email protected]",
                To = "[email protected]",
                SmtpServer = "server1",
                SmtpPort = 27,
                Body = "${level} ${logger} ${message}"
            };
            mmt.Initialize(null);

            var exceptions = new List<Exception>();
            mmt.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "MyLogger", "log message 1").WithContinuation(exceptions.Add));

            Assert.Null(exceptions[0]);
            Assert.Equal(1, mmt.CreatedMocks.Count);
            var mock = mmt.CreatedMocks[0];
            Assert.Equal(1, mock.MessagesSent.Count);

            Assert.Equal(string.Format("Message from NLog on {0}", Environment.MachineName), mock.MessagesSent[0].Subject);
        }
开发者ID:Xharze,项目名称:NLog,代码行数:22,代码来源:MailTargetTests.cs


示例7: MailTargetInitialize_WithoutSpecifiedSmtpServer_should_not_ThrowsConfigException

 public void MailTargetInitialize_WithoutSpecifiedSmtpServer_should_not_ThrowsConfigException()
 {
     var mmt = new MockMailTarget
     {
         From = "[email protected]",
         To = "[email protected]",
         Subject = "Hello from NLog",
         SmtpPort = 27,
         Body = "${level} ${logger} ${message}",
         UseSystemNetMailSettings = true
     };
     mmt.Initialize(null);
 }
开发者ID:NLog,项目名称:NLog,代码行数:13,代码来源:MailTargetTests.cs


示例8: NtlmEmailTest

        public void NtlmEmailTest()
        {
            var mmt = new MockMailTarget
            {
                From = "[email protected]",
                To = "[email protected]",
                SmtpServer = "server1",
                SmtpAuthentication = SmtpAuthenticationMode.Ntlm,
            };

            mmt.Initialize(null);

            var exceptions = new List<Exception>();
            mmt.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "MyLogger", "log message 1").WithContinuation(exceptions.Add));
            Assert.Null(exceptions[0]);

            Assert.Equal(1, mmt.CreatedMocks.Count);

            var mock = mmt.CreatedMocks[0];
            Assert.Equal(CredentialCache.DefaultNetworkCredentials, mock.Credentials);
        }
开发者ID:Xharze,项目名称:NLog,代码行数:21,代码来源:MailTargetTests.cs


示例9: BasicAuthEmailTest

        public void BasicAuthEmailTest()
        {
            try
            {
                var mmt = new MockMailTarget
                {
                    From = "[email protected]",
                    To = "[email protected]",
                    SmtpServer = "server1",
                    SmtpAuthentication = SmtpAuthenticationMode.Basic,
                    SmtpUserName = "${mdc:username}",
                    SmtpPassword = "${mdc:password}",
                };

                mmt.Initialize(null);

                var exceptions = new List<Exception>();
                MappedDiagnosticsContext.Set("username", "u1");
                MappedDiagnosticsContext.Set("password", "p1");
                mmt.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "MyLogger", "log message 1").WithContinuation(exceptions.Add));
                Assert.Null(exceptions[0]);

                Assert.Equal(1, mmt.CreatedMocks.Count);

                var mock = mmt.CreatedMocks[0];
                var credential = mock.Credentials as NetworkCredential;
                Assert.NotNull(credential);
                Assert.Equal("u1", credential.UserName);
                Assert.Equal("p1", credential.Password);
                Assert.Equal(string.Empty, credential.Domain);
            }
            finally
            {
                MappedDiagnosticsContext.Clear();
            }
        }
开发者ID:Xharze,项目名称:NLog,代码行数:36,代码来源:MailTargetTests.cs


示例10: MailTarget_UseSystemNetMailSettings_True_WithVirtualPath

        public void MailTarget_UseSystemNetMailSettings_True_WithVirtualPath()
        {
            var inConfigVal = @"~/App_Data/Mail";
            var mmt = new MockMailTarget(inConfigVal)
            {
                From = "[email protected]",
                To = "[email protected]",
                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);
        }
开发者ID:NLog,项目名称:NLog,代码行数:19,代码来源:MailTargetTests.cs


示例11: ErrorHandlingTest

        public void ErrorHandlingTest()
        {
            var mmt = new MockMailTarget
            {
                From = "[email protected]",
                To = "[email protected]",
                SmtpServer = "${logger}",
                Body = "${message}",
                AddNewLines = true,
            };

            mmt.Initialize(null);

            var exceptions = new List<Exception>();
            var exceptions2 = new List<Exception>();

            mmt.WriteAsyncLogEvents(
                new LogEventInfo(LogLevel.Info, "MyLogger1", "log message 1").WithContinuation(exceptions.Add),
                new LogEventInfo(LogLevel.Debug, "ERROR", "log message 2").WithContinuation(exceptions2.Add),
                new LogEventInfo(LogLevel.Error, "MyLogger1", "log message 3").WithContinuation(exceptions.Add));
            Assert.IsNull(exceptions[0], Convert.ToString(exceptions[0]));
            Assert.IsNull(exceptions[1], Convert.ToString(exceptions[1]));

            Assert.IsNotNull(exceptions2[0]);
            Assert.AreEqual("Some SMTP error.", exceptions2[0].Message);

            // 2 messages are sent, one using MyLogger1.mydomain.com, another using MyLogger2.mydomain.com
            Assert.AreEqual(2, mmt.CreatedMocks.Count);

            var mock1 = mmt.CreatedMocks[0];
            Assert.AreEqual("MyLogger1", mock1.Host);
            Assert.AreEqual(1, mock1.MessagesSent.Count);

            var msg1 = mock1.MessagesSent[0];
            Assert.AreEqual("log message 1\nlog message 3\n", msg1.Body);

            var mock2 = mmt.CreatedMocks[1];
            Assert.AreEqual("ERROR", mock2.Host);
            Assert.AreEqual(1, mock2.MessagesSent.Count);

            var msg2 = mock2.MessagesSent[0];
            Assert.AreEqual("log message 2\n", msg2.Body);
        }
开发者ID:shiggan,项目名称:NLog,代码行数:43,代码来源:MailTargetTests.cs


示例12: MailTarget_UseSystemNetMailSettings_True

        public void MailTarget_UseSystemNetMailSettings_True()
        {
            var inConfigVal = @"C:\config";
            var mmt = new MockMailTarget(inConfigVal)
            {
                From = "[email protected]",
                To = "[email protected]",
                Subject = "Hello from NLog",
                Body = "${level} ${logger} ${message}",
                UseSystemNetMailSettings = true
            };
            mmt.ConfigureMailClient();

            Assert.Equal(mmt.SmtpClientPickUpDirectory, inConfigVal);
        }
开发者ID:NLog,项目名称:NLog,代码行数:15,代码来源:MailTargetTests.cs


示例13: MailTarget_UseSystemNetMailSettings_False_Override_DeliveryMethod_SpecifiedDeliveryMethod

 public void MailTarget_UseSystemNetMailSettings_False_Override_DeliveryMethod_SpecifiedDeliveryMethod()
 {
     var inConfigVal = @"C:\config";
     var mmt = new MockMailTarget(inConfigVal)
     {
         From = "[email protected]",
         To = "[email protected]",
         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);
 }
开发者ID:NLog,项目名称:NLog,代码行数:17,代码来源:MailTargetTests.cs


示例14: MockMailTarget

        public void MailTarget_UseSystemNetMailSettings_False_Override_ThrowsNLogRuntimeException_if_DeliveryMethodNotSpecified()
        {
            var inConfigVal = @"C:\config";
            var mmt = new MockMailTarget(inConfigVal)
            {
                From = "[email protected]",
                To = "[email protected]",
                Subject = "Hello from NLog",
                SmtpPort = 27,
                Body = "${level} ${logger} ${message}",
                PickupDirectoryLocation = @"C:\TEMP",
                UseSystemNetMailSettings = false
            };

            Assert.Throws<NLogRuntimeException>(() => mmt.ConfigureMailClient());
        }
开发者ID:NLog,项目名称:NLog,代码行数:16,代码来源:MailTargetTests.cs


示例15: MailTarget_WithEmptySmtpServer_ThrowsNLogRuntimeException

        public void MailTarget_WithEmptySmtpServer_ThrowsNLogRuntimeException()
        {
            var mmt = new MockMailTarget
            {
                From = "[email protected]",
                To = "[email protected]",
                Subject = "Hello from NLog",
                SmtpServer = "",
                SmtpPort = 27,
                Body = "${level} ${logger} ${message}"
            };
            mmt.Initialize(null);

            var exceptions = new List<Exception>();
            mmt.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "MyLogger", "log message 1").WithContinuation(exceptions.Add));

            Assert.NotNull(exceptions[0]);
            Assert.IsType<NLogRuntimeException>(exceptions[0]);
        }
开发者ID:Xharze,项目名称:NLog,代码行数:19,代码来源:MailTargetTests.cs


示例16: CsvLayoutTest

        public void CsvLayoutTest()
        {
            var layout = new CsvLayout()
            {
                Delimiter = CsvColumnDelimiterMode.Semicolon,
                WithHeader = true,
                Columns =
                {
                    new CsvColumn("name", "${logger}"),
                    new CsvColumn("level", "${level}"),
                    new CsvColumn("message", "${message}"),
                }
            };

            var mmt = new MockMailTarget
            {
                From = "[email protected]",
                To = "[email protected]",
                SmtpServer = "server1",
                AddNewLines = true,
                Layout = layout,
            };

            layout.Initialize(null);

            mmt.Initialize(null);

            var exceptions = new List<Exception>();
            mmt.WriteAsyncLogEvents(
                new LogEventInfo(LogLevel.Info, "MyLogger1", "log message 1").WithContinuation(exceptions.Add),
                new LogEventInfo(LogLevel.Debug, "MyLogger2", "log message 2").WithContinuation(exceptions.Add),
                new LogEventInfo(LogLevel.Error, "MyLogger3", "log message 3").WithContinuation(exceptions.Add));
            Assert.Null(exceptions[0]);

            Assert.Equal(1, mmt.CreatedMocks.Count);

            var mock = mmt.CreatedMocks[0];
            Assert.Equal(1, mock.MessagesSent.Count);
            var msg = mock.MessagesSent[0];
            string expectedBody = "name;level;message\nMyLogger1;Info;log message 1\nMyLogger2;Debug;log message 2\nMyLogger3;Error;log message 3\n";
            Assert.Equal(expectedBody, msg.Body);
        }
开发者ID:Xharze,项目名称:NLog,代码行数:42,代码来源:MailTargetTests.cs


示例17: MailTargetInitialize_WithoutSpecifiedSmtpServer_ThrowsConfigException

 public void MailTargetInitialize_WithoutSpecifiedSmtpServer_ThrowsConfigException()
 {
     var mmt = new MockMailTarget
     {
         From = "[email protected]",
         To = "[email protected]",
         Subject = "Hello from NLog",
         SmtpPort = 27,
         Body = "${level} ${logger} ${message}"
     };
     Assert.Throws<NLogConfigurationException>(() => mmt.Initialize(null));
 }
开发者ID:Xharze,项目名称:NLog,代码行数:12,代码来源:MailTargetTests.cs


示例18: PerMessageAddress

        public void PerMessageAddress()
        {
            var mmt = new MockMailTarget
            {
                From = "[email protected]",
                To = "${logger}@foo.com",
                Body = "${message}",
                SmtpServer = "server1.mydomain.com",
                AddNewLines = true,
            };

            mmt.Initialize(null);

            var exceptions = new List<Exception>();
            mmt.WriteAsyncLogEvents(
                new LogEventInfo(LogLevel.Info, "MyLogger1", "log message 1").WithContinuation(exceptions.Add),
                new LogEventInfo(LogLevel.Debug, "MyLogger2", "log message 2").WithContinuation(exceptions.Add),
                new LogEventInfo(LogLevel.Error, "MyLogger1", "log message 3").WithContinuation(exceptions.Add));
            Assert.Null(exceptions[0]);

            // 2 messages are sent, one using MyLogger1.mydomain.com, another using MyLogger2.mydomain.com
            Assert.Equal(2, mmt.CreatedMocks.Count);

            var mock1 = mmt.CreatedMocks[0];
            Assert.Equal(1, mock1.MessagesSent.Count);

            var msg1 = mock1.MessagesSent[0];
            Assert.Equal("[email protected]", msg1.To[0].Address);
            Assert.Equal("log message 1\nlog message 3\n", msg1.Body);

            var mock2 = mmt.CreatedMocks[1];
            Assert.Equal(1, mock2.MessagesSent.Count);

            var msg2 = mock2.MessagesSent[0];
            Assert.Equal("[email protected]", msg2.To[0].Address);
            Assert.Equal("log message 2\n", msg2.Body);
        }
开发者ID:Xharze,项目名称:NLog,代码行数:37,代码来源:MailTargetTests.cs


示例19: MailTarget_WithNewlineInSubject_SendsMail

        public void MailTarget_WithNewlineInSubject_SendsMail()
        {
            var mmt = new MockMailTarget
            {
                From = "[email protected]",
                To = "[email protected]",
                CC = "[email protected];[email protected]",
                Bcc = "[email protected];[email protected]",
                Subject = "Hello from NLog\n",
                SmtpServer = "server1",
                SmtpPort = 27,
                Body = "${level} ${logger} ${message}"
            };

            mmt.Initialize(null);

            var exceptions = new List<Exception>();
            mmt.WriteAsyncLogEvent(new LogEventInfo(LogLevel.Info, "MyLogger", "log message 1").WithContinuation(exceptions.Add));
            Assert.Null(exceptions[0]);

            Assert.Equal(1, mmt.CreatedMocks.Count);

            var mock = mmt.CreatedMocks[0];
            Assert.Equal(1, mock.MessagesSent.Count);
            var msg = mock.MessagesSent[0];
        }
开发者ID:Xharze,项目名称:NLog,代码行数:26,代码来源:MailTargetTests.cs


示例20: MailTargetInitialize_WithoutSpecifiedFrom_ThrowsConfigException

 public void MailTargetInitialize_WithoutSpecifiedFrom_ThrowsConfigException()
 {
     var mmt = new MockMailTarget
     {
         To = "[email protected]",
         Subject = "Hello from NLog",
         SmtpServer = "server1",
         SmtpPort = 27,
         Body = "${level} ${logger} ${message}",
         UseSystemNetMailSettings = false
     };
     Assert.Throws<NLogConfigurationException>(() => mmt.Initialize(null));
 }
开发者ID:NLog,项目名称:NLog,代码行数:13,代码来源:MailTargetTests.cs



注:本文中的MockMailTarget类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MockMetadataImporter类代码示例发布时间:2022-05-24
下一篇:
C# MockLogger类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap