diff options
7 files changed, 36 insertions, 152 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); |
diff --git a/src/test/burn/WixToolsetTest.BurnE2E/Utilities/TestExeTool.cs b/src/test/burn/WixToolsetTest.BurnE2E/Utilities/TestExeTool.cs index a02299d7..07442cd3 100644 --- a/src/test/burn/WixToolsetTest.BurnE2E/Utilities/TestExeTool.cs +++ b/src/test/burn/WixToolsetTest.BurnE2E/Utilities/TestExeTool.cs | |||
@@ -7,7 +7,7 @@ namespace WixTestTools | |||
7 | 7 | ||
8 | public class TestExeTool : TestTool | 8 | public class TestExeTool : TestTool |
9 | { | 9 | { |
10 | private static readonly string TestExePath32 = Path.Combine(TestData.Get(), "win-x86", "TestExe.exe"); | 10 | private static readonly string TestExePath32 = TestData.Get("win-x86", "TestExe.exe"); |
11 | 11 | ||
12 | public TestExeTool() | 12 | public TestExeTool() |
13 | : base(TestExePath32) | 13 | : base(TestExePath32) |
diff --git a/src/wix/test/WixToolsetTest.Core.Native/CabinetFixture.cs b/src/wix/test/WixToolsetTest.Core.Native/CabinetFixture.cs index 0d5d777d..c566339a 100644 --- a/src/wix/test/WixToolsetTest.Core.Native/CabinetFixture.cs +++ b/src/wix/test/WixToolsetTest.Core.Native/CabinetFixture.cs | |||
@@ -4,9 +4,9 @@ namespace WixToolsetTest.CoreNative | |||
4 | { | 4 | { |
5 | using System.IO; | 5 | using System.IO; |
6 | using System.Linq; | 6 | using System.Linq; |
7 | using WixBuildTools.TestSupport; | ||
7 | using WixToolset.Core.Native; | 8 | using WixToolset.Core.Native; |
8 | using WixToolset.Data; | 9 | using WixToolset.Data; |
9 | using WixToolsetTest.CoreNative.Utility; | ||
10 | using Xunit; | 10 | using Xunit; |
11 | 11 | ||
12 | public class CabinetFixture | 12 | public class CabinetFixture |
diff --git a/src/wix/test/WixToolsetTest.Core.Native/CertificateHashesFixture.cs b/src/wix/test/WixToolsetTest.Core.Native/CertificateHashesFixture.cs index beb5224c..9f8a31f6 100644 --- a/src/wix/test/WixToolsetTest.Core.Native/CertificateHashesFixture.cs +++ b/src/wix/test/WixToolsetTest.Core.Native/CertificateHashesFixture.cs | |||
@@ -3,8 +3,8 @@ | |||
3 | namespace WixToolsetTest.CoreNative | 3 | namespace WixToolsetTest.CoreNative |
4 | { | 4 | { |
5 | using System.Linq; | 5 | using System.Linq; |
6 | using WixBuildTools.TestSupport; | ||
6 | using WixToolset.Core.Native; | 7 | using WixToolset.Core.Native; |
7 | using WixToolsetTest.CoreNative.Utility; | ||
8 | using Xunit; | 8 | using Xunit; |
9 | 9 | ||
10 | public class CertificateHashesFixture | 10 | public class CertificateHashesFixture |
diff --git a/src/wix/test/WixToolsetTest.Core.Native/Utility/DisposableFileSystem.cs b/src/wix/test/WixToolsetTest.Core.Native/Utility/DisposableFileSystem.cs deleted file mode 100644 index c9957247..00000000 --- a/src/wix/test/WixToolsetTest.Core.Native/Utility/DisposableFileSystem.cs +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | namespace WixToolsetTest.CoreNative.Utility | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.IO; | ||
8 | |||
9 | public class DisposableFileSystem : IDisposable | ||
10 | { | ||
11 | protected bool Disposed { get; private set; } | ||
12 | |||
13 | private List<string> CleanupPaths { get; } = new List<string>(); | ||
14 | |||
15 | public string GetFile(bool create = false) | ||
16 | { | ||
17 | var path = Path.GetTempFileName(); | ||
18 | |||
19 | if (!create) | ||
20 | { | ||
21 | File.Delete(path); | ||
22 | } | ||
23 | |||
24 | this.CleanupPaths.Add(path); | ||
25 | |||
26 | return path; | ||
27 | } | ||
28 | |||
29 | public string GetFolder(bool create = false) | ||
30 | { | ||
31 | var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); | ||
32 | |||
33 | if (create) | ||
34 | { | ||
35 | Directory.CreateDirectory(path); | ||
36 | } | ||
37 | |||
38 | this.CleanupPaths.Add(path); | ||
39 | |||
40 | return path; | ||
41 | } | ||
42 | |||
43 | |||
44 | #region // IDisposable | ||
45 | |||
46 | public void Dispose() | ||
47 | { | ||
48 | this.Dispose(true); | ||
49 | GC.SuppressFinalize(this); | ||
50 | } | ||
51 | |||
52 | protected virtual void Dispose(bool disposing) | ||
53 | { | ||
54 | if (this.Disposed) | ||
55 | { | ||
56 | return; | ||
57 | } | ||
58 | |||
59 | if (disposing) | ||
60 | { | ||
61 | foreach (var path in this.CleanupPaths) | ||
62 | { | ||
63 | try | ||
64 | { | ||
65 | if (File.Exists(path)) | ||
66 | { | ||
67 | File.Delete(path); | ||
68 | } | ||
69 | else if (Directory.Exists(path)) | ||
70 | { | ||
71 | Directory.Delete(path, true); | ||
72 | } | ||
73 | } | ||
74 | catch | ||
75 | { | ||
76 | // Best effort delete, so ignore any failures. | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | |||
81 | this.Disposed = true; | ||
82 | } | ||
83 | |||
84 | #endregion | ||
85 | } | ||
86 | } | ||
diff --git a/src/wix/test/WixToolsetTest.Core.Native/Utility/Pushd.cs b/src/wix/test/WixToolsetTest.Core.Native/Utility/Pushd.cs deleted file mode 100644 index 91700c2f..00000000 --- a/src/wix/test/WixToolsetTest.Core.Native/Utility/Pushd.cs +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | namespace WixToolsetTest.CoreNative.Utility | ||
4 | { | ||
5 | using System; | ||
6 | using System.IO; | ||
7 | |||
8 | public class Pushd : IDisposable | ||
9 | { | ||
10 | protected bool Disposed { get; private set; } | ||
11 | |||
12 | public Pushd(string path) | ||
13 | { | ||
14 | this.PreviousDirectory = Directory.GetCurrentDirectory(); | ||
15 | |||
16 | Directory.SetCurrentDirectory(path); | ||
17 | } | ||
18 | |||
19 | public string PreviousDirectory { get; } | ||
20 | |||
21 | #region // IDisposable | ||
22 | |||
23 | public void Dispose() | ||
24 | { | ||
25 | this.Dispose(true); | ||
26 | GC.SuppressFinalize(this); | ||
27 | } | ||
28 | |||
29 | protected virtual void Dispose(bool disposing) | ||
30 | { | ||
31 | if (this.Disposed) | ||
32 | { | ||
33 | return; | ||
34 | } | ||
35 | |||
36 | if (disposing) | ||
37 | { | ||
38 | Directory.SetCurrentDirectory(this.PreviousDirectory); | ||
39 | } | ||
40 | |||
41 | this.Disposed = true; | ||
42 | } | ||
43 | |||
44 | #endregion | ||
45 | } | ||
46 | } | ||
diff --git a/src/wix/test/WixToolsetTest.Core.Native/Utility/TestData.cs b/src/wix/test/WixToolsetTest.Core.Native/Utility/TestData.cs deleted file mode 100644 index cd9c6318..00000000 --- a/src/wix/test/WixToolsetTest.Core.Native/Utility/TestData.cs +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | namespace WixToolsetTest.CoreNative.Utility | ||
4 | { | ||
5 | using System; | ||
6 | using System.IO; | ||
7 | |||
8 | public class TestData | ||
9 | { | ||
10 | public static string LocalPath => Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath); | ||
11 | |||
12 | public static string Get(params string[] paths) | ||
13 | { | ||
14 | return Path.Combine(LocalPath, Path.Combine(paths)); | ||
15 | } | ||
16 | } | ||
17 | } | ||