當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。