コード例 #1
0
        public void ViewManagersPropertyCache_ShadowNode_Set()
        {
            var instance = new ShadowNodeValueTest();

            var setters = ViewManagersPropertyCache.GetNativePropertySettersForShadowNodeType(typeof(ShadowNodeValueTest));

            Assert.AreEqual(3, setters.Count);

            var props = new ReactStylesDiffMap(new JObject
            {
                { "Foo", 42 },
                { "Qux1", "v2" },
                { "Qux2", "v3" },
            });

            AssertEx.Throws <NotSupportedException>(() => setters["Foo"].UpdateViewManagerProperty(new ViewManagerValueTest(), null, props));
            AssertEx.Throws <ArgumentNullException>(
                () => setters["Foo"].UpdateShadowNodeProperty(null, props),
                ex => Assert.AreEqual("shadowNode", ex.ParamName));
            AssertEx.Throws <ArgumentNullException>(
                () => setters["Foo"].UpdateShadowNodeProperty(instance, null),
                ex => Assert.AreEqual("props", ex.ParamName));

            setters["Foo"].UpdateShadowNodeProperty(instance, props);
            setters["Qux1"].UpdateShadowNodeProperty(instance, props);
            setters["Qux2"].UpdateShadowNodeProperty(instance, props);

            Assert.AreEqual(42, instance.FooValue);
            Assert.AreEqual("v2", instance.QuxValues[0]);
            Assert.AreEqual("v3", instance.QuxValues[1]);
        }
コード例 #2
0
        public void ViewManagersPropertyCache_ViewManager_Set()
        {
            var instance = new ViewManagerValueTest();

            var setters = ViewManagersPropertyCache.GetNativePropertySettersForViewManagerType(typeof(ViewManagerValueTest));

            Assert.AreEqual(3, setters.Count);

            var props = new ReactStylesDiffMap(new JObject
            {
                { "Foo", "v1" },
                { "Bar1", "v2" },
                { "Bar2", "v3" },
            });

            Assert.Throws <NotSupportedException>(() => setters["Foo"].UpdateShadowNodeProperty(new ShadowNodeValueTest(), props));
            ArgumentNullException ex1 = Assert.Throws <ArgumentNullException>(
                () => setters["Foo"].UpdateViewManagerProperty(null, null, props));

            Assert.AreEqual("viewManager", ex1.ParamName);
            ArgumentNullException ex2 = Assert.Throws <ArgumentNullException>(
                () => setters["Foo"].UpdateViewManagerProperty(instance, null, null));

            Assert.AreEqual("props", ex2.ParamName);

            setters["Foo"].UpdateViewManagerProperty(instance, null, props);
            setters["Bar1"].UpdateViewManagerProperty(instance, null, props);
            setters["Bar2"].UpdateViewManagerProperty(instance, null, props);

            Assert.AreEqual("v1", instance.FooValue);
            Assert.AreEqual("v2", instance.BarValues[0]);
            Assert.AreEqual("v3", instance.BarValues[1]);
        }
コード例 #3
0
        public void ViewManagersPropertyCache_GetNativePropertiesForView()
        {
            var props = ViewManagersPropertyCache.GetNativePropertiesForView(typeof(ViewManagerValueTest), typeof(ShadowNodeValueTest));

            Assert.AreEqual(5, props.Count);
            Assert.AreEqual("number", props["Foo"]);
            Assert.AreEqual("String", props["Bar1"]);
            Assert.AreEqual("String", props["Bar2"]);
            Assert.AreEqual("String", props["Qux1"]);
            Assert.AreEqual("String", props["Qux2"]);
        }
コード例 #4
0
        public void ViewManagersPropertyCache_ArgumentChecks()
        {
            AssertEx.Throws <ArgumentNullException>(
                () => ViewManagersPropertyCache.GetNativePropertiesForView(null, typeof(object)),
                ex => Assert.AreEqual("viewManagerType", ex.ParamName));

            AssertEx.Throws <ArgumentNullException>(
                () => ViewManagersPropertyCache.GetNativePropertiesForView(typeof(object), null),
                ex => Assert.AreEqual("shadowNodeType", ex.ParamName));

            AssertEx.Throws <ArgumentNullException>(
                () => ViewManagersPropertyCache.GetNativePropertySettersForViewManagerType(null),
                ex => Assert.AreEqual("type", ex.ParamName));

            AssertEx.Throws <ArgumentNullException>(
                () => ViewManagersPropertyCache.GetNativePropertySettersForShadowNodeType
                    (null),
                ex => Assert.AreEqual("type", ex.ParamName));
        }
コード例 #5
0
        public void ViewManagersPropertyCache_ShadowNode_Empty()
        {
            var setters = ViewManagersPropertyCache.GetNativePropertySettersForShadowNodeType(typeof(ReactShadowNode));

            Assert.AreEqual(0, setters.Count);
        }
コード例 #6
0
        public void ViewManagersPropertyCache_Defaults()
        {
            var instance = new DefaultsTest();
            var setters  = ViewManagersPropertyCache.GetNativePropertySettersForViewManagerType(typeof(DefaultsTest));

            var props = new ReactStylesDiffMap(new JObject());

            instance.ByteValue     = byte.MaxValue;
            instance.SByteValue    = sbyte.MaxValue;
            instance.Int16Value    = short.MaxValue;
            instance.UInt16Value   = ushort.MaxValue;
            instance.Int32Value    = int.MaxValue;
            instance.UInt32Value   = uint.MaxValue;
            instance.Int64Value    = long.MaxValue;
            instance.UInt64Value   = ulong.MaxValue;
            instance.SingleValue   = float.MaxValue;
            instance.DoubleValue   = double.MaxValue;
            instance.DecimalValue  = decimal.MaxValue;
            instance.BooleanValue  = true;
            instance.StringValue   = "foo";
            instance.ArrayValue    = new int[0];
            instance.MapValue      = new object();
            instance.NullableValue = true;
            instance.GroupValue    = new[] { "a", "b", "c" };

            setters["TestByte"].UpdateViewManagerProperty(instance, null, props);
            setters["TestSByte"].UpdateViewManagerProperty(instance, null, props);
            setters["TestInt16"].UpdateViewManagerProperty(instance, null, props);
            setters["TestUInt16"].UpdateViewManagerProperty(instance, null, props);
            setters["TestInt32"].UpdateViewManagerProperty(instance, null, props);
            setters["TestUInt32"].UpdateViewManagerProperty(instance, null, props);
            setters["TestInt64"].UpdateViewManagerProperty(instance, null, props);
            setters["TestUInt64"].UpdateViewManagerProperty(instance, null, props);
            setters["TestSingle"].UpdateViewManagerProperty(instance, null, props);
            setters["TestDouble"].UpdateViewManagerProperty(instance, null, props);
            setters["TestDecimal"].UpdateViewManagerProperty(instance, null, props);
            setters["TestBoolean"].UpdateViewManagerProperty(instance, null, props);
            setters["TestString"].UpdateViewManagerProperty(instance, null, props);
            setters["TestArray"].UpdateViewManagerProperty(instance, null, props);
            setters["TestMap"].UpdateViewManagerProperty(instance, null, props);
            setters["TestNullable"].UpdateViewManagerProperty(instance, null, props);
            setters["foo"].UpdateViewManagerProperty(instance, null, props);
            setters["bar"].UpdateViewManagerProperty(instance, null, props);
            setters["baz"].UpdateViewManagerProperty(instance, null, props);

            Assert.AreEqual(0, instance.ByteValue);
            Assert.AreEqual(0, instance.SByteValue);
            Assert.AreEqual(0, instance.Int16Value);
            Assert.AreEqual(0, instance.UInt16Value);
            Assert.AreEqual(0, instance.Int32Value);
            Assert.AreEqual((uint)0, instance.UInt32Value);
            Assert.AreEqual(0, instance.Int64Value);
            Assert.AreEqual((ulong)0, instance.UInt64Value);
            Assert.AreEqual(0, instance.SingleValue);
            Assert.AreEqual(0, instance.DoubleValue);
            Assert.AreEqual(0, instance.DecimalValue);
            Assert.IsFalse(instance.BooleanValue);
            Assert.IsNull(instance.StringValue);
            Assert.IsNull(instance.ArrayValue);
            Assert.IsNull(instance.MapValue);
            Assert.IsFalse(instance.NullableValue.HasValue);
            Assert.IsNull(instance.GroupValue[0]);
            Assert.IsNull(instance.GroupValue[1]);
            Assert.IsNull(instance.GroupValue[2]);
        }