Exemplo n.º 1
0
        protected override string ConstructTestOutputFromInputResource(string inputResourceName, object parameter)
        {
            const string InputFolderPath     = @"C:\input";
            string       targetFileSpecifier = Path.Combine(InputFolderPath, inputResourceName);

            string outputFileName = Guid.NewGuid().ToString() + SarifConstants.SarifFileExtension;
            string outputFilePath = Path.Combine(OutputFolderPath, outputFileName);

            var mockFileSystem = new Mock <IFileSystem>();

            PrepareFileSystemMock(inputResourceName, InputFolderPath, outputFilePath, mockFileSystem);

            IFileSystem fileSystem = mockFileSystem.Object;

            var options = new MergeOptions
            {
                PrettyPrint          = true,
                OutputDirectoryPath  = OutputFolderPath,
                TargetFileSpecifiers = new[] { targetFileSpecifier },
                OutputFileName       = outputFileName,
                Force = true
            };

            var mergeCommand = new MergeCommand(fileSystem);

            int returnCode = mergeCommand.Run(options);

            returnCode.Should().Be(0);

            return(File.ReadAllText(outputFilePath));
        }
Exemplo n.º 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,
                MergeOptions>(args)
            .MapResult(
                (ConvertOptions convertOptions) => ConvertCommand.Run(convertOptions),
                (RewriteOptions rewriteOptions) => RewriteCommand.Run(rewriteOptions),
                (MergeOptions mergeOptions) => MergeCommand.Run(mergeOptions),
                errs => 1));
 }
Exemplo n.º 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 <
                ConvertOptions,
                RewriteOptions,
                MergeOptions,
                RebaseUriOptions,
                AbsoluteUriOptions,
                BaselineOptions>(args)
            .MapResult(
                (ConvertOptions convertOptions) => ConvertCommand.Run(convertOptions),
                (RewriteOptions rewriteOptions) => RewriteCommand.Run(rewriteOptions),
                (MergeOptions mergeOptions) => MergeCommand.Run(mergeOptions),
                (RebaseUriOptions rebaseOptions) => RebaseUriCommand.Run(rebaseOptions),
                (AbsoluteUriOptions absoluteUriOptions) => AbsoluteUriCommand.Run(absoluteUriOptions),
                (BaselineOptions baselineOptions) => BaselineCommand.Run(baselineOptions),
                errs => 1));
 }
Exemplo n.º 4
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));
 }
Exemplo n.º 5
0
        protected override string ConstructTestOutputFromInputResource(string inputResourceName, object parameter)
        {
            const string InputFolderPath     = @"C:\input";
            string       targetFileSpecifier = Path.Combine(InputFolderPath, inputResourceName);

            string outputFileName = Guid.NewGuid().ToString() + SarifConstants.SarifFileExtension;
            string outputFilePath = Path.Combine(OutputFolderPath, outputFileName);

            var mockFileSystem = new Mock <IFileSystem>();

            // We mock the file system to fake out the read operations.
            mockFileSystem.Setup(x => x.FileExists(outputFilePath)).Returns(false);
            mockFileSystem.Setup(x => x.DirectoryExists(InputFolderPath)).Returns(true);
            mockFileSystem.Setup(x => x.GetFilesInDirectory(InputFolderPath, inputResourceName)).Returns(new string[0]); // <= The hard-coded return value in question.

            // But we really do want to create the output file, so tell the mock to execute the actual write operations.
            mockFileSystem.Setup(x => x.CreateDirectory(OutputFolderPath)).Returns((string path) => { return(Directory.CreateDirectory(path)); });
            mockFileSystem.Setup(x => x.Create(outputFilePath)).Returns((string path) => { return(File.Create(path)); });

            IFileSystem fileSystem = mockFileSystem.Object;

            var options = new MergeOptions
            {
                PrettyPrint          = true,
                OutputDirectoryPath  = OutputFolderPath,
                TargetFileSpecifiers = new[] { targetFileSpecifier },
                OutputFileName       = outputFileName
            };

            var mergeCommand = new MergeCommand(fileSystem);

            int returnCode = mergeCommand.Run(options);

            returnCode.Should().Be(0);

            return(File.ReadAllText(outputFilePath));
        }