diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-11-29 22:11:32 -0800 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-11-29 22:11:32 -0800 |
| commit | b387913d0e76aa7863f8766868cd2fb3b3fffcde (patch) | |
| tree | 489c84a68c6a2932efe99def3ebc81e926d07a36 /src/test/WixToolsetTest.CoreIntegration/Utility | |
| parent | 71c52d5af2293d3eb79882ce36b0411f81185c11 (diff) | |
| download | wix-b387913d0e76aa7863f8766868cd2fb3b3fffcde.tar.gz wix-b387913d0e76aa7863f8766868cd2fb3b3fffcde.tar.bz2 wix-b387913d0e76aa7863f8766868cd2fb3b3fffcde.zip | |
Remove "Fixture" from the test assembly name
Diffstat (limited to 'src/test/WixToolsetTest.CoreIntegration/Utility')
3 files changed, 149 insertions, 0 deletions
diff --git a/src/test/WixToolsetTest.CoreIntegration/Utility/DisposableFileSystem.cs b/src/test/WixToolsetTest.CoreIntegration/Utility/DisposableFileSystem.cs new file mode 100644 index 00000000..795d344a --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/Utility/DisposableFileSystem.cs | |||
| @@ -0,0 +1,86 @@ | |||
| 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.CoreIntegration.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 | protected 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/test/WixToolsetTest.CoreIntegration/Utility/Pushd.cs b/src/test/WixToolsetTest.CoreIntegration/Utility/Pushd.cs new file mode 100644 index 00000000..efd733a7 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/Utility/Pushd.cs | |||
| @@ -0,0 +1,46 @@ | |||
| 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.CoreIntegration.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/test/WixToolsetTest.CoreIntegration/Utility/TestData.cs b/src/test/WixToolsetTest.CoreIntegration/Utility/TestData.cs new file mode 100644 index 00000000..e3b21183 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/Utility/TestData.cs | |||
| @@ -0,0 +1,17 @@ | |||
| 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.CoreIntegration.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 | } | ||
