public CodeNamespace GenerateUnitTestFixture(
            SpecFlowDocument specFlowDocument,
            string testClassName,
            string targetNamespace)
        {
            var specFlowFeature = specFlowDocument.SpecFlowFeature;

            var flavors = GetFlavors(specFlowFeature.Tags).ToList();

            // If the feature doesn't have any flavors, just invoke the feature generator.
            if (!flavors.Any())
            {
                return(_featureGenerator.GenerateUnitTestFixture(specFlowDocument, testClassName, targetNamespace));
            }

            // Create the range of flavor combinations.
            var combinations = CreateFlavorCombinations(flavors);

            var generatorResults = new List <CodeNamespace>();

            foreach (var combination in combinations)
            {
                var clonedDocument = CreateFlavoredFeature(specFlowDocument, combination);

                string previousFormat = null;
                if (_featureGenerator is UnitTestFeatureGenerator unitTestFeatureGenerator)
                {
                    previousFormat = unitTestFeatureGenerator.TestclassNameFormat;
                    var extension = "_With" + string.Join(
                        "_AndWith",
                        combination.Select(combo => combo.Category + combo.Value));

                    unitTestFeatureGenerator.TestclassNameFormat += extension;
                }

                // Generate the flavored test fixture.
                var generatorResult = _featureGenerator.GenerateUnitTestFixture(clonedDocument, testClassName, targetNamespace);

                generatorResults.Add(generatorResult);

                if (previousFormat != null)
                {
                    ((UnitTestFeatureGenerator)_featureGenerator).TestclassNameFormat = previousFormat;
                }
            }

            var result = generatorResults.First();

            foreach (var generatorResult in generatorResults.Skip(1))
            {
                foreach (CodeTypeDeclaration type in generatorResult.Types)
                {
                    result.Types.Add(type);
                }
            }

            return(result);
        }
        public CodeNamespace GenerateUnitTestFixture(SpecFlowDocument specFlowDocument, string testClassName, string targetNamespace)
        {
            CodeNamespace result            = null;
            bool          onlyFullframework = false;

            var  specFlowFeature = specFlowDocument.SpecFlowFeature;
            bool onlyDotNetCore  = false;

            if (specFlowFeature.HasTags())
            {
                if (specFlowFeature.Tags.Where(t => t.Name == "@SingleTestConfiguration").Any())
                {
                    return(_defaultFeatureGenerator.GenerateUnitTestFixture(specFlowDocument, testClassName, targetNamespace));
                }

                onlyFullframework = HasFeatureTag(specFlowFeature, "@fullframework");
                onlyDotNetCore    = HasFeatureTag(specFlowFeature, "@dotnetcore");
            }

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                onlyFullframework = false;
                onlyDotNetCore    = true;
            }

            var tagsOfFeature     = specFlowFeature.Tags.Select(t => t.Name);
            var unitTestProviders = tagsOfFeature.Where(t => _unitTestProviderTags.Where(utpt => string.Compare(t, "@" + utpt, StringComparison.CurrentCultureIgnoreCase) == 0).Any());

            foreach (var featureGenerator in GetFilteredFeatureGenerator(unitTestProviders, onlyFullframework, onlyDotNetCore))
            {
                var clonedDocument = CloneDocumentAndAddTag(specFlowDocument, featureGenerator.Key.UnitTestProvider);


                var featureGeneratorResult = featureGenerator.Value.GenerateUnitTestFixture(clonedDocument, testClassName, targetNamespace);

                if (result == null)
                {
                    result = featureGeneratorResult;
                }
                else
                {
                    foreach (CodeTypeDeclaration type in featureGeneratorResult.Types)
                    {
                        result.Types.Add(type);
                    }
                }
            }

            if (result == null)
            {
                result = new CodeNamespace(targetNamespace);
            }

            return(result);
        }
 protected void GenerateFeature(IFeatureGenerator generator, SpecFlowDocument document)
 {
     generator.GenerateUnitTestFixture(document, "dummy", "dummyNS");
 }
Пример #4
0
 protected void GenerateFeature(IFeatureGenerator generator, Feature feature)
 {
     generator.GenerateUnitTestFixture(feature, "dummy", "dummyNS");
 }
 protected void GenerateFeature(IFeatureGenerator generator, SpecFlowFeature feature)
 {
     generator.GenerateUnitTestFixture(feature, "dummy", "dummyNS");
 }
 protected void GenerateFeature(IFeatureGenerator generator, SpecFlowDocument document)
 {
     generator.GenerateUnitTestFixture(document, "dummy", "dummyNS");
 }