public static string MatchesRaw(string rawData, string step, string fileType = "raw") { var context = new AssertContext(step); var basePath = AssertConfigure.GlobalPath ?? AssertConfigure.DefaultGlobalPath; string outputFile = null; if (AssertConfigure.PathResolver != null) { outputFile = Path.GetFullPath(Path.Combine(basePath, AssertConfigure.PathResolver(context), step + "." + fileType)); Directory.CreateDirectory(Path.GetDirectoryName(outputFile)); } else { Directory.CreateDirectory(basePath); outputFile = Path.Combine(step + "." + fileType); } if (AssertConfigure.WriteMode) { AssertConfigure.EnsureDevMode(); if (ChecksumMatches(rawData, outputFile, context)) { return(rawData); // The file already matches; don't write to disk and save a few write cycles } WriteChecksumFile(rawData, outputFile, context); File.WriteAllText(outputFile, rawData); } else { if (!File.Exists(outputFile)) { throw new FileNotFoundException($"Could not find file '{outputFile}'. Is this a new test? Enable {nameof(AssertConfigure.WriteMode)} in {nameof(AssertConfigure)} to fix"); } if (ChecksumMatches(rawData, outputFile, context)) { return(rawData); } if (!File.ReadAllText(outputFile).Equals(rawData)) { throw new InvalidProgramException($"Difference in step {step}"); // TODO better error, with where and what } } return(rawData); }
public static string GetChecksumFilePath(AssertContext context) { var basePath = AssertConfigure.GlobalPath ?? AssertConfigure.DefaultGlobalPath; return(Path.Combine(basePath, AssertConfigure.ChecksumFileResolver(context))); }