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


C# TestContext.AddResultFile方法代码示例

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


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

示例1: AssertLogFileExists

        private static string AssertLogFileExists(string dummyBinDir, string exeName, TestContext testContext)
        {
            string logFilePath = GetLogFilePath(dummyBinDir, exeName);

            Assert.IsTrue(File.Exists(logFilePath), "Expecting the dummy exe log to exist. File: {0}", logFilePath);
            testContext.AddResultFile(logFilePath);
            return logFilePath;
        }
开发者ID:BrightLight,项目名称:sonar-msbuild-runner,代码行数:8,代码来源:DummyExeHelper.cs

示例2: ReturnsValidHtml

        /// <summary>
        /// Determines whether the ASP.NET page returns valid HTML by checking the response against the W3C Markup Validator.
        /// </summary>
        /// <param name="testContext">The test context.</param>
        /// <returns>
        /// An object representing indicating whether the HTML generated is valid.
        /// </returns>
        public static W3CValidityCheckResult ReturnsValidHtml(TestContext testContext)
        {
            var result = new W3CValidityCheckResult();
            WebHeaderCollection w3cResponseHeaders = new WebHeaderCollection();

            using (var webClient = new WebClient())
            {
                string html = GetPageHtml(webClient, testContext.RequestedPage.Request.Url);

                // Send to W3C validator
                string w3cUrl = "http://validator.w3.org/check";
                webClient.Encoding = System.Text.Encoding.UTF8;

                var values = new NameValueCollection();
                values.Add("fragment", html);
                values.Add("prefill", "0");
                values.Add("group", "0");
                values.Add("doctype", "inline");

                try
                {
                    _w3cValidatorBlock.WaitOne();
                    byte[] w3cRawResponse = webClient.UploadValues(w3cUrl, values);
                    result.Body = Encoding.UTF8.GetString(w3cRawResponse);
                    w3cResponseHeaders.Add(webClient.ResponseHeaders);

                    String responsePath = Path.Combine(Directory.GetCurrentDirectory(),
                            String.Format("{0}.html", testContext.TestName));

                    FileStream responseStream = new FileStream(responsePath, FileMode.CreateNew);

                    responseStream.Write(w3cRawResponse, 0, w3cRawResponse.Length);
                    responseStream.Close();

                    testContext.AddResultFile(responsePath);
                }
                finally
                {
                    ThreadPool.QueueUserWorkItem(ResetBlocker); // Reset on background thread
                }
            }

            // Extract result from response headers
            int warnings = -1;
            int errors = -1;
            int.TryParse(w3cResponseHeaders["X-W3C-Validator-Warnings"], out warnings);
            int.TryParse(w3cResponseHeaders["X-W3C-Validator-Errors"], out errors);
            string status = w3cResponseHeaders["X-W3C-Validator-Status"];

            result.WarningsCount = warnings;
            result.ErrorsCount = errors;
            result.IsValid = (!String.IsNullOrEmpty(status) && status.Equals("Valid", StringComparison.InvariantCultureIgnoreCase));

            return result;
        }
开发者ID:davidebbo-test,项目名称:FarmersMarket-1.0,代码行数:62,代码来源:TestHelper.cs

示例3: CreateInitializedProjectRoot

        /// <summary>
        /// Creates a project file on disk from the specified descriptor.
        /// Sets the SonarQube output folder property, if specified.
        /// </summary>
        public static ProjectRootElement CreateInitializedProjectRoot(TestContext testContext, ProjectDescriptor descriptor, IDictionary<string, string> preImportProperties)
        {
            if (testContext == null)
            {
                throw new ArgumentNullException("testContext");
            }
            if (descriptor == null)
            {
                throw new ArgumentNullException("descriptor");
            }
            
            ProjectRootElement projectRoot = BuildUtilities.CreateAnalysisProject(testContext, descriptor, preImportProperties);

            projectRoot.ToolsVersion = MSBuildToolsVersionForTestProjects;

            projectRoot.Save(descriptor.FullFilePath);

            testContext.AddResultFile(descriptor.FullFilePath);
            return projectRoot;
        }
开发者ID:BrightLight,项目名称:sonar-msbuild-runner,代码行数:24,代码来源:BuildUtilities.cs

示例4: Initialize

        public static void Initialize(TestContext context)
        {
            Context = context;

            //各ブラウザ向けImporterの動作確認結果を一覧として出力させる。
            LogWriter = new System.IO.StreamWriter(
                context.TestRunDirectory + @"\checkLog.txt", false, System.Text.Encoding.UTF8);
            Context.AddResultFile("checkLog.txt");
            
            //Blink用のテストデータ生成
            System.IO.Directory.CreateDirectory(@".\TestDatas");
            System.IO.File.Delete(@"TestDatas\blinkCookies.sqlite3");
            var dbClient = new SQLiteConnection(@"Data Source=TestDatas\blinkCookies.sqlite3");
            try
            {
                dbClient.Open();
                var query = dbClient.CreateCommand();
                query.CommandText = SQLITE_QUERY_CREATE_TABLE_COOKIES;
                query.ExecuteNonQuery();

                query = dbClient.CreateCommand();
                query.CommandText = SQLITE_QUERY_CREATE_TABLE_META;
                query.ExecuteNonQuery();

                foreach (var item in SqliteInsertQueries.Select((item, idx) => new { CommandText = item, Index = idx }))
                {
                    var param = new SQLiteParameter("@encryptData", System.Data.DbType.Binary)
                    {
                        Value = Win32Api.CryptProtectedData(
                            System.Text.Encoding.UTF8.GetBytes(string.Format("binary_data{0:00000}", (item.Index + 1) * 10000 + 10))),
                    };
                    query = dbClient.CreateCommand();
                    query.CommandText = string.Format(item.CommandText,
                        (Utility.DateTimeToUnixTime(DateTime.UtcNow.AddYears(1)) + 11644473600) * 1000000);
                    query.Parameters.Add(param);
                    query.ExecuteNonQuery();
                }
            }
            finally
            { dbClient.Close(); }
        }
开发者ID:rokugasenpai,项目名称:SnkLib.App.CookieGetter,代码行数:41,代码来源:SimpleTests.cs

示例5: CreateAnalysisProject

        /// <summary>
        /// Creates and returns an empty MSBuild project using the data in the supplied descriptor.
        /// The project will import the SonarQube analysis targets file and the standard C# targets file.
        /// The project name and GUID will be set if the values are supplied in the descriptor.
        /// </summary>
        private static ProjectRootElement CreateAnalysisProject(TestContext testContext, ProjectDescriptor descriptor,
            IDictionary<string, string> preImportProperties)
        {
            if (testContext == null)
            {
                throw new ArgumentNullException("testContext");
            }
            if (descriptor == null)
            {
                throw new ArgumentNullException("descriptor");
            }

            string sqTargetFile = TestUtils.EnsureAnalysisTargetsExists(testContext);
            Assert.IsTrue(File.Exists(sqTargetFile), "Test error: the SonarQube analysis targets file could not be found. Full path: {0}", sqTargetFile);
            testContext.AddResultFile(sqTargetFile);

            IDictionary<string, string> properties = preImportProperties ?? new Dictionary<string, string>();

            // Disable the standard "ImportBefore/ImportAfter" behaviour if the caller
            // hasn't defined what they want to happen explicitly
            if (!properties.ContainsKey(StandardImportBeforePropertyName))
            {
                DisableStandardTargetsWildcardImporting(properties);
            }

            ProjectRootElement root = CreateMinimalBuildableProject(properties, descriptor.IsVbProject, sqTargetFile);

            // Set the location of the task assembly
            if (!properties.ContainsKey(TargetProperties.SonarBuildTasksAssemblyFile))
            {
                root.AddProperty(TargetProperties.SonarBuildTasksAssemblyFile, typeof(WriteProjectInfoFile).Assembly.Location);
            }

            if (descriptor.ProjectGuid != Guid.Empty)
            {
                root.AddProperty(TargetProperties.ProjectGuid, descriptor.ProjectGuid.ToString("D"));
            }

            foreach (ProjectDescriptor.FileInProject file in descriptor.Files)
            {
                root.AddItem(file.ItemGroup, file.FilePath);
            }

            if (descriptor.IsTestProject && !root.Properties.Any(p => string.Equals(p.Name, TargetProperties.SonarQubeTestProject)))
            {
                root.AddProperty(TargetProperties.SonarQubeTestProject, "true");
            }

            return root;
        }
开发者ID:BrightLight,项目名称:sonar-msbuild-runner,代码行数:55,代码来源:BuildUtilities.cs

示例6: CreateProjectFromTemplate

        /// <summary>
        /// Creates and returns a new MSBuild project using the supplied template
        /// </summary>
        public static ProjectRootElement CreateProjectFromTemplate(string projectFilePath, TestContext testContext, string templateXml, params object[] args)
        {
            string projectXml = templateXml;
            if (args != null && args.Any())
            {
                projectXml = string.Format(System.Globalization.CultureInfo.CurrentCulture, templateXml, args);
            }

            File.WriteAllText(projectFilePath, projectXml);
            testContext.AddResultFile(projectFilePath);

            ProjectRootElement projectRoot = ProjectRootElement.Open(projectFilePath);
            return projectRoot;
        }
开发者ID:BrightLight,项目名称:sonar-msbuild-runner,代码行数:17,代码来源:BuildUtilities.cs

示例7: AssertLogFileExists

 public static string AssertLogFileExists(string logFilePath, TestContext testContext)
 {
     Assert.IsTrue(File.Exists(logFilePath), "Expecting the dummy exe log to exist. File: {0}", logFilePath);
     testContext.AddResultFile(logFilePath);
     return logFilePath;
 }
开发者ID:HSAR,项目名称:sonar-msbuild-runner,代码行数:6,代码来源:DummyExeHelper.cs


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