public void PropertySetter_ViewManager_PropertyType_Number() { var methods = new[] { (MethodInfo)ReflectionHelpers.InfoOf((Test t) => t.TestByte(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((Test t) => t.TestSByte(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((Test t) => t.TestInt16(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((Test t) => t.TestUInt16(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((Test t) => t.TestInt32(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((Test t) => t.TestUInt32(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((Test t) => t.TestInt64(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((Test t) => t.TestUInt64(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((Test t) => t.TestSingle(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((Test t) => t.TestDouble(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((Test t) => t.TestDecimal(null, 0)), }; foreach (var method in methods) { foreach (var setter in PropertySetter.CreateViewManagerSetters(method)) { Assert.AreEqual("number", setter.PropertyType); } } }
public void PropertySetter_ViewManager_Name() { var method = (MethodInfo)ReflectionHelpers.InfoOf((Test t) => t.TestString(null, null)); var setters = PropertySetter.CreateViewManagerSetters(method); Assert.AreEqual(1, setters.Count()); Assert.AreEqual("TestString", setters.First().Name); }
public void PropertySetter_ArgumentChecks() { AssertEx.Throws <ArgumentNullException>( () => PropertySetter.CreateShadowNodeSetters(null).ToList(), ex => Assert.AreEqual("method", ex.ParamName)); AssertEx.Throws <ArgumentNullException>( () => PropertySetter.CreateViewManagerSetters(null).ToList(), ex => Assert.AreEqual("method", ex.ParamName)); }
public void PropertySetter_ViewManager_PropertyType_String() { var setters = PropertySetter.CreateViewManagerSetters( (MethodInfo)ReflectionHelpers.InfoOf( (Test t) => t.TestString(null, null))); foreach (var setter in setters) { Assert.AreEqual("String", setter.PropertyType); } }
public void PropertySetter_ViewManager_PropertyType_Nullable_Boolean() { var setters = PropertySetter.CreateViewManagerSetters( (MethodInfo)ReflectionHelpers.InfoOf( (Test t) => t.TestNullable(null, false))); foreach (var setter in setters) { Assert.AreEqual("boolean", setter.PropertyType); } }
public void PropertySetter_DefaultValue() { var methods = new[] { (MethodInfo)ReflectionHelpers.InfoOf((DefaultTest t) => t.TestBoolean(null, false)), (MethodInfo)ReflectionHelpers.InfoOf((DefaultTest t) => t.TestByte(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((DefaultTest t) => t.TestSByte(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((DefaultTest t) => t.TestInt16(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((DefaultTest t) => t.TestUInt16(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((DefaultTest t) => t.TestInt32(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((DefaultTest t) => t.TestUInt32(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((DefaultTest t) => t.TestInt64(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((DefaultTest t) => t.TestUInt64(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((DefaultTest t) => t.TestSingle(null, 0)), (MethodInfo)ReflectionHelpers.InfoOf((DefaultTest t) => t.TestDouble(null, 0)), }; var instance = new DefaultTest(); Assert.AreEqual(default(byte), instance.TestByteValue); Assert.AreEqual(default(sbyte), instance.TestSByteValue); Assert.AreEqual(default(short), instance.TestInt16Value); Assert.AreEqual(default(ushort), instance.TestUInt16Value); Assert.AreEqual(default(int), instance.TestInt32Value); Assert.AreEqual(default(uint), instance.TestUInt32Value); Assert.AreEqual(default(long), instance.TestInt64Value); Assert.AreEqual(default(ulong), instance.TestUInt64Value); Assert.AreEqual(default(float), instance.TestSingleValue); Assert.AreEqual(default(double), instance.TestDoubleValue); Assert.AreEqual(false, instance.TestBooleanValue); var emptyMap = new ReactStylesDiffMap(new JObject()); foreach (var method in methods) { var setter = PropertySetter.CreateViewManagerSetters(method).Single(); setter.UpdateViewManagerProperty(instance, null, emptyMap); } Assert.AreEqual(byte.MaxValue, instance.TestByteValue); Assert.AreEqual(sbyte.MaxValue, instance.TestSByteValue); Assert.AreEqual(short.MaxValue, instance.TestInt16Value); Assert.AreEqual(ushort.MaxValue, instance.TestUInt16Value); Assert.AreEqual(int.MaxValue, instance.TestInt32Value); Assert.AreEqual(uint.MaxValue, instance.TestUInt32Value); Assert.AreEqual(long.MaxValue, instance.TestInt64Value); Assert.AreEqual(ulong.MaxValue, instance.TestUInt64Value); Assert.AreEqual(float.MaxValue, instance.TestSingleValue); Assert.AreEqual(double.MaxValue, instance.TestDoubleValue); Assert.AreEqual(true, instance.TestBooleanValue); }
public void PropertySetter_DefaultValue_Undefined() { var method = (MethodInfo)ReflectionHelpers.InfoOf((DefaultTest t) => t.TestBoolean(null, false)); var instance = new DefaultTest(); Assert.AreEqual(false, instance.TestBooleanValue); var emptyMap = new ReactStylesDiffMap(new JObject { { "TestBoolean", JValue.CreateUndefined() }, }); var setter = PropertySetter.CreateViewManagerSetters(method).Single(); setter.UpdateViewManagerProperty(instance, null, emptyMap); Assert.AreEqual(true, instance.TestBooleanValue); }
public void PropertySetter_ViewManager_Group() { var setters = PropertySetter.CreateViewManagerSetters( (MethodInfo)ReflectionHelpers.InfoOf( (Test t) => t.TestGroup(null, 0, null))).ToList(); Assert.AreEqual(3, setters.Count); Assert.IsNotNull(setters.FirstOrDefault(s => s.Name == "foo")); Assert.IsNotNull(setters.FirstOrDefault(s => s.Name == "bar")); Assert.IsNotNull(setters.FirstOrDefault(s => s.Name == "baz")); foreach (var setter in setters) { Assert.AreEqual("String", setter.PropertyType); } }