Example #1
0
        protected override TestGeneratorResult GenerateTestFileWithExceptions(FeatureFileInput featureFileInput, GenerationSettings settings)
        {
            if (featureFileInput == null) throw new ArgumentNullException("featureFileInput");
            if (settings == null) throw new ArgumentNullException("settings");

            var generatedTestFullPath = GetTestFullPath(featureFileInput);
            bool? preliminaryUpToDateCheckResult = null;
            if (settings.CheckUpToDate)
            {
                preliminaryUpToDateCheckResult = testUpToDateChecker.IsUpToDatePreliminary(featureFileInput, generatedTestFullPath, settings.UpToDateCheckingMethod);
                if (preliminaryUpToDateCheckResult == true)
                    return new TestGeneratorResult(null, true);
            }

            string generatedTestCode = GetGeneratedTestCode(featureFileInput);

            if (settings.CheckUpToDate && preliminaryUpToDateCheckResult != false)
            {
                var isUpToDate = testUpToDateChecker.IsUpToDate(featureFileInput, generatedTestFullPath, generatedTestCode, settings.UpToDateCheckingMethod);
                if (isUpToDate)
                    return new TestGeneratorResult(null, true);
            }

            if (settings.WriteResultToFile)
            {
                File.WriteAllText(generatedTestFullPath, generatedTestCode, Encoding.UTF8);
            }

            return new TestGeneratorResult(generatedTestCode, false);
        }
        public TestGeneratorResult GenerateTestFile(FeatureFileInput featureFileInput, GenerationSettings settings)
        {
            if (featureFileInput == null) throw new ArgumentNullException("featureFileInput");
            if (settings == null) throw new ArgumentNullException("settings");

            try
            {
                return GenerateTestFileWithExceptions(featureFileInput, settings);
            }
            catch (ParserException parserException)
            {
                return new TestGeneratorResult(parserException.GetParserExceptions().Select(
                    ex => new TestGenerationError(ex.Location == null ? 0 : ex.Location.Line, ex.Location == null ? 0 : ex.Location.Column, ex.Message)));
            }
            catch (Exception exception)
            {
                return new TestGeneratorResult(new TestGenerationError(exception));
            }
        }
        public TestGeneratorResult GenerateTestFile(FeatureFileInput featureFileInput, GenerationSettings settings)
        {
            if (featureFileInput == null) throw new ArgumentNullException("featureFileInput");
            if (settings == null) throw new ArgumentNullException("settings");

            try
            {
                return GenerateTestFileWithExceptions(featureFileInput, settings);
            }
            catch (SpecFlowParserException parserException)
            {
                if (parserException.ErrorDetails == null || parserException.ErrorDetails.Count == 0)
                    return new TestGeneratorResult(new TestGenerationError(parserException));

                return new TestGeneratorResult(parserException.ErrorDetails.Select(
                    ed => new TestGenerationError(ed.ForcedLine - 1, ed.ForcedColumn - 1, ed.Message)));
            }
            catch (Exception exception)
            {
                return new TestGeneratorResult(new TestGenerationError(exception));
            }
        }
Example #4
0
        protected override TestGeneratorResult GenerateTestFile(ITestGenerator generator, FeatureFileInput featureFileInput, GenerationSettings generationSettings)
        {
            try
            {
                var result = base.GenerateTestFile(generator, featureFileInput, generationSettings);

                if (result.IsUpToDate)
                    outputFile.Skip();
                else
                    outputFile.Done(task.Errors);

                return result;
            }
            catch (Exception ex)
            {
                task.RecordException(ex);
                return new TestGeneratorResult(new TestGenerationError(ex));
            }
            finally
            {
                outputFile = null;
            }
        }
        public virtual void Setup()
        {
            net35CSSettings = new ProjectPlatformSettings
                                  {
                                      Language = GenerationTargetLanguage.CSharp,
                                      LanguageVersion = new Version("3.0"),
                                      Platform = GenerationTargetPlatform.DotNet,
                                      PlatformVersion = new Version("3.5"),
                                  };
            net35VBSettings = new ProjectPlatformSettings
                                  {
                                      Language = GenerationTargetLanguage.VB,
                                      LanguageVersion = new Version("9.0"),
                                      Platform = GenerationTargetPlatform.DotNet,
                                      PlatformVersion = new Version("3.5"),
                                  };

            net35CSProjectSettings = new ProjectSettings { ProjectFolder = Path.GetTempPath(), ProjectPlatformSettings = net35CSSettings };
            net35VBProjectSettings = new ProjectSettings { ProjectFolder = Path.GetTempPath(), ProjectPlatformSettings = net35VBSettings };
            defaultSettings = new GenerationSettings();

            TestHeaderWriterStub = new Mock<ITestHeaderWriter>();
            TestUpToDateCheckerStub = new Mock<ITestUpToDateChecker>();
        }
 public TestGeneratorResult GenerateTestFile(FeatureFileInput featureFileInput, GenerationSettings settings)
 {
     return innerGenerator.GenerateTestFile(featureFileInput, settings);
 }
 public TestGeneratorResult GenerateTestFile(FeatureFileInput featureFileInput, GenerationSettings settings)
 {
     throw new NotImplementedException();
 }
 protected abstract TestGeneratorResult GenerateTestFileWithExceptions(FeatureFileInput featureFileInput, GenerationSettings settings);
Example #9
0
 protected virtual TestGeneratorResult GenerateTestFile(ITestGenerator generator, FeatureFileInput featureFileInput, GenerationSettings generationSettings)
 {
     return generator.GenerateTestFile(featureFileInput, generationSettings);
 }
Example #10
0
        private string GetGeneratedTestCode(FeatureFileInput featureFileInput, GenerationSettings settings)
        {
            using (var outputWriter = new IndentProcessingWriter(new StringWriter()))
            {
                var codeProvider = CreateCodeDomProvider(projectSettings.ProjectPlatformSettings);
                CodeDomHelper codeDomHelper = CreateCodeDomHelper(codeProvider, settings);

                var codeNamespace = GenerateTestFileCode(featureFileInput, codeDomHelper);
                var options = new CodeGeneratorOptions
                                  {
                                      BracingStyle = "C"
                                  };

                AddSpecFlowHeader(codeProvider, outputWriter, codeDomHelper);
                codeProvider.GenerateCodeFromNamespace(codeNamespace, outputWriter, options);
                AddSpecFlowFooter(codeProvider, outputWriter, codeDomHelper);

                outputWriter.Flush();
                return outputWriter.ToString();
            }
        }
Example #11
0
 protected virtual CodeDomHelper CreateCodeDomHelper(CodeDomProvider codeDomProvider, GenerationSettings settings)
 {
     return new CodeDomHelper(codeDomProvider);
 }