diff options
author | Rob Mensching <rob@firegiant.com> | 2022-08-01 19:26:38 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2022-08-05 09:22:36 -0700 |
commit | f905838a6398e2d5083145acf279968506ac900b (patch) | |
tree | f6861821ecbbf3d57d20ad7bb21e931d616c9b18 /src/internal/WixBuildTools.TestSupport | |
parent | 54907157d9b961784a50abd3feaf64764b8b1315 (diff) | |
download | wix-f905838a6398e2d5083145acf279968506ac900b.tar.gz wix-f905838a6398e2d5083145acf279968506ac900b.tar.bz2 wix-f905838a6398e2d5083145acf279968506ac900b.zip |
Add TestData.CreateFile and dedupe TestSupport code from Core.Native tests
Diffstat (limited to 'src/internal/WixBuildTools.TestSupport')
-rw-r--r-- | src/internal/WixBuildTools.TestSupport/TestData.cs | 33 |
1 files changed, 33 insertions, 0 deletions
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 | |||
9 | 9 | ||
10 | public class TestData | 10 | public class TestData |
11 | { | 11 | { |
12 | public static void CreateFile(string path, long size, bool fill = false) | ||
13 | { | ||
14 | // Ensure the directory exists. | ||
15 | path = Path.GetFullPath(path); | ||
16 | Directory.CreateDirectory(Path.GetDirectoryName(path)); | ||
17 | |||
18 | using (var file = File.OpenWrite(path)) | ||
19 | { | ||
20 | if (fill) | ||
21 | { | ||
22 | var random = new Random(); | ||
23 | var bytes = new byte[4096]; | ||
24 | var generated = 0L; | ||
25 | |||
26 | // Put fill bytes in the file so it doesn't compress trivially. | ||
27 | while (generated < size) | ||
28 | { | ||
29 | var generate = (int)Math.Min(size - generated, bytes.Length); | ||
30 | |||
31 | random.NextBytes(bytes); | ||
32 | |||
33 | file.Write(bytes, 0, generate); | ||
34 | |||
35 | generated += generate; | ||
36 | } | ||
37 | } | ||
38 | else | ||
39 | { | ||
40 | file.SetLength(size); | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | |||
12 | public static string Get(params string[] paths) | 45 | public static string Get(params string[] paths) |
13 | { | 46 | { |
14 | var localPath = Path.GetDirectoryName(new Uri(Assembly.GetCallingAssembly().CodeBase).LocalPath); | 47 | var localPath = Path.GetDirectoryName(new Uri(Assembly.GetCallingAssembly().CodeBase).LocalPath); |