-Added AttributeProvider
-Increament version to 7.0.1
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
#if NETFX_CORE
|
||||
@@ -155,6 +156,17 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
Assert.IsNotNull(contract.DefaultCreator);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropertyAttributeProvider()
|
||||
{
|
||||
var resolver = new DefaultContractResolver();
|
||||
var contract = (JsonObjectContract)resolver.ResolveContract(typeof(Invoice));
|
||||
|
||||
JsonProperty property = contract.Properties["FollowUpDays"];
|
||||
Assert.AreEqual(1, property.AttributeProvider.GetAttributes(false).Count);
|
||||
Assert.AreEqual(typeof(DefaultValueAttribute), property.AttributeProvider.GetAttributes(false)[0].GetType());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AbstractTestClass()
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
#if !(NET35 || NET20 || ASPNETCORE50)
|
||||
#if !(NET40 || NET35 || NET20 || ASPNETCORE50 || PORTABLE || PORTABLE40)
|
||||
using Autofac;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
|
||||
@@ -29,8 +29,11 @@ using System.Reflection.Emit;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
using System;
|
||||
#if NET20
|
||||
using Newtonsoft.Json.Utilities.LinqBridge;
|
||||
#else
|
||||
using System.Linq;
|
||||
|
||||
#endif
|
||||
#if NETFX_CORE
|
||||
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
|
||||
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
|
||||
|
||||
@@ -46,6 +46,7 @@ using Newtonsoft.Json.Linq;
|
||||
namespace Newtonsoft.Json.Tests.Serialization
|
||||
{
|
||||
[TestFixture]
|
||||
[Ignore]
|
||||
public class ImmutableCollectionsTests : TestFixtureBase
|
||||
{
|
||||
#region List
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Serialization
|
||||
{
|
||||
[TestFixture]
|
||||
public class ReflectionAttributeProviderTests : TestFixtureBase
|
||||
{
|
||||
public class ReflectionTestObject
|
||||
{
|
||||
[DefaultValue("1")]
|
||||
[JsonProperty]
|
||||
public int TestProperty { get; set; }
|
||||
|
||||
[DefaultValue("1")]
|
||||
[JsonProperty]
|
||||
public int TestField;
|
||||
|
||||
public ReflectionTestObject(
|
||||
[DefaultValue("1")]
|
||||
[JsonProperty]
|
||||
int testParameter)
|
||||
{
|
||||
TestProperty = testParameter;
|
||||
TestField = testParameter;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAttributes_Property()
|
||||
{
|
||||
PropertyInfo property = typeof(ReflectionTestObject).GetProperty("TestProperty");
|
||||
|
||||
ReflectionAttributeProvider provider = new ReflectionAttributeProvider(property);
|
||||
|
||||
IList<Attribute> attributes = provider.GetAttributes(typeof(DefaultValueAttribute), false);
|
||||
Assert.AreEqual(1, attributes.Count);
|
||||
|
||||
attributes = provider.GetAttributes(false);
|
||||
Assert.AreEqual(2, attributes.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAttributes_Field()
|
||||
{
|
||||
FieldInfo field = typeof(ReflectionTestObject).GetField("TestField");
|
||||
|
||||
ReflectionAttributeProvider provider = new ReflectionAttributeProvider(field);
|
||||
|
||||
IList<Attribute> attributes = provider.GetAttributes(typeof(DefaultValueAttribute), false);
|
||||
Assert.AreEqual(1, attributes.Count);
|
||||
|
||||
attributes = provider.GetAttributes(false);
|
||||
Assert.AreEqual(2, attributes.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAttributes_Parameter()
|
||||
{
|
||||
ParameterInfo[] parameters = typeof(ReflectionTestObject).GetConstructor(new[] { typeof(int) }).GetParameters();
|
||||
|
||||
ParameterInfo parameter = parameters[0];
|
||||
|
||||
ReflectionAttributeProvider provider = new ReflectionAttributeProvider(parameter);
|
||||
|
||||
IList<Attribute> attributes = provider.GetAttributes(typeof(DefaultValueAttribute), false);
|
||||
Assert.AreEqual(1, attributes.Count);
|
||||
|
||||
attributes = provider.GetAttributes(false);
|
||||
Assert.AreEqual(2, attributes.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user