Microsoft.Protocols.TestSuites.Common.Common.GeneratePrefixOfResourceName C# (CSharp) Method

GeneratePrefixOfResourceName() public static method

A method used to generate the prefix of a resource name based on the current test case name. For example, if the current test case name is "MSOXCRPC_S01_TC01_TestEcDoConnectEx", the prefix will be "MSOXCRPC_S01_TC01".
public static GeneratePrefixOfResourceName ( ITestSite site ) : string
site ITestSite An instance of interface ITestSite which provides logging, assertions, /// and adapters for test code onto its execution context.
return string
        public static string GeneratePrefixOfResourceName(ITestSite site)
        {
            string newPrefixOfResourceName = string.Empty;
            if (site != null)
            {
                site.Assume.IsNotNull(site.TestProperties, "The dictionary object 'site.TestProperties' should NOT be null! ");
                site.Assume.IsTrue(site.TestProperties.ContainsKey("CurrentTestCaseName"), "The dictionary object 'site.TestProperties' should contain the key 'CurrentTestCaseName'!");
                site.Assume.IsNotNull(site.DefaultProtocolDocShortName, "The 'site.DefaultProtocolDocShortName' should NOT be null! ");
                string currentTestCaseName = site.TestProperties["CurrentTestCaseName"].ToString();
                string currentProtocolShortName = string.Empty;
                if (site.DefaultProtocolDocShortName.IndexOf("-") >= 0)
                {
                    foreach (string partName in site.DefaultProtocolDocShortName.Split(new char[1] { '-' }))
                    {
                        currentProtocolShortName += partName;
                    }
                }
                else
                {
                        currentProtocolShortName = site.DefaultProtocolDocShortName;
                }

                int startPos = currentTestCaseName.IndexOf(currentProtocolShortName);
                site.Assume.IsTrue(startPos >= 0, "The '{0}' should contain '{1}'!", currentTestCaseName, currentProtocolShortName);
                if (startPos >= 0)
                {
                    currentTestCaseName = currentTestCaseName.Substring(startPos);
                }

                string currentTestScenarioNumber = currentTestCaseName.Split(new char[1] { '_' })[1];
                string currentTestCaseNumber = currentTestCaseName.Split(new char[1] { '_' })[2];
                newPrefixOfResourceName = string.Format(@"{0}_{1}_{2}", currentProtocolShortName, currentTestScenarioNumber, currentTestCaseNumber);
            }

            return newPrefixOfResourceName;
        }
Common