/// <summary>
        /// Get test suite folder
        /// </summary>
        /// <param name="type"></param>
        /// <param name="endpoint"></param>
        /// <param name="version"></param>
        /// <returns>Test suite folder</returns>
        private string GetTestSuiteFolder(TestSuiteType type, string endpoint, string version)
        {
            switch (type)
            {
            case TestSuiteType.AD_FAMILY:
            case TestSuiteType.FILE_SERVER:
            case TestSuiteType.KERBEROS:
                break;

            case TestSuiteType.ADOD:
            case TestSuiteType.AZOD:
            case TestSuiteType.BRANCH_CACHE:
                return(TestSuiteFolderFormat.Replace("$(TestSuiteVersion)", version));

            case TestSuiteType.RDP_CLIENT:
            case TestSuiteType.RDP_SERVER:
                return(TestSuiteFolderFormat
                       .Replace("$(TestSuiteVersion)", version)
                       .Replace("$(TestSuiteEndpoint)", endpoint));

            default:
                return(null);
            }
            return(string.Format(TestSuiteFolderFormat, TestSuiteName, endpoint, version));
        }
        /// <summary>
        /// Load configuration file and return TestSuiteDir
        /// </summary>
        /// <returns>TestSuiteDir</returns>
        public string CreateTestSuiteDir(TestSuiteType type)
        {
            XmlDocument doc = new XmlDocument();

            doc.XmlResolver = null;
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.XmlResolver   = null;
            settings.DtdProcessing = DtdProcessing.Prohibit;
            XmlReader xmlReader = XmlReader.Create(TestSuiteIntroXmlPath, settings);

            doc.Load(xmlReader);

            // Get Registry info
            string  registryPath     = null;
            XmlNode registryPathNode = doc.DocumentElement.SelectSingleNode("DefaultRegistryPath");

            if (registryPathNode != null)
            {
                registryPath = registryPathNode.InnerText.Trim();
            }
            else
            {
                throw new InvalidOperationException("DefaultRegistryPath is not found");
            }

            string  registryPath64     = null;
            XmlNode registryPathNode64 = doc.DocumentElement.SelectSingleNode("DefaultRegistryPath64");

            if (registryPathNode64 != null)
            {
                registryPath64 = registryPathNode64.InnerText.Trim();
            }
            else
            {
                throw new InvalidOperationException("DefaultRegistryPath64 is not found");
            }

            bool isFound = false;

            foreach (XmlNode groupXN in doc.DocumentElement.SelectNodes("Group"))
            {
                foreach (XmlNode testSuiteXN in groupXN.SelectNodes("TestSuite"))
                {
                    if (TestSuiteName.Equals(testSuiteXN.Attributes["name"].Value))
                    {
                        TestSuiteFolderFormat = (testSuiteXN.Attributes["folder"] != null) ? testSuiteXN.Attributes["folder"].Value : null;
                        isFound = true;
                        break;
                    }
                }
                if (isFound)
                {
                    break;
                }
            }

            // If TestSuiteFolderFormat is not found in xml file, set it to default TestSuiteFolderFormat
            if (TestSuiteFolderFormat == null)
            {
                TestSuiteFolderFormat = "C:\\MicrosoftProtocolTests\\{0}\\{1}-Endpoint\\{2}";
            }

            RegistryKey HKLM = Registry.LocalMachine;
            RegistryKey TestSuitesRegPath = Environment.Is64BitProcess ?
                                            HKLM.OpenSubKey(registryPath64) : HKLM.OpenSubKey(registryPath);
            string registryKeyName = TestSuitesRegPath.GetSubKeyNames()
                                     .Where((s) => s.Contains(TestSuiteName))
                                     .FirstOrDefault();
            Match  endpointMatch     = Regex.Match(registryKeyName, "(Server)|(Client)");
            string testSuiteEndPoint = endpointMatch.Value;
            Match  versionMatch      = Regex.Match(registryKeyName, "\\d+\\.\\d+\\.\\d+\\.\\d+");
            string testSuiteVersion  = versionMatch.Value;

            return(GetTestSuiteFolder(type, testSuiteEndPoint, testSuiteVersion));
        }
Exemple #3
0
        /// <summary>
        /// Create a new test suite
        /// </summary>
        /// <param name="TeamProjectName"></param>
        /// <param name="TestPlanId"></param>
        /// <param name="TestSuiteName"></param>
        /// <param name="SuiteType"></param>
        /// <param name="ParentPath"></param>
        /// <param name="SuiteQuery"></param>
        /// <param name="RequirementIds"></param>
        /// <returns></returns>
        static bool CreateTestSuite(string TeamProjectName, int TestPlanId, string TestSuiteName = "", TestSuiteType SuiteType = TestSuiteType.StaticTestSuite, string ParentPath = "", string SuiteQuery = "", int RequirementId = 0)
        {
            switch (SuiteType)
            {
            case TestSuiteType.StaticTestSuite: if (TestSuiteName == "")
                {
                    Console.WriteLine("Set the name for the test suite"); return(false);
                }
                break;

            case TestSuiteType.DynamicTestSuite: if (TestSuiteName == "")
                {
                    Console.WriteLine("Set the name for the test suite"); return(false);
                }
                if (SuiteQuery == "")
                {
                    Console.WriteLine("Set the query for the new a suite"); return(false);
                }
                break;

            case TestSuiteType.RequirementTestSuite:
                if (RequirementId == 0)
                {
                    Console.WriteLine("Set the requrement id for the test suite"); return(false);
                }
                break;
            }

            int parentsuiteId = GetParentSuiteId(TeamProjectName, TestPlanId, ParentPath);

            if (parentsuiteId > 0)
            {
                TestSuiteCreateParams newSuite = new TestSuiteCreateParams()
                {
                    Name          = TestSuiteName,
                    SuiteType     = SuiteType,
                    QueryString   = SuiteQuery,
                    RequirementId = RequirementId,
                    ParentSuite   = new TestSuiteReference()
                    {
                        Id = parentsuiteId
                    }
                };

                TestSuite testSuite = TestPlanClient.CreateTestSuiteAsync(newSuite, TeamProjectName, TestPlanId).Result;
                Console.WriteLine("The Test Suite has been created: " + testSuite.Id + " - " + testSuite.Name);
            }
            else
            {
                Console.WriteLine("Can not find the parent test suite"); return(false);
            }

            return(true);
        }
Exemple #4
0
 public TestSuiteAttribute(TestSuiteType testSuiteType = TestSuiteType.Unit)
 {
     TestSuiteType = testSuiteType;
 }