Ejemplo n.º 1
0
        public async Task <ReportingResult> WriteAnalysisReportsAsync(
            IEnumerable <string> assemblyPaths,
            IFileWriter reportWriter,
            bool includeJson)
        {
            await _outputWindow.ShowWindowAsync().ConfigureAwait(false);

            await _optionsViewModel.UpdateAsync().ConfigureAwait(false);

            var reportDirectory = _optionsViewModel.OutputDirectory;
            var outputFormats   = _optionsViewModel.Formats.Where(f => f.IsSelected).Select(f => f.DisplayName);
            var reportFileName  = _optionsViewModel.DefaultOutputName;

            var analysisOptions = await GetApiPortOptions(assemblyPaths, outputFormats, Path.Combine(reportDirectory, reportFileName)).ConfigureAwait(false);

            var issuesBefore = _reporter.Issues.Count;

            var result = await _client.WriteAnalysisReportsAsync(analysisOptions, includeJson).ConfigureAwait(false);

            if (!result.Paths.Any())
            {
                var issues = _reporter.Issues.ToArray();

                await _threadingService.SwitchToMainThreadAsync();

                for (int i = issuesBefore; i < issues.Length; i++)
                {
                    _outputWindow.WriteLine(LocalizedStrings.ListItem, issues[i]);
                }
            }

            await _viewer.ViewAsync(result.Paths).ConfigureAwait(false);

            return(result.Result);
        }
Ejemplo n.º 2
0
        public static async Task WriteAnalysisReports_ThrowsOnInvalidOptions_TargetCount()
        {
            var service                = Substitute.For <IApiPortService>();
            var progressReporter       = Substitute.For <IProgressReporter>();
            var targetMapper           = Substitute.For <ITargetMapper>();
            var dependencyFinder       = Substitute.For <IDependencyFinder>();
            var reportGenerator        = Substitute.For <IReportGenerator>();
            var ignoreAssemblyInfoList = Substitute.For <IEnumerable <IgnoreAssemblyInfo> >();
            var writer = Substitute.For <IFileWriter>();

            var client  = new ApiPortClient(service, progressReporter, targetMapper, dependencyFinder, reportGenerator, ignoreAssemblyInfoList, writer);
            var options = Substitute.For <IApiPortOptions>();

            options.Targets.Returns(Enumerable.Range(0, 16).Select(x => x.ToString(CultureInfo.CurrentCulture)));
            options.OutputFormats.Returns(new[] { "HTML", "Excel" });

            await Assert.ThrowsAsync <InvalidApiPortOptionsException>(() => client.WriteAnalysisReportsAsync(options));

            await Assert.ThrowsAsync <InvalidApiPortOptionsException>(() => client.WriteAnalysisReportsAsync(options, true));
        }
Ejemplo n.º 3
0
        public async Task AnalyzeAssembliesAsync()
        {
            var outputPaths = await _apiPortClient.WriteAnalysisReportsAsync(_options);

            Console.WriteLine();
            Console.WriteLine(LocalizedStrings.OutputWrittenTo);

            foreach (var outputPath in outputPaths)
            {
                Console.WriteLine(outputPath);
            }
        }
Ejemplo n.º 4
0
        private static async Task UserAssemblyTestsAsync(IEnumerable <AssemblyInfo> assemblies)
        {
            var service                = Substitute.For <IApiPortService>();
            var progressReporter       = Substitute.For <IProgressReporter>();
            var targetMapper           = Substitute.For <ITargetMapper>();
            var dependencyFinder       = Substitute.For <IDependencyFinder>();
            var reportGenerator        = Substitute.For <IReportGenerator>();
            var ignoreAssemblyInfoList = Substitute.For <IEnumerable <IgnoreAssemblyInfo> >();
            var writer = Substitute.For <IFileWriter>();

            service.SendAnalysisAsync(Arg.Any <AnalyzeRequest>(), Arg.Any <IEnumerable <string> >()).Returns(
                ServiceResponse.Create(Enumerable.Empty <ReportingResultWithFormat>()));

            var client  = new ApiPortClient(service, progressReporter, targetMapper, dependencyFinder, reportGenerator, ignoreAssemblyInfoList, writer);
            var options = Substitute.For <IApiPortOptions>();

            IAssemblyFile CreateAssemblyFile(AssemblyInfo assemblyInfo)
            {
                var file = Substitute.For <IAssemblyFile>();

                file.Name.Returns(assemblyInfo.AssemblyIdentity);
                file.Version.Returns(assemblyInfo.FileVersion);
                file.Exists.Returns(true);
                return(file);
            }

            var assemblyFiles = assemblies.Where(a => a.IsExplicitlySpecified).ToImmutableDictionary(CreateAssemblyFile, _ => false);

            options.InputAssemblies.Returns(assemblyFiles);

            var info = Substitute.For <IDependencyInfo>();

            info.UserAssemblies.Returns(assemblies);

            dependencyFinder.FindDependencies(Arg.Any <IEnumerable <IAssemblyFile> >(), progressReporter)
            .Returns(info);

            await client.WriteAnalysisReportsAsync(options);

            Assert.All(assemblies, a =>
            {
                var expected = assemblies.First(t => string.Equals(t.Location, a.Location, StringComparison.OrdinalIgnoreCase)).IsExplicitlySpecified;
                Assert.Equal(expected, a.IsExplicitlySpecified);
            });
        }
Ejemplo n.º 5
0
        public async Task <string> AnalyzeAssembliesAsync()
        {
            var outputPaths = await _apiPortClient.WriteAnalysisReportsAsync(_options);

            string reportPath = string.Empty;

            Console.WriteLine();
            if (outputPaths.Any())
            {
                Console.WriteLine(LocalizedStrings.OutputWrittenTo);

                foreach (var outputPath in outputPaths)
                {
                    reportPath = outputPath;
                    Console.WriteLine(outputPath);
                }
            }

            return(reportPath);
        }
Ejemplo n.º 6
0
        public async Task <ReportingResult> WriteAnalysisReportsAsync(
            string entrypoint,
            IEnumerable <string> assemblyPaths,
            IEnumerable <string> installedPackages,
            IFileWriter reportWriter,
            bool includeJson)
        {
            await Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            await _outputWindow.ShowWindowAsync();

            await _optionsViewModel.UpdateAsync();

            var reportDirectory = _optionsViewModel.OutputDirectory;
            var outputFormats   = _optionsViewModel.Formats.Where(f => f.IsSelected).Select(f => f.DisplayName);
            var reportFileName  = _optionsViewModel.DefaultOutputName;

            var analysisOptions = await GetOptionsAsync(entrypoint, assemblyPaths, outputFormats, installedPackages, Path.Combine(reportDirectory, reportFileName));

            var issuesBefore = _reporter.Issues.Count;

            var result = await _client.WriteAnalysisReportsAsync(analysisOptions, includeJson);

            if (!result.Paths.Any())
            {
                var issues = _reporter.Issues.ToArray();

                for (var i = issuesBefore; i < issues.Length; i++)
                {
                    _outputWindow.WriteLine(LocalizedStrings.ListItem, issues[i]);
                }
            }

            await _viewer.ViewAsync(result.Paths);

            return(result.Result);
        }