Ejemplo n.º 1
0
        public void NativeModuleBase_Invocation_Callbacks_InvalidArgumentThrows()
        {
            var callbackArgs = new object[] { 1, 2, 3 };
            var module       = new CallbackNativeModule(callbackArgs);

            module.Initialize();

            var nopCallback = new InvokeCallback((_, __) => { });

            AssertEx.Throws <NativeArgumentsParseException>(
                () => module.Methods[nameof(CallbackNativeModule.Foo)].Invoke(nopCallback, JArray.FromObject(new[] { default(object) })),
                ex => Assert.AreEqual("jsArguments", ex.ParamName));
        }
Ejemplo n.º 2
0
        public void NativeModuleBase_Invocation_Callbacks_NullCallback()
        {
            var module = new CallbackNativeModule(null);

            module.Initialize();

            var args = default(List <int>);

            var callback = new InvokeCallback((i, a) =>
            {
                args = a.ToObject <List <int> >();
            });

            module.Methods[nameof(CallbackNativeModule.Foo)].Invoke(callback, JArray.FromObject(new[] { 42 }));
            Assert.AreEqual(0, args.Count);
        }
Ejemplo n.º 3
0
        public void NativeModuleBase_Invocation_Callbacks_InvalidArgumentThrows()
        {
            var callbackArgs = new object[] { 1, 2, 3 };
            var module       = new CallbackNativeModule(callbackArgs);

            module.Initialize();

            var id   = default(int);
            var args = default(List <int>);

            var reactInstance = new MockReactInstance((i, a) =>
            {
                id   = i;
                args = a.ToObject <List <int> >();
            });

            AssertEx.Throws <NativeArgumentsParseException>(
                () => module.Methods[nameof(CallbackNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] { default(object) })),
                ex => Assert.AreEqual("jsArguments", ex.ParamName));
        }
Ejemplo n.º 4
0
        public void NativeModuleBase_Invocation_Callbacks()
        {
            var callbackArgs = new object[] { 1, 2, 3 };
            var module       = new CallbackNativeModule(callbackArgs);

            module.Initialize();

            var id   = default(int);
            var args = default(List <int>);

            var reactInstance = new MockReactInstance((i, a) =>
            {
                id   = i;
                args = a.ToObject <List <int> >();
            });

            module.Methods[nameof(CallbackNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] { 42 }));
            Assert.AreEqual(42, id);
            Assert.IsTrue(args.Cast <object>().SequenceEqual(callbackArgs));
        }
        public void NativeModuleBase_Invocation_Callbacks_NullCallback()
        {
            var module = new CallbackNativeModule(null);
            module.Initialize();

            var id = default(int);
            var args = default(List<int>);

            var reactInstance = new MockReactInstance((i, a) =>
            {
                id = i;
                args = a.ToObject<List<int>>();
            });

            module.Methods[nameof(CallbackNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] { 42 }));
            Assert.AreEqual(0, args.Count);
        }
        public void NativeModuleBase_Invocation_Callbacks_InvalidArgumentThrows()
        {
            var callbackArgs = new object[] { 1, 2, 3 };
            var module = new CallbackNativeModule(callbackArgs);
            module.Initialize();

            var id = default(int);
            var args = default(List<int>);

            var reactInstance = new MockReactInstance((i, a) =>
            {
                id = i;
                args = a.ToObject<List<int>>();
            });

            AssertEx.Throws<NativeArgumentsParseException>(
                () => module.Methods[nameof(CallbackNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] { default(object) })),
                ex => Assert.AreEqual("arguments", ex.ParamName));
        }
        public void NativeModuleBase_Invocation_Callbacks()
        {
            var callbackArgs = new object[] { 1, 2, 3 };
            var module = new CallbackNativeModule(callbackArgs);
            module.Initialize();

            var id = default(int);
            var args = default(List<int>);

            var reactInstance = new MockReactInstance((i, a) =>
            {
                id = i;
                args = a.ToObject<List<int>>();
            });

            module.Methods[nameof(CallbackNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] { 42 }));
            Assert.AreEqual(42, id);
            Assert.IsTrue(args.Cast<object>().SequenceEqual(callbackArgs));
        }