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


C# ITestContext.WriteLine方法代码示例

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


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

示例1: Test

        public void Test(ITestContext context)
        {
            var options = new ConnectionOptions();
            var scope = new ManagementScope(@"\\localhost\root\cimv2", options);
            scope.Connect();
            var query = new SelectQuery("Select * from Win32_LogicalDisk");

            var searcher = new ManagementObjectSearcher(scope, query);
            var queryCollection = searcher.Get();

            var fail = false;
            var warning = false;
            foreach (var managementBaseObject in queryCollection)
            {
                if (managementBaseObject["DeviceID"] != null && managementBaseObject["FreeSpace"] != null && managementBaseObject["Size"] != null)
                {
                    var driveLetter = managementBaseObject["DeviceID"].ToString();
                    var freeSpace = long.Parse(managementBaseObject["FreeSpace"].ToString());
                    var totalSpace = long.Parse(managementBaseObject["Size"].ToString());

                    var percentageFree = (freeSpace / (double)totalSpace) * 100;
                    var critical = percentageFree <= 2;
                    var low = percentageFree > 2 && percentageFree < 5;
                    context.WriteLine(
                        string.Format(
                            InfoMessages.DriveSpace,
                            driveLetter,
                            this.GetBytesFormatted(freeSpace),
                            this.GetBytesFormatted(totalSpace)),
                        critical ? EventType.Error : (low ? EventType.Warning : EventType.Success));
                    if (critical)
                    {
                        fail = true;
                    }
                    else if (low)
                    {
                        warning = true;
                    }
                }
            }

            if (fail)
            {
                Assert.Fails(Errors.VeryLowSpace);
            }
            else if (warning)
            {
                Assert.PassWithWarning(Errors.LowSpace);
            }
        }
开发者ID:ChrisBriggsy,项目名称:SSW.HealthCheck,代码行数:50,代码来源:DiskSpaceTest.cs

示例2: Test

        public void Test(ITestContext context)
        {
            var failedChecks = new System.Collections.Concurrent.ConcurrentBag<SqlDeployResult>();
            var databasesCount = this.sqlDeploy.Settings.Databases.Count();
            var processedCount = 0;
            var databases = this.sqlDeploy.Settings.Databases.ToList();
            context.UpdateProgress(0, processedCount, databasesCount);
            Parallel.ForEach(
                databases,
                database =>
                {
                    var csBuilder = new SqlConnectionStringBuilder(database.ConnectionString);
                    var dbName = csBuilder.InitialCatalog;
                    var upToDate = database.Status.IsUpToDate;
                    try
                    {
                        var reconcileResult = this.sqlDeploy.ReconcileDatabase(database.DatabaseName);
                        if (upToDate && reconcileResult.IsSuccessful)
                        {
                            context.WriteLine(EventType.Success, Titles.DbIsUpToDate, dbName);
                        }
                        else
                        {
                            if (!upToDate)
                            {
                                context.WriteLine(
                                    EventType.Error,
                                    Titles.DbCheckFailed,
                                    dbName,
                                    Titles.SchemaNotUpToDate);
                                var result = new SqlDeployResult
                                                 {
                                                     IsSuccessful = false,
                                                     DatabaseName = dbName,
                                                     Exceptions =
                                                         new List<Exception>
                                                             {
                                                                 new Exception(
                                                                     Titles
                                                                     .SchemaNotUpToDate)
                                                             }
                                                 };
                                failedChecks.Add(result);
                            }
                            else
                            {
                                context.WriteLine(EventType.Error, Titles.DbCheckFailed, dbName, Titles.SchemaChanged);
                                failedChecks.Add(reconcileResult);
                            }
                        }
                    }
                    catch (SqlException ex)
                    {
                        context.WriteLine(
                                    EventType.Error,
                                    Titles.DbCheckFailed,
                                    dbName,
                                    ex.Message);
                                var result = new SqlDeployResult
                                                 {
                                                     IsSuccessful = false,
                                                     DatabaseName = dbName,
                                                     Exceptions =
                                                         new List<Exception>
                                                             {
                                                                 new Exception(ex.Message)
                                                             }
                                                 };
                                failedChecks.Add(result);
                    }

                    processedCount++;
                    context.UpdateProgress(0, processedCount, databasesCount);
                });
            
            if (failedChecks.Any())
            {
                var msg = string.Format(Titles.DbsNotUpToDate, string.Join(", ", failedChecks.Select(x => x.DatabaseName).ToArray()));
                Assert.Fails(msg);
            }
        }
开发者ID:ChrisBriggsy,项目名称:SSW.HealthCheck,代码行数:81,代码来源:SQLDeployTest.cs


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