-Fixed MetadataTypeAttribute reflection bug by using CustomAttributeData

-Fixed immutable collections bug by getting type from known assembly
-Added support from running tests on aspnetcore50
This commit is contained in:
James Newton-King
2014-10-18 00:00:26 +13:00
parent 4d09aca2c1
commit 88eeb8ba92
111 changed files with 1193 additions and 573 deletions
+144 -4
View File
@@ -27,6 +27,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;
#if NET20
using Newtonsoft.Json.Serialization;
@@ -35,13 +36,17 @@ using System.Runtime.Serialization.Json;
#endif
using System.Text;
using System.Threading;
#if !NETFX_CORE
using NUnit.Framework;
#else
#if NETFX_CORE
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
using TestMethod = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
using SetUp = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestInitializeAttribute;
#elif ASPNETCORE50
using Xunit;
using Assert = Newtonsoft.Json.Tests.XUnitAssert;
using XAssert = Xunit.Assert;
#else
using NUnit.Framework;
#endif
using Newtonsoft.Json.Utilities;
using System.Collections;
@@ -53,6 +58,137 @@ using System.Linq;
namespace Newtonsoft.Json.Tests
{
public class TestReflectionUtils
{
public static IEnumerable<ConstructorInfo> GetConstructors(Type type)
{
#if !(NETFX_CORE || ASPNETCORE50)
return type.GetConstructors();
#else
return type.GetTypeInfo().DeclaredConstructors;
#endif
}
public static PropertyInfo GetProperty(Type type, string name)
{
#if !(NETFX_CORE || ASPNETCORE50)
return type.GetProperty(name);
#else
return type.GetTypeInfo().GetDeclaredProperty(name);
#endif
}
public static FieldInfo GetField(Type type, string name)
{
#if !(NETFX_CORE || ASPNETCORE50)
return type.GetField(name);
#else
return type.GetTypeInfo().GetDeclaredField(name);
#endif
}
public static MethodInfo GetMethod(Type type, string name)
{
#if !(NETFX_CORE || ASPNETCORE50)
return type.GetMethod(name);
#else
return type.GetTypeInfo().GetDeclaredMethod(name);
#endif
}
}
#if ASPNETCORE50
public class TestFixtureAttribute : Attribute
{
// xunit doesn't need a test fixture attribute
// this exists so the project compiles
}
public class XUnitAssert
{
public static void IsInstanceOf(Type expectedType, object o)
{
XAssert.IsType(expectedType, o);
}
public static void AreEqual(double expected, double actual, double r)
{
XAssert.Equal(expected, actual, 5); // hack
}
public static void AreEqual(object expected, object actual, string message = null)
{
XAssert.Equal(expected, actual);
}
public static void AreEqual<T>(T expected, T actual, string message = null)
{
XAssert.Equal(expected, actual);
}
public static void AreNotEqual(object expected, object actual, string message = null)
{
XAssert.NotEqual(expected, actual);
}
public static void AreNotEqual<T>(T expected, T actual, string message = null)
{
XAssert.NotEqual(expected, actual);
}
public static void Fail(string message = null, params object[] args)
{
if (message != null)
message = message.FormatWith(CultureInfo.InvariantCulture, args);
XAssert.True(false, message);
}
public static void IsTrue(bool condition, string message = null)
{
XAssert.True(condition);
}
public static void IsFalse(bool condition)
{
XAssert.False(condition);
}
public static void IsNull(object o)
{
XAssert.Null(o);
}
public static void IsNotNull(object o)
{
XAssert.NotNull(o);
}
public static void AreNotSame(object expected, object actual)
{
XAssert.NotSame(expected, actual);
}
public static void AreSame(object expected, object actual)
{
XAssert.Same(expected, actual);
}
}
public class CollectionAssert
{
public static void AreEquivalent<T>(IEnumerable<T> expected, IEnumerable<T> actual)
{
XAssert.Equal(expected, actual);
}
public static void AreEqual<T>(IEnumerable<T> expected, IEnumerable<T> actual)
{
XAssert.Equal(expected, actual);
}
}
#endif
[TestFixture]
public abstract class TestFixtureBase
{
@@ -118,8 +254,12 @@ namespace Newtonsoft.Json.Tests
return bytes;
}
#if ASPNETCORE50
protected TestFixtureBase()
#else
[SetUp]
protected void TestSetup()
#endif
{
//#if !NETFX_CORE
// CultureInfo turkey = CultureInfo.CreateSpecificCulture("tr");
@@ -169,7 +309,7 @@ namespace Newtonsoft.Json.Tests
public static void Contains(IList collection, object value, string message)
{
#if !NETFX_CORE
#if !(NETFX_CORE || ASPNETCORE50)
Assert.Contains(value, collection, message);
#else
if (!collection.Cast<object>().Any(i => i.Equals(value)))