-Added Newtonsoft.Json.Metro build (whew, what a pain!)

-Added .gitignore file
This commit is contained in:
James Newton-King
2012-03-15 18:34:51 +13:00
parent f9e5745425
commit 5800e97ff3
141 changed files with 3921 additions and 1097 deletions
@@ -31,67 +31,86 @@ using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using Newtonsoft.Json.Tests.Linq;
#if !NETFX_CORE
using NUnit.Framework;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestFixture = Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
#endif
using Newtonsoft.Json.Utilities;
using Newtonsoft.Json.Tests.TestObjects;
using Newtonsoft.Json.Tests.Serialization;
namespace Newtonsoft.Json.Tests.Utilities
{
[TestFixture]
public class DynamicReflectionDelegateFactoryTests : TestFixtureBase
{
[Test]
[ExpectedException(typeof(InvalidCastException), ExpectedMessage = "Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.")]
public void CreateGetWithBadObjectTarget()
{
Person p = new Person();
p.Name = "Hi";
ExceptionAssert.Throws<InvalidCastException>("Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.",
() =>
{
Person p = new Person();
p.Name = "Hi";
Func<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateGet<object>(typeof(Movie).GetProperty("Name"));
Func<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateGet<object>(typeof(Movie).GetProperty("Name"));
setter(p);
setter(p);
});
}
[Test]
[ExpectedException(typeof(InvalidCastException), ExpectedMessage = "Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.")]
public void CreateSetWithBadObjectTarget()
{
Person p = new Person();
Movie m = new Movie();
ExceptionAssert.Throws<InvalidCastException>("Unable to cast object of type 'Newtonsoft.Json.Tests.TestObjects.Person' to type 'Newtonsoft.Json.Tests.TestObjects.Movie'.",
() =>
{
Person p = new Person();
Movie m = new Movie();
Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(Movie).GetProperty("Name"));
Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(Movie).GetProperty("Name"));
setter(m, "Hi");
setter(m, "Hi");
Assert.AreEqual(m.Name, "Hi");
Assert.AreEqual(m.Name, "Hi");
setter(p, "Hi");
setter(p, "Hi");
});
}
[Test]
[ExpectedException(typeof(InvalidCastException), ExpectedMessage = "Specified cast is not valid.")]
public void CreateSetWithBadTarget()
{
object structTest = new StructTest();
ExceptionAssert.Throws<InvalidCastException>("Specified cast is not valid.",
() =>
{
object structTest = new StructTest();
Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(StructTest).GetProperty("StringProperty"));
Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(StructTest).GetProperty("StringProperty"));
setter(structTest, "Hi");
setter(structTest, "Hi");
Assert.AreEqual("Hi", ((StructTest)structTest).StringProperty);
Assert.AreEqual("Hi", ((StructTest)structTest).StringProperty);
setter(new TimeSpan(), "Hi");
setter(new TimeSpan(), "Hi");
});
}
[Test]
[ExpectedException(typeof(InvalidCastException), ExpectedMessage = "Unable to cast object of type 'System.Version' to type 'System.String'.")]
public void CreateSetWithBadObjectValue()
{
Movie m = new Movie();
ExceptionAssert.Throws<InvalidCastException>("Unable to cast object of type 'System.Version' to type 'System.String'.",
() =>
{
Movie m = new Movie();
Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(Movie).GetProperty("Name"));
Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(Movie).GetProperty("Name"));
setter(m, new Version());
setter(m, new Version("1.1.1.1"));
});
}
[Test]