-Fixed deserializing classes derived from ConcurrentDictionary
-Updated to latest immutable collections -Tests
This commit is contained in:
@@ -78,9 +78,9 @@
|
||||
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Collections.Immutable, Version=1.1.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Reference Include="System.Collections.Immutable, Version=1.1.33.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\System.Collections.Immutable.1.1.33-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
|
||||
<HintPath>..\packages\System.Collections.Immutable.1.1.34-rc\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ComponentModel.DataAnnotations">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
|
||||
@@ -44,9 +44,9 @@
|
||||
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Collections.Immutable, Version=1.1.33.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\System.Collections.Immutable.1.1.33-beta\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
|
||||
<Reference Include="System.Collections.Immutable, Version=1.1.34.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Collections.Immutable.1.1.34-rc\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
|
||||
@@ -76,4 +76,4 @@ using System.Security;
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly: AssemblyVersion("7.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("7.0.1.18402")]
|
||||
[assembly: AssemblyFileVersion("7.0.1.18405")]
|
||||
|
||||
@@ -46,7 +46,6 @@ using Newtonsoft.Json.Linq;
|
||||
namespace Newtonsoft.Json.Tests.Serialization
|
||||
{
|
||||
[TestFixture]
|
||||
[Ignore]
|
||||
public class ImmutableCollectionsTests : TestFixtureBase
|
||||
{
|
||||
#region List
|
||||
@@ -441,5 +440,4 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -26,6 +26,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.Runtime.Serialization;
|
||||
#if !(NET35 || NET20 || PORTABLE || DNXCORE50 || PORTABLE40)
|
||||
using System.Collections.Concurrent;
|
||||
#endif
|
||||
@@ -73,6 +74,57 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !(NET35 || NET20 || PORTABLE || PORTABLE40)
|
||||
public class SomeObject
|
||||
{
|
||||
public string Text1 { get; set; }
|
||||
}
|
||||
|
||||
public class CustomConcurrentDictionary : ConcurrentDictionary<string, List<SomeObject>>
|
||||
{
|
||||
[OnDeserialized]
|
||||
internal void OnDeserializedMethod(StreamingContext context)
|
||||
{
|
||||
((IDictionary)this).Add("key2", new List<SomeObject>
|
||||
{
|
||||
new SomeObject
|
||||
{
|
||||
Text1 = "value2"
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeCustomConcurrentDictionary()
|
||||
{
|
||||
IDictionary d = new CustomConcurrentDictionary();
|
||||
d.Add("key", new List<SomeObject>
|
||||
{
|
||||
new SomeObject
|
||||
{
|
||||
Text1 = "value1"
|
||||
}
|
||||
});
|
||||
|
||||
string json = JsonConvert.SerializeObject(d, Formatting.Indented);
|
||||
|
||||
Assert.AreEqual(@"{
|
||||
""key"": [
|
||||
{
|
||||
""Text1"": ""value1""
|
||||
}
|
||||
]
|
||||
}", json);
|
||||
|
||||
CustomConcurrentDictionary d2 = JsonConvert.DeserializeObject<CustomConcurrentDictionary>(json);
|
||||
|
||||
Assert.AreEqual(2, d2.Count);
|
||||
Assert.AreEqual("value1", d2["key"][0].Text1);
|
||||
Assert.AreEqual("value2", d2["key2"][0].Text1);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void MultiDObjectArray()
|
||||
{
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
<package id="Autofac" version="3.5.0" targetFramework="net45" />
|
||||
<package id="FSharp.Core" version="4.0.0" targetFramework="net45" />
|
||||
<package id="NUnit" version="2.6.2" targetFramework="net45" />
|
||||
<package id="System.Collections.Immutable" version="1.1.33-beta" targetFramework="net45" />
|
||||
<package id="System.Collections.Immutable" version="1.1.34-rc" targetFramework="net45" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user