diff --git a/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs b/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs index c0bf23fe91d618..cce2ce07575f11 100644 --- a/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs +++ b/src/libraries/Common/tests/TestUtilities/System/IO/FileCleanupTestBase.cs @@ -84,11 +84,12 @@ protected virtual void Dispose(bool disposing) protected string GetRandomLinkName() => GetTestFileName() + ".link"; protected string GetRandomDirName() => GetTestFileName() + "_dir"; - protected string GetRandomFilePath() => Path.Combine(ActualTestDirectory.Value, GetRandomFileName()); - protected string GetRandomLinkPath() => Path.Combine(ActualTestDirectory.Value, GetRandomLinkName()); - protected string GetRandomDirPath() => Path.Combine(ActualTestDirectory.Value, GetRandomDirName()); + protected string GetRandomFilePath() => Path.Combine(TestDirectoryActualCasing, GetRandomFileName()); + protected string GetRandomLinkPath() => Path.Combine(TestDirectoryActualCasing, GetRandomLinkName()); + protected string GetRandomDirPath() => Path.Combine(TestDirectoryActualCasing, GetRandomDirName()); - private Lazy ActualTestDirectory => new Lazy(() => GetTestDirectoryActualCasing()); + private string _testDirectoryActualCasing; + private string TestDirectoryActualCasing => _testDirectoryActualCasing ??= GetTestDirectoryActualCasing(); /// Gets a test file full path that is associated with the call site. /// An optional index value to use as a suffix on the file name. Typically a loop index. diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index f92ec2a8c0bb2d..67618c72842878 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -23,7 +23,7 @@ public static partial class PlatformDetection // do it in a way that failures don't cascade. // - private static Lazy s_IsInHelix => new Lazy(() => Environment.GetEnvironmentVariables().Keys.Cast().Any(key => key.StartsWith("HELIX"))); + private static readonly Lazy s_IsInHelix = new Lazy(() => Environment.GetEnvironmentVariables().Keys.Cast().Any(key => key.StartsWith("HELIX"))); public static bool IsInHelix => s_IsInHelix.Value; public static bool IsNetCore => Environment.Version.Major >= 5 || RuntimeInformation.FrameworkDescription.StartsWith(".NET Core", StringComparison.OrdinalIgnoreCase); @@ -66,9 +66,9 @@ public static partial class PlatformDetection public static bool Is64BitProcess => IntPtr.Size == 8; public static bool IsNotWindows => !IsWindows; - private static Lazy s_isCheckedRuntime => new Lazy(() => AssemblyConfigurationEquals("Checked")); - private static Lazy s_isReleaseRuntime => new Lazy(() => AssemblyConfigurationEquals("Release")); - private static Lazy s_isDebugRuntime => new Lazy(() => AssemblyConfigurationEquals("Debug")); + private static readonly Lazy s_isCheckedRuntime = new Lazy(() => AssemblyConfigurationEquals("Checked")); + private static readonly Lazy s_isReleaseRuntime = new Lazy(() => AssemblyConfigurationEquals("Release")); + private static readonly Lazy s_isDebugRuntime = new Lazy(() => AssemblyConfigurationEquals("Debug")); public static bool IsCheckedRuntime => s_isCheckedRuntime.Value; public static bool IsReleaseRuntime => s_isReleaseRuntime.Value; @@ -209,7 +209,7 @@ public static bool IsMetadataTokenSupported // Linux - OpenSsl supports alpn from openssl 1.0.2 and higher. // OSX - SecureTransport doesn't expose alpn APIs. TODO https://github.com/dotnet/runtime/issues/27727 // Android - Platform supports alpn from API level 29 and higher - private static Lazy s_supportsAlpn = new Lazy(GetAlpnSupport); + private static readonly Lazy s_supportsAlpn = new Lazy(GetAlpnSupport); private static bool GetAlpnSupport() { if (IsWindows && !IsWindows7 && !IsNetFramework) @@ -238,11 +238,11 @@ private static bool GetAlpnSupport() public static bool SupportsAlpn => s_supportsAlpn.Value; public static bool SupportsClientAlpn => SupportsAlpn || IsOSX || IsMacCatalyst || IsiOS || IstvOS; - private static Lazy s_supportsTls10 = new Lazy(GetTls10Support); - private static Lazy s_supportsTls11 = new Lazy(GetTls11Support); - private static Lazy s_supportsTls12 = new Lazy(GetTls12Support); - private static Lazy s_supportsTls13 = new Lazy(GetTls13Support); - private static Lazy s_sendsCAListByDefault = new Lazy(GetSendsCAListByDefault); + private static readonly Lazy s_supportsTls10 = new Lazy(GetTls10Support); + private static readonly Lazy s_supportsTls11 = new Lazy(GetTls11Support); + private static readonly Lazy s_supportsTls12 = new Lazy(GetTls12Support); + private static readonly Lazy s_supportsTls13 = new Lazy(GetTls13Support); + private static readonly Lazy s_sendsCAListByDefault = new Lazy(GetSendsCAListByDefault); public static bool SupportsTls10 => s_supportsTls10.Value; public static bool SupportsTls11 => s_supportsTls11.Value; @@ -251,7 +251,7 @@ private static bool GetAlpnSupport() public static bool SendsCAListByDefault => s_sendsCAListByDefault.Value; public static bool SupportsSendingCustomCANamesInTls => UsesAppleCrypto || IsOpenSslSupported || (PlatformDetection.IsWindows8xOrLater && SendsCAListByDefault); - private static Lazy s_largeArrayIsNotSupported = new Lazy(IsLargeArrayNotSupported); + private static readonly Lazy s_largeArrayIsNotSupported = new Lazy(IsLargeArrayNotSupported); [MethodImpl(MethodImplOptions.NoOptimization)] private static bool IsLargeArrayNotSupported()