private static string RunTransformationCore(string logFileContents, SarifVersion targetVersion) { string logFilePath = @"c:\logs\mylog.sarif"; string transformedContents = null; var mockFileSystem = new Mock <IFileSystem>(); mockFileSystem.Setup(x => x.ReadAllText(logFilePath)).Returns(logFileContents); mockFileSystem.Setup(x => x.WriteAllText(logFilePath, It.IsAny <string>())).Callback <string, string>((path, contents) => { transformedContents = contents; }); var transformCommand = new TransformCommand(mockFileSystem.Object, testing: true); var options = new TransformOptions { Inline = true, TargetVersion = targetVersion, InputFilePath = logFilePath }; int returnCode = transformCommand.Run(options); returnCode.Should().Be(0); return(transformedContents); }
private static string RunTransformationCore(string logFileContents, SarifVersion targetVersion) { string logFilePath = @"c:\logs\mylog.sarif"; StringBuilder transformedContents = new StringBuilder(); // Complex: TransformCommand has codepaths 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()); }