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


C# EventData.ToXml方法代码示例

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


在下文中一共展示了EventData.ToXml方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AssertMessage

		internal static void AssertMessage(Type from, string[] stack, EventData data, LogLevels level, string expected, Type expectedError)
		{
			DateTime time = DateTime.Now;

			Assert.AreEqual(AppDomain.CurrentDomain.FriendlyName, data.AppDomainName);
			Assert.AreEqual("nunit.core", data.EntryAssembly.ToLower());

			Assert.Less(0, data.EventId);
			Assert.IsTrue(data.EventTime <= DateTime.Now);
			if (!System.Diagnostics.Debugger.IsAttached)
				Assert.IsTrue((time - data.EventTime).TotalMilliseconds < 500);
			if (expectedError == null)
				Assert.IsNull(data.Exception);
			else
				Assert.AreEqual(data.Exception.GetType(), expectedError);
			Assert.Less(0, data.FileColumn, "no FileColumn");
			Assert.Less(0, data.FileLine, "no FileLine");
			Assert.IsTrue(data.FileLocation.Contains(data.FileName));
			Assert.AreEqual(from.Name + ".cs", Path.GetFileName(data.FileName));
			if(expected != null) Assert.IsTrue(data.FullMessage.Contains(expected));
			Assert.IsTrue(data.FullMessage.Contains(data.FileName));
			//ROK - not always available, optimizations can disable
			//Assert.Less(0, data.IlOffset, "no ILOffset");
			Assert.Less(-1, data.IlOffset, "no ILOffset");
			Assert.AreEqual(level, data.Level);
			Assert.IsTrue(data.Location.Contains(String.Format("{0}.{1}(", from.FullName, data.MethodName)));
			if (stack == null)
			{
				Assert.IsNull(data.LogCurrent);
				Assert.IsNull(data.LogStack);
			}
			else
			{
				Assert.AreEqual(stack[stack.Length - 1], data.LogCurrent);
				Assert.AreEqual(String.Join("::", stack), data.LogStack);
			}
			Assert.AreEqual(Thread.CurrentThread.ManagedThreadId, data.ManagedThreadId);
			Assert.AreEqual(Thread.CurrentThread.Name, data.ManagedThreadName);
			if (expected != null) Assert.AreEqual(expected, data.Message);
			Assert.IsTrue(data.Method.StartsWith(from.FullName));
			Assert.IsTrue(data.Method.EndsWith(")"));
			Assert.IsNotNull(data.MethodArgs);
			Assert.AreEqual(from.Assembly.GetName().Name, data.MethodAssembly);
			Assert.AreEqual(from.Assembly.GetName().Version.ToString(), data.MethodAssemblyVersion);
			Assert.IsNotEmpty(data.MethodName);
			Assert.AreEqual(from.FullName, data.MethodType);
			Assert.AreEqual(from.Name, data.MethodTypeName);
			Assert.AreEqual(Log.Config.Output, data.Output);
			Assert.AreEqual(Process.GetCurrentProcess().Id, data.ProcessId);
			Assert.AreEqual("nunit-console", Path.GetFileNameWithoutExtension( data.ProcessName ).ToLower());
			Assert.IsTrue(String.IsNullOrEmpty(data.ThreadPrincipalName));
			
			Assert.IsNotEmpty(data.ToXml());
			new XmlDocument().LoadXml(data.ToXml());

			StringWriter sw = new StringWriter();
			data.Write(sw);
			if (expected != null) Assert.IsTrue(sw.ToString().Contains(expected));

			if (expected != null)
			{
				Assert.AreEqual(expected, data.ToString("{Message}"));
				Assert.AreEqual("!" + expected + "-", data.ToString("{Message:!%s-}"));
				Assert.AreEqual(expected, data.ToString("{Message}{ThreadPrincipalName}"));

				StringWriter wtr = new StringWriter();
				data.Write(wtr, "{Message}");
				Assert.AreEqual(expected, wtr.ToString().Trim());
			}
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:70,代码来源:BasicLogTest.cs


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