From 51378119bd5877cab4c54dc64c853ff3b9dee5fa Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Thu, 1 Apr 2021 16:21:42 +0200 Subject: [PATCH] use a hacky way to run all the tests using new FileStream implementation --- src/Tests/Common/runtimeconfig.template.json | 5 ++- .../dotnet.Tests/Net5CompatSwitchTests.cs | 42 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/Tests/dotnet.Tests/Net5CompatSwitchTests.cs diff --git a/src/Tests/Common/runtimeconfig.template.json b/src/Tests/Common/runtimeconfig.template.json index 2c73f3989069..4fe34ff40af3 100644 --- a/src/Tests/Common/runtimeconfig.template.json +++ b/src/Tests/Common/runtimeconfig.template.json @@ -1,3 +1,6 @@ { - "rollForwardOnNoCandidateFx": 2 + "rollForwardOnNoCandidateFx": 2, + "configProperties": { + "System.IO.UseNet5CompatFileStream": false + } } \ No newline at end of file diff --git a/src/Tests/dotnet.Tests/Net5CompatSwitchTests.cs b/src/Tests/dotnet.Tests/Net5CompatSwitchTests.cs new file mode 100644 index 000000000000..4bc7296575dc --- /dev/null +++ b/src/Tests/dotnet.Tests/Net5CompatSwitchTests.cs @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#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) + ?? null; + + if (OperatingSystem.IsWindows()) + { + if (strategy == null) + { + throw new Exception("using an old build"); + } + + Assert.DoesNotContain("Net5Compat", strategy.GetType().FullName); + Assert.DoesNotContain("Legacy", strategy.GetType().FullName); + } + } + + File.Delete(filePath); + } + } +} +#endif