public void ResultLogJsonWriter_CannotWriteToolInfoToDisposedWriter() { using (var str = new StringWriter()) using (var json = new JsonTextWriter(str)) using (var uut = new ResultLogJsonWriter(json)) { uut.Dispose(); uut.WriteToolAndRunInfo(s_defaultToolInfo, s_defaultRunInfo); } }
public ResultLogger( Assembly assembly, string outputFilePath, bool verbose, IEnumerable<string> analysisTargets, bool computeTargetsHash, string prereleaseInfo) { Verbose = verbose; _fileStream = new FileStream(outputFilePath, FileMode.Create, FileAccess.Write, FileShare.None); _textWriter = new StreamWriter(_fileStream); _jsonTextWriter = new JsonTextWriter(_textWriter); // for debugging it is nice to have the following line added. _jsonTextWriter.Formatting = Newtonsoft.Json.Formatting.Indented; _issueLogJsonWriter = new ResultLogJsonWriter(_jsonTextWriter); var toolInfo = new ToolInfo(); toolInfo.InitializeFromAssembly(assembly, prereleaseInfo); RunInfo runInfo = new RunInfo(); runInfo.AnalysisTargets = new List<FileReference>(); foreach (string target in analysisTargets) { var fileReference = new FileReference() { Uri = target.CreateUriForJsonSerialization(), }; if (computeTargetsHash) { string sha256Hash = HashUtilities.ComputeSha256Hash(target) ?? "[could not compute file hash]"; fileReference.Hashes = new List<Hash>(new Hash[] { new Hash() { Value = sha256Hash, Algorithm = AlgorithmKind.Sha256, } }); } runInfo.AnalysisTargets.Add(fileReference); } runInfo.InvocationInfo = Environment.CommandLine; _issueLogJsonWriter.WriteToolAndRunInfo(toolInfo, runInfo); }