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


C# Profiler.Step方法代码示例

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


在下文中一共展示了Profiler.Step方法的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();
        }
开发者ID:volkd,项目名称:nanoprofiler,代码行数:59,代码来源:JsonDataProfilingStorageTest.cs


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