本文整理汇总了C#中Profiler.AddCustomTiming方法的典型用法代码示例。如果您正苦于以下问题:C# Profiler.AddCustomTiming方法的具体用法?C# Profiler.AddCustomTiming怎么用?C# Profiler.AddCustomTiming使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Profiler
的用法示例。
在下文中一共展示了Profiler.AddCustomTiming方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestJsonProfilingStorage
public void TestJsonProfilingStorage()
{
slf4net.LoggerFactory.SetFactoryResolver(new SimpleFactoryResolver(item => Console.WriteLine(item.Message)));
var target = new JsonProfilingStorage(ProfilingStorageBase.Inline);
// save empty result should not throw exception
target.SaveResult(null);
var name = "test";
var stepName = "step1";
var profiler = new Profiler(name, target, new [] { "test", "test2" }) as IProfiler;
var mockParameter = new Mock<IDataParameter>();
mockParameter.Setup(p => p.ParameterName).Returns("p1");
mockParameter.Setup(p => p.Value).Returns(1);
mockParameter.Setup(p => p.Direction).Returns(ParameterDirection.Input);
var mockParameterDBNull = new Mock<IDbDataParameter>();
mockParameterDBNull.Setup(p => p.DbType).Returns(DbType.Binary);
mockParameterDBNull.Setup(p => p.Value).Returns(DBNull.Value);
mockParameterDBNull.Setup(p => p.Direction).Returns(ParameterDirection.Input);
var mockParameterBinary = new Mock<IDataParameter>();
mockParameterBinary.Setup(p => p.DbType).Returns(DbType.Binary);
mockParameterBinary.Setup(p => p.Value).Returns(new byte[100]);
mockParameterBinary.Setup(p => p.Direction).Returns(ParameterDirection.Input);
var mockParameterBinaryTooBig = new Mock<IDbDataParameter>();
mockParameterBinaryTooBig.Setup(p => p.DbType).Returns(DbType.Binary);
mockParameterBinaryTooBig.Setup(p => p.Value).Returns(new byte[0x200 + 1]);
mockParameterBinaryTooBig.Setup(p => p.Direction).Returns(ParameterDirection.Input);
var mockParameterDateTime = new Mock<IDbDataParameter>();
mockParameterDateTime.Setup(p => p.DbType).Returns(DbType.DateTime);
mockParameterDateTime.Setup(p => p.Value).Returns(DateTime.Now);
mockParameterDateTime.Setup(p => p.Direction).Returns(ParameterDirection.Input);
var mockParameterEnum = new Mock<IDbDataParameter>();
mockParameterEnum.Setup(p => p.DbType).Returns(DbType.Int32);
mockParameterEnum.Setup(p => p.Value).Returns(DbType.Boolean);
mockParameterEnum.Setup(p => p.Direction).Returns(ParameterDirection.Input);
var mockParameterXml = new Mock<IDbDataParameter>();
mockParameterXml.Setup(p => p.DbType).Returns(DbType.Xml);
mockParameterXml.Setup(p => p.Value).Returns("<xml />");
mockParameterXml.Setup(p => p.Direction).Returns(ParameterDirection.Input);
var mockParameterCollection = new Mock<IDataParameterCollection>();
mockParameterCollection.Setup(collections => collections.GetEnumerator()).Returns(new IDataParameter[] { mockParameter.Object, mockParameterDBNull.Object, mockParameterBinary.Object, mockParameterBinaryTooBig.Object, mockParameterDateTime.Object, mockParameterEnum.Object, mockParameterXml.Object }.GetEnumerator());
mockParameterCollection.Setup(collection => collection.Count).Returns(1);
var mockCommand = new Mock<IDbCommand>();
mockCommand.Setup(cmd => cmd.CommandText).Returns("test sql");
mockCommand.Setup(cmd => cmd.Parameters).Returns(mockParameterCollection.Object);
var dbTiming = new DbTiming(
profiler, DbExecuteType.Reader, mockCommand.Object);
using (profiler.Step(stepName, null, null))
{
profiler.AddCustomTiming(dbTiming);
profiler.AddCustomTiming(new CustomTiming(profiler, "custom", "custom"));
}
profiler.Stop();
// save normal result should not throw exception
target.SaveResult(profiler);
slf4net.LoggerFactory.Reset();
}