Skip to content

Fix: SettingsProperty constructor ignores serializeAs parameter if it is not SettingsSerializeAs.Binary #106295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public SettingsProperty(
throw new NotSupportedException(Obsoletions.BinaryFormatterMessage);
}
}
else
{
SerializeAs = serializeAs;
}
Attributes = attributes;
ThrowOnErrorDeserializing = throwOnErrorDeserializing;
ThrowOnErrorSerializing = throwOnErrorSerializing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<Compile Include="System\Configuration\SettingsManageabilityAttributeTests.cs" />
<Compile Include="System\Configuration\SettingsPropertyIsReadOnlyExceptionTests.cs" />
<Compile Include="System\Configuration\SettingsPropertyNotFoundExceptionTests.cs" />
<Compile Include="System\Configuration\SettingsPropertyTests.cs" />
<Compile Include="System\Configuration\SettingsPropertyWrongTypeExceptionTests.cs" />
<Compile Include="System\Configuration\SmokeTest.cs" />
<Compile Include="System\Configuration\StringUtilTests.cs" />
Expand All @@ -93,7 +94,7 @@
<Compile Include="System\Configuration\UrlPathTests.cs" />
<Compile Include="System\Configuration\ValidatiorUtilsTests.cs" />
<Compile Include="System\Diagnostics\DiagnosticsTestData.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
<Compile Include="System\Diagnostics\TraceSourceConfigurationTests.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
<Compile Include="System\Diagnostics\TraceSourceConfigurationTests.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
<Compile Include="System\Drawing\Configuration\SystemDrawingSectionTests.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Configuration;
using Xunit;

namespace System.ConfigurationTests
{
public class SettingsPropertyTests
{
[Fact]
public void SettingsProperty_WithNoArguments()
{
var settingsProperty = new SettingsProperty("TestName");
Assert.Equal("TestName", settingsProperty.Name);
Assert.False(settingsProperty.IsReadOnly);
Assert.Null(settingsProperty.DefaultValue);
Assert.Null(settingsProperty.PropertyType);
Assert.Equal(SettingsSerializeAs.String, settingsProperty.SerializeAs);
Assert.Null(settingsProperty.Provider);
Assert.NotNull(settingsProperty.Attributes);
Assert.False(settingsProperty.ThrowOnErrorDeserializing);
Assert.False(settingsProperty.ThrowOnErrorSerializing);
}

[Theory]
[InlineData(SettingsSerializeAs.String)]
[InlineData(SettingsSerializeAs.Xml)]
[InlineData(SettingsSerializeAs.ProviderSpecific)]
public void SettingsProperty_WithArguments(SettingsSerializeAs serializeAs)
{
var settingsProperty = new SettingsProperty(
"TestName",
typeof(string),
provider: null,
isReadOnly: true,
"TestDefaultValue",
serializeAs,
new SettingsAttributeDictionary(),
throwOnErrorDeserializing: true,
throwOnErrorSerializing: false);
Assert.Equal("TestName", settingsProperty.Name);
Assert.True(settingsProperty.IsReadOnly);
Assert.Equal("TestDefaultValue", settingsProperty.DefaultValue);
Assert.Equal(typeof(string), settingsProperty.PropertyType);
Assert.Equal(serializeAs, settingsProperty.SerializeAs);
Assert.Null(settingsProperty.Provider);
Assert.NotNull(settingsProperty.Attributes);
Assert.True(settingsProperty.ThrowOnErrorDeserializing);
Assert.False(settingsProperty.ThrowOnErrorSerializing);
}
}
}