From 85df7be7e82235e4316dc8bdb48e48f00f5d6137 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 30 Nov 2020 08:51:12 +0100 Subject: [PATCH] Added TestEnvironment Signed-off-by: Bjarke Berg --- src/Umbraco.Tests.Common/TestHelperBase.cs | 20 +++++++++++++++++-- .../TestHelpers/TestEnvironment.cs | 13 ++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/Umbraco.Tests.Common/TestHelpers/TestEnvironment.cs diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs index 9485865d8d..f4f55c1de8 100644 --- a/src/Umbraco.Tests.Common/TestHelperBase.cs +++ b/src/Umbraco.Tests.Common/TestHelperBase.cs @@ -24,6 +24,7 @@ using Umbraco.Web; using Umbraco.Web.Routing; using Umbraco.Tests.Common.Builders; using System.Runtime.InteropServices; +using Umbraco.Tests.Common.TestHelpers; namespace Umbraco.Tests.Common { @@ -89,8 +90,23 @@ namespace Umbraco.Tests.Common if (_ioHelper == null) { var hostingEnvironment = GetHostingEnvironment(); - _ioHelper = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? new IOHelperLinux(hostingEnvironment) - : (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? (IIOHelper)new IOHelperOSX(hostingEnvironment) : new IOHelperWindows(hostingEnvironment)); + + if (TestEnvironment.IsWindows) + { + _ioHelper = new IOHelperWindows(hostingEnvironment); + } + else if (TestEnvironment.IsLinux) + { + _ioHelper = new IOHelperLinux(hostingEnvironment); + } + else if (TestEnvironment.IsOSX) + { + _ioHelper = new IOHelperOSX(hostingEnvironment); + } + else + { + throw new NotSupportedException("Unexpected OS"); + } } return _ioHelper; } diff --git a/src/Umbraco.Tests.Common/TestHelpers/TestEnvironment.cs b/src/Umbraco.Tests.Common/TestHelpers/TestEnvironment.cs new file mode 100644 index 0000000000..e5d5d2650e --- /dev/null +++ b/src/Umbraco.Tests.Common/TestHelpers/TestEnvironment.cs @@ -0,0 +1,13 @@ +using System.Runtime.InteropServices; + +namespace Umbraco.Tests.Common.TestHelpers +{ + public static class TestEnvironment + { + public static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); + + public static bool IsOSX => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + + public static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + } +}