MergeConfigurationFile() public static method

Merge the properties from the specified ptfconfig file.
public static MergeConfigurationFile ( string configFilename, ITestSite site ) : void
configFilename string ptfconfig filename.
site ITestSite An instance of interface ITestSite which provides logging, assertions, /// and adapters for test code onto its execution context.
return void
示例#1
0
        /// <summary>
        /// Merge the properties from the SHOULD/MAY ptfconfig file according to the supported products and specified protocol short name.
        /// </summary>
        /// <param name="supportedProducts">A parameter represents the all supported products.</param>
        /// <param name="supportedProductsRelatedRequirementId">A parameter represents the id of the requirement which specifies the supported products.</param>
        /// <param name="site">An instance of interface ITestSite which provides logging, assertions, and adapters for test code onto its execution context.</param>
        /// <param name="shortName">A parameter represents the current protocol short name. If this parameter is string.empty or null, this method will not use the parameter.</param>
        public static void MergeSHOULDMAYConfig(string[] supportedProducts, int supportedProductsRelatedRequirementId, ITestSite site, string shortName)
        {
            if (null == supportedProducts)
            {
                throw new ArgumentNullException("supportedProducts");
            }

            if (supportedProductsRelatedRequirementId <= 0)
            {
                throw new ArgumentException("The value should be greater than Zero.", "supportedProductsRelatedRequirementId");
            }

            SutVersion currentSutVersion       = Common.GetConfigurationPropertyValue <SutVersion>("SutVersion", site);
            string     currentSutVersionValue  = currentSutVersion.ToString();
            bool       isCurrentSutSupported   = supportedProducts.Any(supportedProduct => supportedProduct.Equals(currentSutVersionValue, StringComparison.OrdinalIgnoreCase));
            string     requirementPropertyName = string.Empty;
            string     actualShortNameValue    = string.Empty;

            if (string.IsNullOrEmpty(shortName))
            {
                requirementPropertyName = string.Format("R{0}Enabled", supportedProductsRelatedRequirementId);
                actualShortNameValue    = site.DefaultProtocolDocShortName;
            }
            else
            {
                requirementPropertyName = string.Format("R{0}Enabled_{1}", supportedProductsRelatedRequirementId, shortName);
                actualShortNameValue    = shortName;
            }

            if (isCurrentSutSupported)
            {
                string shouldMayConfigFilename = string.Format("{0}_{1}_SHOULDMAY.deployment.ptfconfig", actualShortNameValue, currentSutVersionValue);
                Common.MergeConfigurationFile(shouldMayConfigFilename, site);
                site.Log.Add(LogEntryKind.Debug, "Use {0} file for optional requirements configuration", shouldMayConfigFilename);
                bool isExpectedPropertyExist = site.Properties.AllKeys.Any(property => property.Equals(requirementPropertyName, StringComparison.OrdinalIgnoreCase));
                if (!isExpectedPropertyExist)
                {
                    site.Assert.Fail("There should be a property [{0}].", requirementPropertyName);
                }
            }
            else
            {
                // If the current SUT version does not support the protocol, this method add a R***enable property into the properties collection.
                bool isExpectedPropertyExist = site.Properties.AllKeys.Any(property => property.Equals(requirementPropertyName, StringComparison.OrdinalIgnoreCase));
                if (isExpectedPropertyExist)
                {
                    site.Properties[requirementPropertyName] = bool.FalseString;
                }
                else
                {
                    site.Properties.Add(requirementPropertyName, bool.FalseString);
                }
            }
        }