From f905838a6398e2d5083145acf279968506ac900b Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Mon, 1 Aug 2022 19:26:38 -0700 Subject: Add TestData.CreateFile and dedupe TestSupport code from Core.Native tests --- src/internal/WixBuildTools.TestSupport/TestData.cs | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/internal/WixBuildTools.TestSupport') diff --git a/src/internal/WixBuildTools.TestSupport/TestData.cs b/src/internal/WixBuildTools.TestSupport/TestData.cs index 309e9038..fc1ae4cc 100644 --- a/src/internal/WixBuildTools.TestSupport/TestData.cs +++ b/src/internal/WixBuildTools.TestSupport/TestData.cs @@ -9,6 +9,39 @@ namespace WixBuildTools.TestSupport public class TestData { + public static void CreateFile(string path, long size, bool fill = false) + { + // Ensure the directory exists. + path = Path.GetFullPath(path); + Directory.CreateDirectory(Path.GetDirectoryName(path)); + + using (var file = File.OpenWrite(path)) + { + if (fill) + { + var random = new Random(); + var bytes = new byte[4096]; + var generated = 0L; + + // Put fill bytes in the file so it doesn't compress trivially. + while (generated < size) + { + var generate = (int)Math.Min(size - generated, bytes.Length); + + random.NextBytes(bytes); + + file.Write(bytes, 0, generate); + + generated += generate; + } + } + else + { + file.SetLength(size); + } + } + } + public static string Get(params string[] paths) { var localPath = Path.GetDirectoryName(new Uri(Assembly.GetCallingAssembly().CodeBase).LocalPath); -- cgit v1.2.3-55-g6feb