public override void SetTestMethodIgnore(TestClassGenerationContext generationContext, CodeMemberMethod testMethod)
        {
            var factAttr = testMethod.CustomAttributes.OfType<CodeAttributeDeclaration>()
                .FirstOrDefault(codeAttributeDeclaration => codeAttributeDeclaration.Name == FACT_ATTRIBUTE);

            if (factAttr != null)
            {
                // set [FactAttribute(Skip="reason")]
                factAttr.Arguments.Add
                    (
                        new CodeAttributeArgument(FACT_ATTRIBUTE_SKIP_PROPERTY_NAME, new CodePrimitiveExpression(SKIP_REASON))
                    );
            }

            var theoryAttr = testMethod.CustomAttributes.OfType<CodeAttributeDeclaration>()
                .FirstOrDefault(codeAttributeDeclaration => codeAttributeDeclaration.Name == THEORY_ATTRIBUTE);

            if (theoryAttr != null)
            {
                // set [TheoryAttribute(Skip="reason")]
                theoryAttr.Arguments.Add
                    (
                        new CodeAttributeArgument(THEORY_ATTRIBUTE_SKIP_PROPERTY_NAME, new CodePrimitiveExpression(SKIP_REASON))
                    );
            }
        }
        public override void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle)
        {
            CodeDomHelper.AddAttribute(testMethod, THEORY_ATTRIBUTE);

            SetProperty(testMethod, FEATURE_TITLE_PROPERTY_NAME, generationContext.Feature.Name);
            SetDescription(testMethod, scenarioTitle);
        }
		public override void SetTestMethodCategories(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable<string> scenarioCategories)
		{
			IEnumerable<string> tags = scenarioCategories.ToList();

			IEnumerable<string> ownerTags = tags.Where(t => t.StartsWith(OWNER_TAG, StringComparison.InvariantCultureIgnoreCase)).Select(t => t);
			if(ownerTags.Any())
			{
				string ownerName = ownerTags.Select(t => t.Substring(OWNER_TAG.Length).Trim('\"')).FirstOrDefault();
				if(!String.IsNullOrEmpty(ownerName))
				{
					CodeDomHelper.AddAttribute(testMethod, OWNER_ATTR, ownerName);
				}
			}

			IEnumerable<string> workitemTags = tags.Where(t => t.StartsWith(WORKITEM_TAG, StringComparison.InvariantCultureIgnoreCase)).Select(t => t);
			if(workitemTags.Any())
			{
				int temp;
				IEnumerable<string> workitemsAsStrings = workitemTags.Select(t => t.Substring(WORKITEM_TAG.Length).Trim('\"'));
				IEnumerable<int> workitems = workitemsAsStrings.Where(t => int.TryParse(t, out temp)).Select(t => int.Parse(t));
				foreach(int workitem in workitems)
				{
					CodeDomHelper.AddAttribute(testMethod, WORKITEM_ATTR, workitem);
				}
			}

			CodeDomHelper.AddAttributeForEachValue(testMethod, CATEGORY_ATTR, GetNonMSTestSpecificTags(tags));
		}
		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);
				}
			}
		}
        public override void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle)
        {
            base.SetTestMethod(generationContext, testMethod, scenarioTitle);

            if (generationContext.GenerateAsynchTests)
                SetupAsyncTest(testMethod);
        }
        public override void FinalizeTestClass(TestClassGenerationContext generationContext)
        {
            base.FinalizeTestClass(generationContext);

            if (generationContext.GenerateAsynchTests)
                SetupAsyncTestClass(generationContext);
        }
Ejemplo n.º 7
0
 protected virtual void FixTestRunOrderingIssue(TestClassGenerationContext generationContext)
 {
     //see https://github.com/techtalk/SpecFlow/issues/96
     generationContext.TestInitializeMethod.Statements.Add(
         new CodeConditionStatement(
             new CodeBinaryOperatorExpression(
                 new CodeBinaryOperatorExpression(
                     new CodePropertyReferenceExpression(
                         new CodeTypeReferenceExpression(typeof (FeatureContext)),
                         "Current"),
                     CodeBinaryOperatorType.IdentityInequality,
                     new CodePrimitiveExpression(null)),
                 CodeBinaryOperatorType.BooleanAnd,
                 new CodeBinaryOperatorExpression(
                     new CodePropertyReferenceExpression(
                         new CodePropertyReferenceExpression(
                             new CodePropertyReferenceExpression(
                                 new CodeTypeReferenceExpression(typeof (FeatureContext)),
                                 "Current"),
                             "FeatureInfo"),
                         "Title"),
                     CodeBinaryOperatorType.IdentityInequality,
                     new CodePrimitiveExpression(generationContext.Feature.Title))),
             new CodeExpressionStatement(
                 new CodeMethodInvokeExpression(
                     new CodeTypeReferenceExpression(
                         generationContext.Namespace.Name + "." + generationContext.TestClass.Name
                         ),
                     generationContext.TestClassInitializeMethod.Name,
                     new CodePrimitiveExpression(null)))));
 }
        public void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable<string> arguments, IEnumerable<string> tags, bool isIgnored)
        {
            var args = arguments.Select(
              arg => new CodeAttributeArgument(new CodePrimitiveExpression(arg))).ToList();

            // addressing ReSharper bug: TestCase attribute with empty string[] param causes inconclusive result - https://github.com/techtalk/SpecFlow/issues/116
            bool hasExampleTags = tags.Any();
            var exampleTagExpressionList = tags.Select(t => new CodePrimitiveExpression(t));
            CodeExpression exampleTagsExpression = hasExampleTags ?
                (CodeExpression)new CodePrimitiveExpression(null) :
                new CodeArrayCreateExpression(typeof(string[]), exampleTagExpressionList.ToArray());
            args.Add(new CodeAttributeArgument(exampleTagsExpression));

            // adds 'Category' named parameter so that NUnit also understands that this test case belongs to the given categories
            if (hasExampleTags)
            {
                CodeExpression exampleTagsStringExpr = new CodePrimitiveExpression(string.Join(",", tags.ToArray()));
                args.Add(new CodeAttributeArgument("Category", exampleTagsStringExpr));
            }

            if (isIgnored)
                args.Add(new CodeAttributeArgument("Ignored", new CodePrimitiveExpression(true)));

            CodeDomHelper.AddAttribute(testMethod, ROW_ATTR, args.ToArray());
        }
        public void SetTestClassInitializeMethod(TestClassGenerationContext generationContext)
        {
            // xUnit uses IUseFixture<T> on the class

            generationContext.TestClassInitializeMethod.Attributes |= MemberAttributes.Static;

            _currentFixtureDataTypeDeclaration = CodeDomHelper.CreateGeneratedTypeDeclaration("FixtureData");
            generationContext.TestClass.Members.Add(_currentFixtureDataTypeDeclaration);

            var fixtureDataType =
                CodeDomHelper.CreateNestedTypeReference(generationContext.TestClass, _currentFixtureDataTypeDeclaration.Name);
            
            var useFixtureType = new CodeTypeReference(IUSEFIXTURE_INTERFACE, fixtureDataType);
            CodeDomHelper.SetTypeReferenceAsInterface(useFixtureType);

            generationContext.TestClass.BaseTypes.Add(useFixtureType);

            // public void SetFixture(T) { } // explicit interface implementation for generic interfaces does not work with codedom

            CodeMemberMethod setFixtureMethod = new CodeMemberMethod();
            setFixtureMethod.Attributes = MemberAttributes.Public;
            setFixtureMethod.Name = "SetFixture";
            setFixtureMethod.Parameters.Add(new CodeParameterDeclarationExpression(fixtureDataType, "fixtureData"));
            setFixtureMethod.ImplementationTypes.Add(useFixtureType);
            generationContext.TestClass.Members.Add(setFixtureMethod);

            // public <_currentFixtureTypeDeclaration>() { <fixtureSetupMethod>(); }
            CodeConstructor ctorMethod = new CodeConstructor();
            ctorMethod.Attributes = MemberAttributes.Public;
            _currentFixtureDataTypeDeclaration.Members.Add(ctorMethod);
            ctorMethod.Statements.Add(
                new CodeMethodInvokeExpression(
                    new CodeTypeReferenceExpression(new CodeTypeReference(generationContext.TestClass.Name)),
                    generationContext.TestClassInitializeMethod.Name));
        }
Ejemplo n.º 10
0
        public virtual void SetTestClassInitializeMethod(TestClassGenerationContext generationContext)
        {
            generationContext.TestClassInitializeMethod.Attributes |= MemberAttributes.Static;
            generationContext.TestClassInitializeMethod.Parameters.Add(new CodeParameterDeclarationExpression(
                TESTCONTEXT_TYPE, "testContext"));

            CodeDomHelper.AddAttribute(generationContext.TestClassInitializeMethod, TESTFIXTURESETUP_ATTR);
        }
Ejemplo n.º 11
0
        public virtual void SetTestInitializeMethod(TestClassGenerationContext generationContext)
        {
            CodeDomHelper.AddAttribute(generationContext.TestInitializeMethod, TESTSETUP_ATTR);

            //if (FeatureContext.Current != null && FeatureContext.Current.FeatureInfo.Title != "<current_feature_title>")
            //  <TestClass>.<TestClassInitialize>(null);

            FixTestRunOrderingIssue(generationContext);
        }
 public override void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle)
 {
     base.SetTestMethod(generationContext, testMethod, scenarioTitle);
     if (generationContext.CustomData.ContainsKey("featureCategories"))
     {
         var featureCategories = (string[])generationContext.CustomData["featureCategories"];
         CodeDomHelper.AddAttributeForEachValue(testMethod, CATEGORY_ATTR, featureCategories);
     }
 }
        public override void SetTestInitializeMethod(TestClassGenerationContext generationContext)
        {
            base.SetTestInitializeMethod(generationContext);

            // SenarioContext.Current.SetTestInstance(this);
            var scenarioContext = new CodeTypeReferenceExpression("ScenarioContext");
            var currentContext = new CodePropertyReferenceExpression(scenarioContext, "Current");
            var scenarioContextExtensions = new CodeTypeReferenceExpression("ScenarioContextExtensions");
            var setTestInstance = new CodeMethodInvokeExpression(scenarioContextExtensions, "SetTestInstance",
                currentContext, new CodeThisReferenceExpression());

            // Add it to ScenarioSetup
            generationContext.ScenarioInitializeMethod.Statements.Add(new CodeExpressionStatement(setTestInstance));
        }
Ejemplo n.º 14
0
        public virtual void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable<string> arguments, IEnumerable<string> tags, bool isIgnored)
        {
            //TODO: better handle "ignored"
            if (isIgnored)
                return;

            var args = arguments.Select(
              arg => new CodeAttributeArgument(new CodePrimitiveExpression(arg))).ToList();

            args.Add(
                new CodeAttributeArgument(
                    new CodeArrayCreateExpression(typeof(string[]), tags.Select(t => new CodePrimitiveExpression(t)).ToArray())));

            CodeDomHelper.AddAttribute(testMethod, INLINEDATA_ATTRIBUTE, args.ToArray());
        }
        private void SetupAsyncTestClass(TestClassGenerationContext generationContext)
        {
            generationContext.TestClass.BaseTypes.Add(new CodeTypeReference(ASYNCTEST_INTERFACE));

            //AsyncTestRunner.RegisterAsyncTestExecutor(testRunner, new TechTalk.SpecFlow.Async.SilverlightAsyncTestExecutor(this));

            var nawSilverlightAsyncTestExecutorExpr = new CodeObjectCreateExpression("TechTalk.SpecFlow.Async.SilverlightAsyncTestExecutor", new CodeThisReferenceExpression());

            var registerAsyncExpression = new CodeMethodInvokeExpression(
                new CodeTypeReferenceExpression(typeof(AsyncTestRunner)), 
                "RegisterAsyncTestExecutor", 
                new CodeVariableReferenceExpression("testRunner"),
                nawSilverlightAsyncTestExecutorExpr);

            generationContext.TestInitializeMethod.Statements.Add(new CodeExpressionStatement(registerAsyncExpression));
        }
Ejemplo n.º 16
0
        public void SetTestClassCleanupMethod(TestClassGenerationContext generationContext)
        {
            // xUnit uses IUseFixture<T> on the class

            generationContext.TestClassCleanupMethod.Attributes |= MemberAttributes.Static;

            _currentFixtureDataTypeDeclaration.BaseTypes.Add(typeof(IDisposable));

            // void IDisposable.Dispose() { <fixtureTearDownMethod>(); }

            CodeMemberMethod disposeMethod = new CodeMemberMethod();
            disposeMethod.PrivateImplementationType = new CodeTypeReference(typeof(IDisposable));
            disposeMethod.Name = "Dispose";
            _currentFixtureDataTypeDeclaration.Members.Add(disposeMethod);

            disposeMethod.Statements.Add(
                new CodeMethodInvokeExpression(
                    new CodeTypeReferenceExpression(new CodeTypeReference(generationContext.TestClass.Name)),
                    generationContext.TestClassCleanupMethod.Name));
        }
	    public override void SetTestClassCategories(TestClassGenerationContext generationContext, IEnumerable<string> featureCategories)
		{
			generationContext.CustomData["featureCategories"] = GetNonMSTestSpecificTags(featureCategories).ToArray();

			IEnumerable<string> ownerTags = featureCategories.Where(t => t.StartsWith(OWNER_TAG, StringComparison.InvariantCultureIgnoreCase)).Select(t => t);
			if(ownerTags.Any())
			{
				generationContext.CustomData[OWNER_TAG] = ownerTags.Select(t => t.Substring(OWNER_TAG.Length).Trim('\"')).FirstOrDefault();
			}

			IEnumerable<string> workitemTags = featureCategories.Where(t => t.StartsWith(WORKITEM_TAG, StringComparison.InvariantCultureIgnoreCase)).Select(t => t);
			if(workitemTags.Any())
			{
				int temp;
				IEnumerable<string> workitemsAsStrings = workitemTags.Select(t => t.Substring(WORKITEM_TAG.Length).Trim('\"'));
				if(workitemsAsStrings.Any())
				{
					generationContext.CustomData[WORKITEM_TAG] = workitemsAsStrings.Where(t => int.TryParse(t, out temp)).Select(t => int.Parse(t));
				}
			}
		}
Ejemplo n.º 18
0
        public void SetTestInitializeMethod(TestClassGenerationContext generationContext)
        {
            // xUnit uses a parameterless constructor

            // public <_currentTestTypeDeclaration>() { <memberMethod>(); }

            CodeConstructor ctorMethod = new CodeConstructor();
            ctorMethod.Attributes = MemberAttributes.Public;
            generationContext.TestClass.Members.Add(ctorMethod);

            ctorMethod.Statements.Add(
                new CodeMethodInvokeExpression(
                    new CodeThisReferenceExpression(),
                    generationContext.TestInitializeMethod.Name));
        }
Ejemplo n.º 19
0
 public void SetTestClassIgnore(TestClassGenerationContext generationContext)
 {
     //TODO: how to do class level ignore?
 }
Ejemplo n.º 20
0
 public virtual void SetTestClassInitializeMethod(TestClassGenerationContext generationContext)
 {
     CodeDomHelper.AddAttribute(generationContext.TestClassInitializeMethod, TESTFIXTURESETUP_ATTR_NUNIT3);
 }
Ejemplo n.º 21
0
 public void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod,
                           string scenarioTitle)
 {
     baseGeneratorProvider.SetTestMethod(generationContext, testMethod, scenarioTitle);
 }
Ejemplo n.º 22
0
 public void SetTestClassParallelize(TestClassGenerationContext generationContext)
 {
     baseGeneratorProvider.SetTestClassParallelize(generationContext);
 }
 public void FinalizeTestClass(TestClassGenerationContext generationContext)
 {
     _innerGenerator.FinalizeTestClass(generationContext);
 }
 public void SetTestCleanupMethod(TestClassGenerationContext generationContext)
 {
     _innerGenerator.SetTestCleanupMethod(generationContext);
 }
Ejemplo n.º 25
0
 public void SetTestCleanupMethod(TestClassGenerationContext generationContext)
 {
     baseGeneratorProvider.SetTestCleanupMethod(generationContext);
 }
 public void SetTestClassCategories(TestClassGenerationContext generationContext, IEnumerable <string> featureCategories)
 {
     _innerGenerator.SetTestClassCategories(generationContext, featureCategories);
 }
 public void SetTestClassIgnore(TestClassGenerationContext generationContext)
 {
     _innerGenerator.SetTestClassIgnore(generationContext);
 }
 public void SetTestClass(TestClassGenerationContext generationContext, string featureTitle, string featureDescription)
 {
     _innerGenerator.SetTestClass(generationContext, featureTitle, featureDescription);
 }
 public void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle)
 {
     _innerGenerator.SetRowTest(generationContext, testMethod, scenarioTitle);
 }
 public void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable <string> arguments, IEnumerable <string> tags, bool isIgnored)
 {
     _innerGenerator.SetRow(generationContext, testMethod, arguments, tags, isIgnored);
 }
Ejemplo n.º 31
0
 public void SetTestMethodAsRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle, string exampleSetName, string variantName, IEnumerable<KeyValuePair<string, string>> arguments)
 {
     // doing nothing since we support RowTest
 }
 public void SetTestInitializeMethod(TestClassGenerationContext generationContext)
 {
     _innerGenerator.SetTestInitializeMethod(generationContext);
 }
Ejemplo n.º 33
0
 public void SetTestClassCategories(TestClassGenerationContext generationContext, IEnumerable<string> featureCategories)
 {
     // xUnit does not support caregories
 }
Ejemplo n.º 34
0
 public void SetTestInitializeMethod(TestClassGenerationContext generationContext)
 {
     CodeDomHelper.AddAttribute(generationContext.TestInitializeMethod, TESTSETUP_ATTR);
 }
Ejemplo n.º 35
0
 public void SetTestClassIgnore(TestClassGenerationContext generationContext)
 {
     baseGeneratorProvider.SetTestClassIgnore(generationContext);
 }
Ejemplo n.º 36
0
 public virtual void SetTestClassParallelize(TestClassGenerationContext generationContext)
 {
     CodeDomHelper.AddAttribute(generationContext.TestClass, PARALLELIZABLE_ATTR, new CodeAttributeArgument(new CodePrimitiveExpression(generationContext.TestClass.Name)));
 }
 public void SetTestMethodAsRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle, string exampleSetName, string variantName, IEnumerable <KeyValuePair <string, string> > arguments)
 {
     _innerGenerator.SetTestMethodAsRow(generationContext, testMethod, scenarioTitle, exampleSetName, variantName, arguments);
 }
 public void SetTestMethodCategories(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable <string> scenarioCategories)
 {
     _innerGenerator.SetTestMethodCategories(generationContext, testMethod, scenarioCategories);
 }
Ejemplo n.º 39
0
 public void SetTestClass(TestClassGenerationContext generationContext, string featureTitle, string featureDescription)
 {
     featureDescription = string.IsNullOrEmpty(featureDescription) ? featureTitle : featureDescription;
     CodeDomHelper.AddAttribute(generationContext.TestClass, TESTFIXTURE_ATTR, new CodeAttributeArgument(TESTFIXTURENAME_PROPERTY_NAME, new CodePrimitiveExpression(featureTitle)));
     CodeDomHelper.AddAttribute(generationContext.TestClass, DESCRIPTION_ATTR, featureDescription);
 }
 public override void SetTestClassCleanupMethod(TestClassGenerationContext generationContext)
 {
     CodeDomHelper.AddAttribute(generationContext.TestClassCleanupMethod, TESTFIXTURETEARDOWN_ATTR_NUNIT3);
 }
Ejemplo n.º 41
0
 public virtual void SetTestClassCleanupMethod(TestClassGenerationContext generationContext)
 {
     CodeDomHelper.AddAttribute(generationContext.TestClassCleanupMethod, TESTFIXTURETEARDOWN_ATTR_NUNIT3);
 }
 public override void SetTestClassInitializeMethod(TestClassGenerationContext generationContext)
 {
     CodeDomHelper.AddAttribute(generationContext.TestClassInitializeMethod, TESTFIXTURESETUP_ATTR_NUNIT3);
 }
Ejemplo n.º 43
0
 public virtual void SetTestMethodIgnore(TestClassGenerationContext generationContext, CodeMemberMethod testMethod)
 {
     CodeDomHelper.AddAttribute(testMethod, IGNORE_ATTR, "Ignored scenario");
 }
Ejemplo n.º 44
0
 public void FinalizeTestClass(TestClassGenerationContext generationContext)
 {
     baseGeneratorProvider.FinalizeTestClass(generationContext);
 }
Ejemplo n.º 45
0
 public void SetTestMethodCategories(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable<string> scenarioCategories)
 {
     // xUnit does not support caregories
 }
 public void SetTestClassIgnore(TestClassGenerationContext generationContext)
 {
     CodeDomHelper.AddAttribute(generationContext.TestClass, IgnoreAttr, "Test class is ignored\n");
 }
Ejemplo n.º 47
0
        public void SetTestCleanupMethod(TestClassGenerationContext generationContext)
        {
            // xUnit supports test tear down through the IDisposable interface

            generationContext.TestClass.BaseTypes.Add(typeof(IDisposable));

            // void IDisposable.Dispose() { <memberMethod>(); }

            CodeMemberMethod disposeMethod = new CodeMemberMethod();
            disposeMethod.PrivateImplementationType = new CodeTypeReference(typeof(IDisposable));
            disposeMethod.Name = "Dispose";
            generationContext.TestClass.Members.Add(disposeMethod);

            disposeMethod.Statements.Add(
                new CodeMethodInvokeExpression(
                    new CodeThisReferenceExpression(),
                    generationContext.TestCleanupMethod.Name));
        }
 public void SetTestClassParallelize(TestClassGenerationContext generationContext)
 {
     CodeDomHelper.AddAttribute(generationContext.TestClass, ParallelizableAttr);
 }
Ejemplo n.º 49
0
 public virtual void FinalizeTestClass(TestClassGenerationContext generationContext)
 {
     // by default, doing nothing to the final generated code
 }
Ejemplo n.º 50
0
 public void SetTestClass(TestClassGenerationContext generationContext, string featureTitle,
                          string featureDescription)
 {
     baseGeneratorProvider.SetTestClass(generationContext, featureTitle, featureDescription);
 }
Ejemplo n.º 51
0
 public void SetTestClass(TestClassGenerationContext generationContext, string featureTitle, string featureDescription)
 {
     // xUnit does not use an attribute for the TestFixture, all public classes are potential fixtures
 }
Ejemplo n.º 52
0
 public void SetTestMethodIgnore(TestClassGenerationContext generationContext, CodeMemberMethod testMethod)
 {
     baseGeneratorProvider.SetTestMethodIgnore(generationContext, testMethod);
 }
Ejemplo n.º 53
0
 public override void SetTestClassParallelize(TestClassGenerationContext generationContext)
 {
     CodeDomHelper.AddAttribute(generationContext.TestClass, COLLECTION_ATTRIBUTE, new CodeAttributeArgument(new CodePrimitiveExpression(Guid.NewGuid())));
 }
Ejemplo n.º 54
0
 public void SetTestInitializeMethod(TestClassGenerationContext generationContext)
 {
     baseGeneratorProvider.SetTestInitializeMethod(generationContext);
 }
 public override void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle)
 {
     CodeDomHelper.AddAttribute(testMethod, TEST_ATTR);
     CodeDomHelper.AddAttribute(testMethod, DESCRIPTION_ATTR, scenarioTitle);
 }
        public void SetRow(TestClassGenerationContext generationContext,
                           CodeMemberMethod testMethod, IEnumerable <string> arguments, IEnumerable <string> tags, bool isIgnored)
        {
            var args = arguments.Select(arg => new CodeAttributeArgument(new CodePrimitiveExpression(arg))).ToList();

            var exampleTagExpressionList = tags.Select(t => new CodePrimitiveExpression(t)).ToArray();
            var exampleTagsExpression    = exampleTagExpressionList.Length == 0
                ? (CodeExpression) new CodePrimitiveExpression(null)
                : new CodeArrayCreateExpression(typeof(string[]), exampleTagExpressionList);

            args.Add(new CodeAttributeArgument(exampleTagsExpression));

            if (isIgnored)
            {
                args.Add(new CodeAttributeArgument("Ignored", new CodePrimitiveExpression(true)));
            }

            var categories = testMethod.UserData.Keys.OfType <string>()
                             .Where(key => key.Contains(":"));

            var userDataKeys = categories as IList <string> ?? categories.ToList();

            if (userDataKeys.Any())
            {
                //List of list of tags different values
                var values = new Dictionary <string, List <string> >();
                foreach (var userDataKey in userDataKeys)
                {
                    var           catName = userDataKey.Substring(0, userDataKey.IndexOf(':'));
                    List <string> val;
                    if (!values.TryGetValue(catName, out val))
                    {
                        val             = new List <string>();
                        values[catName] = val;
                    }

                    val.Add((string)testMethod.UserData[userDataKey]);
                }

                var combinations = new List <List <string> >();
                //Generate an exhaustive list of values combinations
                GeneratePermutations(values.Values.ToList(), combinations, 0, new List <string>());

                //Remove TestCase attributes
                foreach (var codeAttributeDeclaration in testMethod.CustomAttributes.Cast <CodeAttributeDeclaration>()
                         .Where(attr => attr.Name == RowAttr && attr.Arguments.Count == 2 + values.Keys.Count).ToList())
                {
                    testMethod.CustomAttributes.Remove(codeAttributeDeclaration);
                }

                foreach (var combination in combinations)
                {
                    var argsString = string.Concat(args.Take(args.Count - 1).Select(arg =>
                                                                                    $"\"{((CodePrimitiveExpression) arg.Value).Value}\" ,"));
                    argsString = argsString.TrimEnd(' ', ',');
                    //Fix
                    argsString = argsString.Replace('.', '_');

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

                    CodeDomHelper.AddAttribute(testMethod, RowAttr, withTagArgs);
                }
            }
            else
            {
                CodeDomHelper.AddAttribute(testMethod, RowAttr, args.ToArray());
            }
        }
 public override void SetTestClassIgnore(TestClassGenerationContext generationContext)
 {
     CodeDomHelper.AddAttribute(generationContext.TestClass, IGNORE_ATTR, "Ignored feature");
 }
 public void SetTestClassCategories(TestClassGenerationContext generationContext,
                                    IEnumerable <string> featureCategories)
 {
     CodeDomHelper.AddAttributeForEachValue(generationContext.TestClass, CategoryAttr, featureCategories);
 }
 public override void SetTestMethodIgnore(TestClassGenerationContext generationContext, CodeMemberMethod testMethod)
 {
     CodeDomHelper.AddAttribute(testMethod, IGNORE_ATTR, "Ignored scenario");
 }
 public void SetTestClassCleanupMethod(TestClassGenerationContext generationContext)
 {
     generationContext.TestClassCleanupMethod.Statements.Insert(0,
                                                                GenerateCodeSnippetStatement("helper.FeatureTearDown();"));
     CodeDomHelper.AddAttribute(generationContext.TestClassCleanupMethod, TestFixtureTearDownAttr);
 }