Skip to content

Commit

Permalink
Update unit tests to work with BF killbit
Browse files Browse the repository at this point in the history
  • Loading branch information
GrabYourPitchforks committed Apr 5, 2023
1 parent 13e3ca7 commit 26aa7dd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@

<!-- Warnings that should be disabled in our test projects. -->
<PropertyGroup Condition="'$(IsTestProject)' == 'true' or '$(IsTestSupportProject)' == 'true' or '$(IsPublishedAppTestProject)' == 'true'">
<!-- don't warn on usage of BinaryFormatter and legacy formatter infrastructure from test projects -->
<!-- some of our unit tests exercise legacy serialization infrastructure; ensure these continue to work and don't warn on usage -->
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
<NoWarn>$(NoWarn);SYSLIB0011;SYSLIB0050;SYSLIB0051</NoWarn>
<!-- don't warn about unnecessary trim warning suppressions. can be removed with preview 6. -->
<NoWarn>$(NoWarn);IL2121</NoWarn>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ public static void DisabledAlwaysInBrowser()
Assert.Contains(MoreInfoUrl, ex.Message, StringComparison.Ordinal); // error message should link to the more info URL
}

[ConditionalFact(nameof(ShouldRunFullFeatureSwitchEnablementChecks))]
public static void EnabledThroughFeatureSwitch()
{
RemoteInvokeOptions options = new RemoteInvokeOptions();
options.RuntimeConfigurationOptions[EnableBinaryFormatterSwitchName] = bool.TrueString;

RemoteExecutor.Invoke(() =>
{
// Test serialization
MemoryStream ms = new MemoryStream();
new BinaryFormatter().Serialize(ms, "A string to serialize.");
// Test round-trippability
ms.Position = 0;
object roundTripped = new BinaryFormatter().Deserialize(ms);
Assert.Equal("A string to serialize.", roundTripped);
}, options).Dispose();
}

[ConditionalFact(nameof(ShouldRunFullFeatureSwitchEnablementChecks))]
public static void DisabledThroughFeatureSwitch()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-freebsd;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-solaris;$(NetCoreAppCurrent)-linux;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;net48</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<!--
We're testing the BinaryFormatter enablement / disablement switch, so we need to suppress any inherited behavior.
The specific combination below accomplishes this. Normal apps should *NOT* set this combination of switches and
should instead set the switches documented at https://aka.ms/binaryformatter.
-->
<_ProjectTypeRequiresBinaryFormatter>true</_ProjectTypeRequiresBinaryFormatter>
<EnableUnsafeBinaryFormatterSerialization><!-- intentionally left blank --></EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>
<ItemGroup>
<Compile Include="BinaryFormatterTestData.cs" />
<Compile Include="BinaryFormatterTests.cs" />
Expand Down

0 comments on commit 26aa7dd

Please sign in to comment.