예제 #1
0
        private static async Task <Dictionary <string, XUnitTestAssembly> > GetTestUrls(string jsonUrl, Dictionary <string, XUnitTestAssembly> testDefinitions = null, bool runAllTests = false)
        {
            if (httpClient is null)
            {
                httpClient = new HttpClient();
            }

            Debug.Assert(runAllTests || testDefinitions != null);
            // Set up the json stream reader
            using (var responseStream = await httpClient.GetStreamAsync(jsonUrl))
                using (var streamReader = new StreamReader(responseStream))
                    using (var jsonReader = new JsonTextReader(streamReader))
                    {
                        // Manual parsing - we only need to key-value pairs from each object and this avoids deserializing all of the work items into objects
                        string markedTestName      = string.Empty;
                        string currentPropertyName = string.Empty;

                        while (jsonReader.Read())
                        {
                            if (jsonReader.Value != null)
                            {
                                switch (jsonReader.TokenType)
                                {
                                case JsonToken.PropertyName:
                                    currentPropertyName = jsonReader.Value.ToString();
                                    break;

                                case JsonToken.String:
                                    if (currentPropertyName.Equals("WorkItemId"))
                                    {
                                        string currentTestName = jsonReader.Value.ToString();

                                        if (runAllTests || testDefinitions.ContainsKey(currentTestName))
                                        {
                                            markedTestName = currentTestName;
                                        }
                                    }
                                    else if (currentPropertyName.Equals("PayloadUri") && markedTestName != string.Empty)
                                    {
                                        if (!testDefinitions.ContainsKey(markedTestName))
                                        {
                                            testDefinitions[markedTestName] = new XUnitTestAssembly()
                                            {
                                                Name = markedTestName
                                            };
                                        }
                                        testDefinitions[markedTestName].Url = jsonReader.Value.ToString();
                                        markedTestName = string.Empty;
                                    }
                                    break;
                                }
                            }
                        }
                    }
            return(testDefinitions);
        }
        public void GenerateRSPFile(XUnitTestAssembly testDefinition, string outputPath)
        {
            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }
            string rspFilePath = Path.Combine(outputPath, testDefinition.Name + ".rsp");

            if (File.Exists(rspFilePath))
            {
                File.Delete(rspFilePath);
            }


            using (StreamWriter sr = File.CreateText(rspFilePath))
            {
                if (testDefinition.Exclusions == null)
                {
                    return;
                }

                // Method exclusions
                if (testDefinition.Exclusions.Methods != null)
                {
                    foreach (Exclusion exclusion in testDefinition.Exclusions.Methods)
                    {
                        if (String.IsNullOrWhiteSpace(exclusion.Name))
                        {
                            continue;
                        }
                        sr.Write("-skipmethod ");
                        sr.Write(exclusion.Name);
                        sr.WriteLine();
                    }
                }

                // Class exclusions
                if (testDefinition.Exclusions.Classes != null)
                {
                    foreach (Exclusion exclusion in testDefinition.Exclusions.Classes)
                    {
                        if (String.IsNullOrWhiteSpace(exclusion.Name))
                        {
                            continue;
                        }
                        sr.Write("-skipclass ");
                        sr.Write(exclusion.Name);
                        sr.WriteLine();
                    }
                }

                // Namespace exclusions
                if (testDefinition.Exclusions.Namespaces != null)
                {
                    foreach (Exclusion exclusion in testDefinition.Exclusions.Namespaces)
                    {
                        if (String.IsNullOrWhiteSpace(exclusion.Name))
                        {
                            continue;
                        }
                        sr.Write("-skipnamespace ");
                        sr.Write(exclusion.Name);
                        sr.WriteLine();
                    }
                }
            }
        }