From 5147f6db1d7cbeef38d42fd91706747bc25d93eb Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Thu, 1 Apr 2021 11:37:10 +0200 Subject: [PATCH] use a hacky way to run all the tests using new FileStream implementation (which is currently disabled) --- Directory.Build.props | 1 + eng/runtimeconfig.template.json | 5 +++ .../Embedded/test/Net5CompatSwitchTests.cs | 35 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 eng/runtimeconfig.template.json create mode 100644 src/FileProviders/Embedded/test/Net5CompatSwitchTests.cs diff --git a/Directory.Build.props b/Directory.Build.props index c837ed4c35d9..b8fbd0c931ff 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -220,6 +220,7 @@ .tar.gz .zip + $(RepoRoot)eng\runtimeconfig.template.json diff --git a/eng/runtimeconfig.template.json b/eng/runtimeconfig.template.json new file mode 100644 index 000000000000..0c1a3482aba4 --- /dev/null +++ b/eng/runtimeconfig.template.json @@ -0,0 +1,5 @@ +{ + "configProperties": { + "System.IO.UseNet5CompatFileStream": false + } +} diff --git a/src/FileProviders/Embedded/test/Net5CompatSwitchTests.cs b/src/FileProviders/Embedded/test/Net5CompatSwitchTests.cs new file mode 100644 index 000000000000..af9157b8e5c9 --- /dev/null +++ b/src/FileProviders/Embedded/test/Net5CompatSwitchTests.cs @@ -0,0 +1,35 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#if NET6_0 +using System.Reflection; +using Xunit; + +namespace System.IO.Tests +{ + public class Net5CompatSwitchTests + { + [Fact] + public static void LegacySwitchIsHonored() + { + string filePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()); + + using (FileStream fileStream = File.Create(filePath)) + { + object strategy = fileStream + .GetType() + .GetField("_strategy", BindingFlags.NonPublic | BindingFlags.Instance) + .GetValue(fileStream); + + if (OperatingSystem.IsWindows()) + { + Assert.DoesNotContain("Net5Compat", strategy.GetType().FullName); + Assert.DoesNotContain("Legacy", strategy.GetType().FullName); + } + } + + File.Delete(filePath); + } + } +} +#endif