Skip to content
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 @@ -95,11 +95,11 @@ private object Deserialize()
{
value = GetObjectFromString(Property.PropertyType, Property.SerializeAs, (string)SerializedValue);
}
else
else if (SerializedValue is byte[] serializedBytes)
{
if (SettingsProperty.EnableUnsafeBinaryFormatterInPropertyValueSerialization)
{
using (MemoryStream ms = new MemoryStream((byte[])SerializedValue))
using (MemoryStream ms = new MemoryStream(serializedBytes))
{
#pragma warning disable SYSLIB0011 // BinaryFormatter serialization is obsolete and should not be used.
value = (new BinaryFormatter()).Deserialize(ms);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<DefineConstants>$(DefineConstants);LEGACY_GETRESOURCESTRING_USER</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(CommonTestPath)TestUtilities\System\DisableParallelization.cs" Link="Common\TestUtilities\System\DisableParallelization.cs" />
<Compile Include="$(CommonTestPath)System\IO\TempDirectory.cs" Link="Common\System\IO\TempDirectory.cs" />
<Compile Include="$(CommonTestPath)System\IO\TempFile.cs" Link="Common\System\IO\TempFile.cs" />
<Compile Include="..\src\System\Configuration\ConfigPathUtility.cs" Link="Source\ConfigPathUtility.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Configuration;
using Xunit;

namespace System.ConfigurationTests
{
[Collection(nameof(DisableParallelization))]
public class LocalFileSettingsProviderTests
{
private readonly SettingsContext _testContext = new SettingsContext
Expand All @@ -14,7 +16,6 @@ public class LocalFileSettingsProviderTests
["SettingsKey"] = "SettingsKeyFoo"
};

[ActiveIssue("https://github.com/dotnet/runtime/issues/29429")]
[Fact]
public void GetPropertyValues_NotStoredProperty_ValueEqualsNull()
{
Expand All @@ -30,7 +31,6 @@ public void GetPropertyValues_NotStoredProperty_ValueEqualsNull()
Assert.Null(propertyValues["PropertyName"].PropertyValue);
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/29429")]
[Fact]
public void GetPropertyValues_NotStoredConnectionStringProperty_ValueEqualsEmptyString()
{
Expand All @@ -47,5 +47,32 @@ public void GetPropertyValues_NotStoredConnectionStringProperty_ValueEqualsEmpty
Assert.Equal(1, propertyValues.Count);
Assert.Equal(string.Empty, propertyValues["PropertyName"].PropertyValue);
}

[Theory]
[InlineData(true)]
[InlineData(42)]
[InlineData(867.5309)]
[InlineData(StringComparison.Ordinal)]
public void GetPropertyValues_DefaultValueApplied(object defaultValue)
{
var provider = new LocalFileSettingsProvider();
var property = new SettingsProperty(
"Test",
defaultValue.GetType(),
provider,
false,
defaultValue,
SettingsSerializeAs.Xml,
new SettingsAttributeDictionary(),
false,
false);
property.Attributes.Add(typeof(UserScopedSettingAttribute), new UserScopedSettingAttribute());

var properties = new SettingsPropertyCollection() { property };
var propertyValues = provider.GetPropertyValues(_testContext, properties);

Assert.Equal(1, propertyValues.Count);
Assert.Equal(defaultValue, propertyValues["Test"].PropertyValue);
}
}
}