aboutsummaryrefslogtreecommitdiff
path: root/src/internal/WixBuildTools.TestSupport/TestData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/internal/WixBuildTools.TestSupport/TestData.cs')
-rw-r--r--src/internal/WixBuildTools.TestSupport/TestData.cs33
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);