コード例 #1
0
        public override void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string friendlyTestName)
        {
            base.SetTestMethod(generationContext, testMethod, friendlyTestName);
            if (generationContext.CustomData.ContainsKey("featureCategories"))
            {
                var featureCategories = (string[])generationContext.CustomData["featureCategories"];
                CodeDomHelper.AddAttributeForEachValue(testMethod, CATEGORY_ATTR, featureCategories);
            }

            if (generationContext.CustomData.ContainsKey(OWNER_TAG))
            {
                string ownerName = generationContext.CustomData[OWNER_TAG] as string;
                if (!String.IsNullOrEmpty(ownerName))
                {
                    CodeDomHelper.AddAttribute(testMethod, OWNER_ATTR, ownerName);
                }
            }

            if (generationContext.CustomData.ContainsKey(WORKITEM_TAG))
            {
                IEnumerable <int> workItems = generationContext.CustomData[WORKITEM_TAG] as IEnumerable <int>;
                foreach (int workItem in workItems)
                {
                    CodeDomHelper.AddAttribute(testMethod, WORKITEM_ATTR, workItem);
                }
            }

            if (generationContext.CustomData.ContainsKey(DEPLOYMENTITEM_TAG))
            {
                IEnumerable <string> deploymentItems = generationContext.CustomData[DEPLOYMENTITEM_TAG] as IEnumerable <string>;
                foreach (string deploymentItem in deploymentItems)
                {
                    CodeDomHelper.AddAttribute(testMethod, DEPLOYMENTITEM_ATTR, deploymentItem);
                }
            }
        }
コード例 #2
0
 public void SetTestClassCategories(TestClassGenerationContext generationContext, IEnumerable <string> featureCategories)
 {
     CodeDomHelper.AddAttributeForEachValue(generationContext.TestClass, CATEGORY_ATTR, featureCategories);
 }
コード例 #3
0
 public virtual void SetTestMethodCategories(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable <string> scenarioCategories)
 {
     CodeDomHelper.AddAttributeForEachValue(testMethod, CATEGORY_ATTR, scenarioCategories);
 }
コード例 #4
0
 public void SetTestClassCategories(TestClassGenerationContext generationContext, IEnumerable <string> featureCategories)
 {
     _codeDomHelper.AddAttributeForEachValue(generationContext.TestClass, "NUnit.Framework.CategoryAttribute", featureCategories);
 }
コード例 #5
0
        public override void SetTestClassCategories(TestClassGenerationContext generationContext, IEnumerable <string> featureCategories)
        {
            var categories = featureCategories.ToArray();

            CodeDomHelper.AddAttributeForEachValue(generationContext.TestClass, TAG_ATTR, categories);
        }
コード例 #6
0
        public void SetTestMethodCategories(TestClassGenerationContext generationContext,
                                            CodeMemberMethod testMethod, IEnumerable <string> scenarioCategories)
        {
            var categories = scenarioCategories as IList <string> ?? scenarioCategories.ToList();

            _codeDomHelper.AddAttributeForEachValue(testMethod, CategoryAttr,
                                                    categories.Where(cat => !cat.StartsWith("Browser:") && !cat.Contains(":")));

            var categoryTags = new Dictionary <string, List <string> >();

            var hasTags = false;


            foreach (var tag in categories.Where(cat => cat.Contains(":")).Select(cat => cat.Split(':')))
            {
                if (tag.Length != 2)
                {
                    continue;
                }
                hasTags = true;
                if (tag[0].Equals("Browser", StringComparison.OrdinalIgnoreCase))
                {
                    _hasBrowser = true;
                }
                testMethod.UserData.Add(tag[0] + ":" + tag[1], tag[1]);
                List <string> tagValues;
                if (!categoryTags.TryGetValue(tag[0], out tagValues))
                {
                    tagValues            = new List <string>();
                    categoryTags[tag[0]] = tagValues;
                }
                tagValues.Add(tag[1]);
            }

            if (hasTags)
            {
                //TestName and TestCategory Building
                //List of list of tags different values
                var values = new List <List <string> >();
                foreach (var kvp in categoryTags)
                {
                    values.Add(kvp.Value);
                }
                var combinations = new List <List <string> >();
                //Generate an exhaustive list of values combinations
                GeneratePermutations(values, combinations, 0, new List <string>());

                foreach (var combination in combinations)
                {
                    //Each combination is a different TestCase
                    var withTagArgs =
                        combination.Select(s => new CodeAttributeArgument(new CodePrimitiveExpression(s))).ToList()
                        .Concat(new[]
                    {
                        new CodeAttributeArgument("Category",
                                                  new CodePrimitiveExpression(string.Join(",", combination))),
                        new CodeAttributeArgument("TestName",
                                                  new CodePrimitiveExpression(
                                                      $"{testMethod.Name} with {string.Join(",", combination)}"))
                    })
                        .ToArray();

                    _codeDomHelper.AddAttribute(testMethod, RowAttr, withTagArgs);
                }

                var i = 0;

                var orderedTags = new List <string>();
                foreach (var kvp in categoryTags)
                {
                    //Add the category name to category list
                    orderedTags.Add(kvp.Key);
                    //Mark the field to be generated
                    _fieldsToGenerate.Add(kvp.Key);
                    //Add a parameter to the testMethod
                    testMethod.Parameters.Insert(i,
                                                 new CodeParameterDeclarationExpression("System.String",
                                                                                        kvp.Key.ToLowerInvariant()));
                    i = i + 1;
                }

                var methodName             = "InitializeSelenium" + string.Join("", orderedTags);
                var initializeSeleniumArgs = string.Join(",", orderedTags).ToLowerInvariant();
                //Create the call to the initialization Method
                testMethod.Statements.Insert(0,
                                             new CodeSnippetStatement(methodName + "(" + initializeSeleniumArgs + ");"));
                List <string> nothing;
                if (!_initializeMethodsToGenerate.TryGetValue(methodName, out nothing))
                {
                    _initializeMethodsToGenerate[methodName] = orderedTags.Select(s => s.ToLowerInvariant()).ToList();
                }
            }
        }
コード例 #7
0
 public void SetTestClassCategories(TestClassGenerationContext generationContext, IEnumerable <string> featureCategories)
 {
     //NUnit
     CodeDomHelper.AddAttributeForEachValue(generationContext.TestClass, CATEGORY_ATTR, featureCategories);
     //MsTest does not support caregories... :(
 }