Ejemplo n.º 1
0
        public void Evaluate(int numberOfGroups, string[] directories, int specificGroup)
        {
            var groupedFilesList = DirectoryGroupEvaluator.Evaluate(numberOfGroups, directories);

            var groupedResults = new List <List <JavaScriptEvaluationResult> >();

            var i = 1;

            foreach (var fileList in groupedFilesList)
            {
                if (specificGroup == 0 || i == specificGroup)
                {
                    Ux.WriteLine(string.Format("Group{0} ({1} {2})", i, fileList.StartDir, fileList.EndDir));
                    groupedResults.Add(JavaScriptStatsPresenter.Present(fileList.Files));
                    Ux.WriteLine("");
                    ScrollDown(null, null);
                }
                i++;
            }

            Ux.DisplayBoolOption("Store detailed JS results to disk?", () =>
            {
                i = 1;
                foreach (var resultGroup in groupedResults)
                {
                    JavaScriptStatsStorageService.Store(resultGroup, string.Format("Group {0}", specificGroup > 0 ? specificGroup : i));
                    ScrollDown(null, null);
                    i++;
                }
                //FolderPresenter.Present(Properties.Settings.Default.ResultsPath);
            }, null);

            Ux.WriteLine("");
        }
        public void Present()
        {
            var jsResults = JavaScriptStatsPresenter.Present(FilteredFilesEvaluator.Evaluate(SettingsEvaluator.GetSpecificFiles()));

            var cssResults = CssStatsPresenter.Present(FilteredFilesEvaluator.Evaluate(SettingsEvaluator.GetSpecificFiles()));

            Ux.DisplayBoolOption("Store detailed Javascript results to disk?", () => JavaScriptStatsStorageService.Store(jsResults, string.Empty), null);
            Ux.DisplayBoolOption("Store detailed CSS results to disk?", () => CssStatsStorageService.Store(cssResults, string.Empty), null);
        }
        public void StoreJavascript()
        {
            var mockRelevantAttributesEvaluator = new Mock <IRelevantAttributesEvaluator>();
            var mockHumanInterface   = new Mock <IHumanInterface>();
            var mockDateTimeProvider = new Mock <IDateTimeProvider>();
            var mockStorer           = new Mock <IStorageService>();
            var mockNamer            = new Mock <IJavaScriptStatsFileNameEvaluator>();

            mockRelevantAttributesEvaluator.Setup(x => x.Evaluate(It.IsAny <List <JavaScriptEvaluationResult> >())).Returns(() => new List <string> {
                "onclick", "onblur", "ondblclick"
            });

            mockStorer.Setup(x => x.Store(It.IsAny <StringBuilder>(), It.IsAny <string>())).Callback <StringBuilder, string>((sb, title) =>
            {
                var str = sb.ToString();

                Assert.AreEqual(8 * 3, str.Count(x => x == ','));
                Assert.AreEqual(2, Regex.Matches(str, Environment.NewLine).Count);
            });

            var evaluator = new JavaScriptStatsStorageService(mockStorer.Object, mockDateTimeProvider.Object, mockHumanInterface.Object, mockRelevantAttributesEvaluator.Object, mockNamer.Object);

            var testData = new List <JavaScriptEvaluationResult>
            {
                new JavaScriptEvaluationResult
                {
                    Block = new List <DetailedJavaScriptEvaluationResult>
                    {
                        new DetailedJavaScriptEvaluationResult {
                            AttributeName = "onclick", InlineJavascriptTags = new List <JavascriptOccurenceResult>()
                        },
                        new DetailedJavaScriptEvaluationResult {
                            AttributeName = "onblur", InlineJavascriptTags = new List <JavascriptOccurenceResult>()
                        },
                    },
                    Razor = new List <DetailedJavaScriptEvaluationResult>
                    {
                        new DetailedJavaScriptEvaluationResult {
                            AttributeName = "onclick"
                        },
                        new DetailedJavaScriptEvaluationResult {
                            AttributeName = "ondblclick"
                        },
                    },
                    PageInstances = new []
                    {
                        new BlockContent {
                            Lines = new List <string> {
                                "line1"
                            }
                        },
                        new BlockContent {
                            Lines = new List <string>()
                        },
                    },
                    FileName   = "test",
                    References = 1
                }
            };

            evaluator.Store(testData, string.Empty);
        }
Ejemplo n.º 4
0
        public void Execute()
        {
            SettingsValidator.Validate();

            var directory = SettingsEvaluator.GetApTwoDirectory();

            var files = DirectoryDescendentFilesEvaluator.Evaluate(directory).OrderBy(x => x).ToList();

            var loop = true;

            while (loop)
            {
                Ux.WriteLine(string.Format("Analysing: {0}", directory));

                Ux.AddOption("Exit", () => loop = false);

                Ux.AddOptionWithHeadingSpace("View all file extensions", () => FileExtensionPresenter.Present(files));
                Ux.AddOption("View all files", () => ListPresenter.Present(files));
                Ux.AddOption("View filtered extensions", () => FilteredFilesPresenter.PresentFilteredExtensions());
                Ux.AddOption("View filtered files", () => FilteredFilesPresenter.PresentFilteredFiles(files));
                Ux.AddOption("View filtered file statistics", () => FilteredFilesStatsPresenter.Present(files));

                Ux.AddOptionWithHeadingSpace("Count inline CSS on filtered files", () =>
                {
                    var results = CssStatsPresenter.Present(FilteredFilesEvaluator.Evaluate(files));
                    Ux.DisplayBoolOption("Store detailed CSS results to disk?", () => CssStatsStorageService.Store(results, string.Empty), null);
                });

                Ux.AddOptionWithHeadingSpace("Count inline Javascript on filtered files", () =>
                {
                    var results = JavaScriptStatsPresenter.Present(FilteredFilesEvaluator.Evaluate(files));
                    Ux.DisplayBoolOption("Store detailed JavaScript results to disk?", () => JavaScriptStatsStorageService.Store(results, string.Empty), null);
                });

                Ux.AddOptionWithHeadingSpace("Count inline Javascript and CSS on specific file...", () => JavaScriptFileStatsPresenter.Present());

                Ux.DisplayOptions("Please choose an option");
            }
        }