Пример #1
0
        private static string RunTransformationCore(string logFileContents, SarifVersion targetVersion)
        {
            const string LogFilePath         = @"c:\logs\mylog.sarif";
            var          transformedContents = new StringBuilder();

            // Complex: TransformCommand has code paths that use Create and OpenRead, but also ReadAllText and WriteAllText.
            var mockFileSystem = new Mock <IFileSystem>();

            mockFileSystem.Setup(x => x.ReadAllText(LogFilePath)).Returns(logFileContents);
            mockFileSystem.Setup(x => x.OpenRead(LogFilePath)).Returns(() => new MemoryStream(Encoding.UTF8.GetBytes(logFileContents)));
            mockFileSystem.Setup(x => x.Create(LogFilePath)).Returns(() => new MemoryStreamToStringBuilder(transformedContents));
            mockFileSystem.Setup(x => x.WriteAllText(LogFilePath, It.IsAny <string>())).Callback <string, string>((path, contents) => { transformedContents.Append(contents); });

            var transformCommand = new TransformCommand(mockFileSystem.Object);

            var options = new TransformOptions
            {
                Inline             = true,
                SarifOutputVersion = targetVersion,
                InputFilePath      = LogFilePath
            };

            int returnCode = transformCommand.Run(options);

            returnCode.Should().Be(0);

            return(transformedContents.ToString());
        }
Пример #2
0
 /// <summary>The entry point for the SARIF multi utility.</summary>
 /// <param name="args">Arguments passed in from the tool's command line.</param>
 /// <returns>0 on success; nonzero on failure.</returns>
 public static int Main(string[] args)
 {
     return(Parser.Default.ParseArguments <
                ConvertOptions,
                RewriteOptions,
                TransformOptions,
                MergeOptions,
                RebaseUriOptions,
                AbsoluteUriOptions,
                BaselineOptions>(args)
            .MapResult(
                (ConvertOptions convertOptions) => ConvertCommand.Run(convertOptions),
                (RewriteOptions rewriteOptions) => RewriteCommand.Run(rewriteOptions),
                (TransformOptions transformOptions) => TransformCommand.Run(transformOptions),
                (MergeOptions mergeOptions) => MergeCommand.Run(mergeOptions),
                (RebaseUriOptions rebaseOptions) => RebaseUriCommand.Run(rebaseOptions),
                (AbsoluteUriOptions absoluteUriOptions) => AbsoluteUriCommand.Run(absoluteUriOptions),
                (BaselineOptions baselineOptions) => BaselineCommand.Run(baselineOptions),
                errs => 1));
 }
Пример #3
0
 /// <summary>The entry point for the SARIF multi utility.</summary>
 /// <param name="args">Arguments passed in from the tool's command line.</param>
 /// <returns>0 on success; nonzero on failure.</returns>
 public static int Main(string[] args)
 {
     return(Parser.Default.ParseArguments <
                ValidateOptions,
                ConvertOptions,
                RewriteOptions,
                TransformOptions,
                MergeOptions,
                RebaseUriOptions,
                AbsoluteUriOptions,
                ResultMatchingOptions>(args)
            .MapResult(
                (ValidateOptions validateOptions) => new ValidateCommand(new FileSystem()).Run(validateOptions),
                (ConvertOptions convertOptions) => ConvertCommand.Run(convertOptions),
                (RewriteOptions rewriteOptions) => RewriteCommand.Run(rewriteOptions),
                (TransformOptions transformOptions) => TransformCommand.Run(transformOptions),
                (MergeOptions mergeOptions) => MergeCommand.Run(mergeOptions),
                (RebaseUriOptions rebaseOptions) => RebaseUriCommand.Run(rebaseOptions),
                (AbsoluteUriOptions absoluteUriOptions) => AbsoluteUriCommand.Run(absoluteUriOptions),
                (ResultMatchingOptions baselineOptions) => ResultMatchingCommand.Run(baselineOptions),
                errs => 1));
 }