Skip to content

Commit eb9c01f

Browse files
authored
Fix: SettingsProperty constructor ignores serializeAs parameter if it is not SettingsSerializeAs.Binary (#106295)
* Fix SettingsProperty constructor ignores serializeAs parameter if it is not SettingsSerializeAs.Binary * Add parameter name for null, booleans
1 parent 6a69493 commit eb9c01f

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SettingsProperty.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public SettingsProperty(
5252
throw new NotSupportedException(Obsoletions.BinaryFormatterMessage);
5353
}
5454
}
55+
else
56+
{
57+
SerializeAs = serializeAs;
58+
}
5559
Attributes = attributes;
5660
ThrowOnErrorDeserializing = throwOnErrorDeserializing;
5761
ThrowOnErrorSerializing = throwOnErrorSerializing;

src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<Compile Include="System\Configuration\SettingsManageabilityAttributeTests.cs" />
7979
<Compile Include="System\Configuration\SettingsPropertyIsReadOnlyExceptionTests.cs" />
8080
<Compile Include="System\Configuration\SettingsPropertyNotFoundExceptionTests.cs" />
81+
<Compile Include="System\Configuration\SettingsPropertyTests.cs" />
8182
<Compile Include="System\Configuration\SettingsPropertyWrongTypeExceptionTests.cs" />
8283
<Compile Include="System\Configuration\SmokeTest.cs" />
8384
<Compile Include="System\Configuration\StringUtilTests.cs" />
@@ -93,7 +94,7 @@
9394
<Compile Include="System\Configuration\UrlPathTests.cs" />
9495
<Compile Include="System\Configuration\ValidatiorUtilsTests.cs" />
9596
<Compile Include="System\Diagnostics\DiagnosticsTestData.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
96-
<Compile Include="System\Diagnostics\TraceSourceConfigurationTests.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
97+
<Compile Include="System\Diagnostics\TraceSourceConfigurationTests.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
9798
<Compile Include="System\Drawing\Configuration\SystemDrawingSectionTests.cs" />
9899
</ItemGroup>
99100
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Configuration;
5+
using Xunit;
6+
7+
namespace System.ConfigurationTests
8+
{
9+
public class SettingsPropertyTests
10+
{
11+
[Fact]
12+
public void SettingsProperty_WithNoArguments()
13+
{
14+
var settingsProperty = new SettingsProperty("TestName");
15+
Assert.Equal("TestName", settingsProperty.Name);
16+
Assert.False(settingsProperty.IsReadOnly);
17+
Assert.Null(settingsProperty.DefaultValue);
18+
Assert.Null(settingsProperty.PropertyType);
19+
Assert.Equal(SettingsSerializeAs.String, settingsProperty.SerializeAs);
20+
Assert.Null(settingsProperty.Provider);
21+
Assert.NotNull(settingsProperty.Attributes);
22+
Assert.False(settingsProperty.ThrowOnErrorDeserializing);
23+
Assert.False(settingsProperty.ThrowOnErrorSerializing);
24+
}
25+
26+
[Theory]
27+
[InlineData(SettingsSerializeAs.String)]
28+
[InlineData(SettingsSerializeAs.Xml)]
29+
[InlineData(SettingsSerializeAs.ProviderSpecific)]
30+
public void SettingsProperty_WithArguments(SettingsSerializeAs serializeAs)
31+
{
32+
var settingsProperty = new SettingsProperty(
33+
"TestName",
34+
typeof(string),
35+
provider: null,
36+
isReadOnly: true,
37+
"TestDefaultValue",
38+
serializeAs,
39+
new SettingsAttributeDictionary(),
40+
throwOnErrorDeserializing: true,
41+
throwOnErrorSerializing: false);
42+
Assert.Equal("TestName", settingsProperty.Name);
43+
Assert.True(settingsProperty.IsReadOnly);
44+
Assert.Equal("TestDefaultValue", settingsProperty.DefaultValue);
45+
Assert.Equal(typeof(string), settingsProperty.PropertyType);
46+
Assert.Equal(serializeAs, settingsProperty.SerializeAs);
47+
Assert.Null(settingsProperty.Provider);
48+
Assert.NotNull(settingsProperty.Attributes);
49+
Assert.True(settingsProperty.ThrowOnErrorDeserializing);
50+
Assert.False(settingsProperty.ThrowOnErrorSerializing);
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)