当前位置: 首页>>代码示例>>C#>>正文


C# MockMailTarget.WriteAsyncLogEvent方法代码示例

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


在下文中一共展示了MockMailTarget.WriteAsyncLogEvent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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]", 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_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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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


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