Exemple #1
0
        private static void AddStepDefinitonToIntelliSenseProject(List <NodeFeature> features, string pathToFeatureFile, string pathToIntelliSenseProject)
        {
            foreach (var feature in features)
            {
                List <StepInstance> si = new List <StepInstance>();
                var steps = new List <NodeStep>();
                feature.Scenarios.ForEach(s => steps.AddRange(s.Steps));
                var uniqueSteps = GeneratorHelper.FindUniqueSteps(new List <NodeStep>(), steps);

                foreach (var step in uniqueSteps)
                {
                    StepDefinitionType    type;
                    StepDefinitionKeyword keyword;
                    string stepNameWithoutType;

                    if (step.Name.StartsWith("Given"))
                    {
                        type                = StepDefinitionType.Given;
                        keyword             = StepDefinitionKeyword.Given;
                        stepNameWithoutType = step.Name.Substring("Given".Length);
                    }
                    else if (step.Name.StartsWith("When"))
                    {
                        type                = StepDefinitionType.When;
                        keyword             = StepDefinitionKeyword.When;
                        stepNameWithoutType = step.Name.Substring("When".Length);
                    }
                    else
                    {
                        type                = StepDefinitionType.Then;
                        keyword             = StepDefinitionKeyword.Then;
                        stepNameWithoutType = step.Name.Substring("Then".Length);
                    }
                    string scenarioName = feature.Scenarios.First(scenario => scenario.Steps.Contains(step)).Name;
                    si.Add(new StepInstance(type, keyword, stepNameWithoutType, stepNameWithoutType, new StepContext(feature.Name, scenarioName, new List <string>(), CultureInfo.CurrentCulture)));
                }

                var stepDefSkeleton = new StepDefinitionSkeletonProvider(new SpecFlowCSkeletonTemplateProvider(), new StepTextAnalyzer());
                var template        = stepDefSkeleton.GetBindingClassSkeleton(TechTalk.SpecFlow.ProgrammingLanguage.CSharp, si.ToArray(), "CppUnitTest", feature.Name, StepDefinitionSkeletonStyle.MethodNamePascalCase, CultureInfo.CurrentCulture);

                string basePathToFeatures            = Path.GetDirectoryName(pathToFeatureFile);
                string basePathToIntelliSenseProject = Path.GetDirectoryName(pathToIntelliSenseProject);
                _csProj = _csProj ?? GetUnloadedProject(pathToIntelliSenseProject);

                var stepDefinitionDirPathInProj = string.Format("Steps\\{0}\\", PROJECT_NAME);
                var stepDefinitionDirPath       = string.Format("{0}\\{1}", basePathToIntelliSenseProject, stepDefinitionDirPathInProj);

                var filePathInProjFile = string.Format("{0}{1}_step.cs", stepDefinitionDirPathInProj, feature.Name);
                var filePath           = string.Format("{0}{1}_step.cs", stepDefinitionDirPath, feature.Name);

                if (!_csProj.GetItems("Compile").Any(item => item.UnevaluatedInclude == filePathInProjFile))
                {
                    Console.WriteLine(string.Format("Generating Step Definition file for IntelliSense support: {0}", filePathInProjFile));
                    Directory.CreateDirectory(stepDefinitionDirPath);
                    File.WriteAllText(filePath, template);
                    _csProj.AddItem("Compile", filePathInProjFile);
                    _isDirtyCsProj = true;
                }
            }
        }
Exemple #2
0
        private void BuildTestClass(NodeFeature feature)
        {
            List <string>   privateContents   = new List <string>();
            List <string>   publicContents    = new List <string>();
            List <NodeStep> filterUniqueSteps = new List <NodeStep>();

            foreach (var scenario in feature.Scenarios)
            {
                AddScenario(scenario, feature.Hooks, publicContents);
                if ((scenario.Steps.Count > 0) && (feature.Scenarios.First() == scenario))
                {
                    OpenTestClassPrivateSection(privateContents);
                }
                AddSteps(GeneratorHelper.FindUniqueSteps(filterUniqueSteps, scenario.Steps), scenario, privateContents);
            }

            OpenTestClassPublicSection(feature.Hooks);

            Contents.AddRange(publicContents);

            if (privateContents.Count > 0)
            {
                Contents.AddRange(privateContents);
            }
        }
        private void BuildStepClass(string featureName, IList <NodeScenario> scenarios)
        {
            List <NodeStep> filterUniqueSteps = new List <NodeStep>();

            foreach (var scenario in scenarios)
            {
                if (scenario.Steps.Count > 0)
                {
                    AddSteps(featureName, GeneratorHelper.FindUniqueSteps(filterUniqueSteps, scenario.Steps));
                    if (scenarios.Last() != scenario)
                    {
                        Contents.Add(string.Empty);
                    }
                }
            }
        }