예제 #1
0
파일: Program.cs 프로젝트: robfe/SpecShow
        static void Process(ProgramArguments args)
        {
            var parser = new SpecFlowLangParser(new CultureInfo("en-US"));
            var srcDir = new DirectoryInfo(args.FeatureDirectory);
            var files = srcDir.GetFiles("*.feature", SearchOption.AllDirectories);
            var startIndex = srcDir.FullName.Length;
            if (!srcDir.FullName.EndsWith("\\"))
            {
                startIndex++;
            }

            var features = files
                .Select(x => parser.Parse(x.OpenText(), x.FullName.Substring(startIndex)))
                .Where(x => x.FilePosition != null); //not parsable

            var vm = new RootViewModel()
                {
                    Title = args.PageTitle ?? Path.GetFileNameWithoutExtension(args.OutputFile),
                };

            foreach (var feature in features)
            {
                vm.AddFeature(new FeatureViewModel(feature));
            }

            if (args.XUnitResults != null)
            {
                IResultsMatcher matcher = new XUnitResultsMatcher();
                matcher.Populate(File.OpenRead(args.XUnitResults), vm);
            }
            //todo: other parsers

            PrintSummary(vm);

            /**
            var template = new SinglePageTemplate { Session = new Dictionary<string, object> { { "TemplateModel", vm } } };
            template.Initialize();
            /*/
            var template = new SinglePageRazorTemplate { TemplateModel=vm };
            /**/
            var transformText = template.TransformText();
            File.WriteAllText(args.OutputFile, transformText);
        }
예제 #2
0
        public void Populate(Stream file, RootViewModel viewModel)
        {
            Dictionary<string, FeatureViewModel> features = viewModel.RootFolder.DescendantFeatures().ToDictionary(x => x.Name);

            var document = XDocument.Load(file);
            var tests = document.Descendants("test");
            var testOutputs = from t in tests
                              let traits = t.Descendants("trait")
                              let featureTitleElement = traits.FirstOrDefault(x => (string)x.Attribute("name") == "FeatureTitle")
                              let descriptionElement = traits.FirstOrDefault(x => (string)x.Attribute("name") == "Description")
                              where descriptionElement != null && featureTitleElement != null
                              select new ScenarioOutput
                                  {
                                      TestElement = t,
                                      FeatureTitle = (string)featureTitleElement.Attribute("value"),
                                      Description = (string)descriptionElement.Attribute("value"),
                                      Output = (string)t.Element("output"),
                                      Result = (string)t.Attribute("result"),
                                      TestName = (string)t.Attribute("name"),
                                      FailureElement = t.Element("failure"),
                                  };

            foreach (var scenarioOutputs in testOutputs.ToLookup(x => Tuple.Create(x.FeatureTitle, x.Description)))
            {
                string featureTitle = scenarioOutputs.Key.Item1;
                string scenarioTitle = scenarioOutputs.Key.Item2;

                FeatureViewModel featureViewModel;
                if (!features.TryGetValue(featureTitle, out featureViewModel))
                {
                    continue;
                }
                ScenarioViewModelBase svmb = featureViewModel.Scenarios.SingleOrDefault(x => x.ScenarioNode.Title == scenarioTitle);
                if (svmb == null)
                {
                    continue;
                }

                var svm = svmb as ScenarioViewModel;
                if (svm != null)
                {
                    var test = scenarioOutputs.Single();
                    MatchScenario(test, svm);
                }

                var scenarioOutline = svmb as ScenarioOutlineViewModel;
                if (scenarioOutline != null)
                {
                    foreach (ScenarioOutlineExampleSetViewModel exampleSet in scenarioOutline.Examples)
                    {
                        foreach (ScenarioOutlineExampleRowViewModel exampleRow in exampleSet.ExampleRows)
                        {
                            var content = ExpectedTestNameContents(exampleSet, exampleRow);
                            var scenarioOutput = scenarioOutputs.Single(x => x.TestName.Contains(content + ","));
                            MatchScenario(scenarioOutput, exampleRow);
            //                            exampleRow.Status = MapResult(scenarioOutput.Result);
            //                            exampleRow.FailureMessage = scenarioOutput.
                        }
                    }
                }
            }
        }
예제 #3
0
파일: Program.cs 프로젝트: robfe/SpecShow
        static void PrintSummary(RootViewModel vm)
        {
            //print totals of each status that exists:
            var grouping = vm.RootFolder.DescendantFeatures()
                             .SelectMany(x => x.Scenarios)
                             .ToLookup(x => x.Status)
                             .Select(x => new { Status = x.Key, Count = x.Count(), Items = x })
                             .OrderBy(x => (int)x.Status);

            if (grouping.Any(x => x.Status == Status.Failed))
            {
                Environment.ExitCode = -1;
            }
            foreach (var g in grouping)
            {
                WriteLine(g.Status, "SpecShow: {0} {1} scenarios", g.Count, g.Status);
            }

            //print each feature & scenario (todo: sort by folder?)
            PrintFolder(vm.RootFolder, "", 0);

            if (IsTeamCity)
            {
                var statuses = vm.RootFolder.DescendantFeatures().SelectMany(x => x.Scenarios).Select(x => x.Status);
                var total = statuses.Count();
                System.Console.Out.WriteLine("##teamcity[buildStatisticValue key='{0}' value='{1}']", "SpecShow_Scenarios_Total", total);

                foreach (var status in (Status[])Enum.GetValues(typeof(Status)))
                {
                    System.Console.Out.WriteLine("##teamcity[buildStatisticValue key='SpecShow_Scenarios_{0}' value='{1}']", status, statuses.Count(x => x == status));
                    System.Console.Out.WriteLine("##teamcity[buildStatisticValue key='SpecShow_Scenarios_{0}_Percent' value='{1}']", status, statuses.Count(x => x == status) / (double)total * 100);
                }
            }
        }
 protected ViewModelConstructionTestBase()
 {
     _viewModel = new RootViewModel();
 }