-Code reformat

This commit is contained in:
James Newton-King
2013-10-20 15:08:39 +13:00
parent d03963016e
commit bcd6982419
466 changed files with 71645 additions and 71598 deletions
@@ -41,92 +41,93 @@ using Newtonsoft.Json.Tests.Serialization;
namespace Newtonsoft.Json.Tests.Utilities
{
[TestFixture]
public class DynamicReflectionDelegateFactoryTests : TestFixtureBase
{
[Test]
public void CreateGetWithBadObjectTarget()
[TestFixture]
public class DynamicReflectionDelegateFactoryTests : TestFixtureBase
{
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";
[Test]
public void CreateGetWithBadObjectTarget()
{
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]
public void CreateSetWithBadObjectTarget()
{
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"));
setter(m, "Hi");
Assert.AreEqual(m.Name, "Hi");
setter(p, "Hi");
Assert.AreEqual(p.Name, "Hi");
});
}
[Test]
public void CreateSetWithBadTarget()
{
ExceptionAssert.Throws<InvalidCastException>("Specified cast is not valid.",
() =>
{
object structTest = new StructTest();
Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(StructTest).GetProperty("StringProperty"));
setter(structTest, "Hi");
Assert.AreEqual("Hi", ((StructTest)structTest).StringProperty);
setter(new TimeSpan(), "Hi");
});
}
[Test]
public void CreateSetWithBadObjectValue()
{
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"));
setter(m, new Version("1.1.1.1"));
});
}
[Test]
public void CreateStaticMethodCall()
{
MethodInfo castMethodInfo = typeof(JsonSerializerTest.DictionaryKey).GetMethod("op_Implicit", new[] { typeof(string) });
Assert.IsNotNull(castMethodInfo);
MethodCall<object, object> call = DynamicReflectionDelegateFactory.Instance.CreateMethodCall<object>(castMethodInfo);
object result = call(null, "First!");
Assert.IsNotNull(result);
JsonSerializerTest.DictionaryKey key = (JsonSerializerTest.DictionaryKey)result;
Assert.AreEqual("First!", key.Value);
}
}
[Test]
public void CreateSetWithBadObjectTarget()
{
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"));
setter(m, "Hi");
Assert.AreEqual(m.Name, "Hi");
setter(p, "Hi");
Assert.AreEqual(p.Name, "Hi");
});
}
[Test]
public void CreateSetWithBadTarget()
{
ExceptionAssert.Throws<InvalidCastException>("Specified cast is not valid.",
() =>
{
object structTest = new StructTest();
Action<object, object> setter = DynamicReflectionDelegateFactory.Instance.CreateSet<object>(typeof(StructTest).GetProperty("StringProperty"));
setter(structTest, "Hi");
Assert.AreEqual("Hi", ((StructTest)structTest).StringProperty);
setter(new TimeSpan(), "Hi");
});
}
[Test]
public void CreateSetWithBadObjectValue()
{
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"));
setter(m, new Version("1.1.1.1"));
});
}
[Test]
public void CreateStaticMethodCall()
{
MethodInfo castMethodInfo = typeof(JsonSerializerTest.DictionaryKey).GetMethod("op_Implicit", new[] { typeof(string) });
Assert.IsNotNull(castMethodInfo);
MethodCall<object, object> call = DynamicReflectionDelegateFactory.Instance.CreateMethodCall<object>(castMethodInfo);
object result = call(null, "First!");
Assert.IsNotNull(result);
JsonSerializerTest.DictionaryKey key = (JsonSerializerTest.DictionaryKey) result;
Assert.AreEqual("First!", key.Value);
}
}
}
#endif