public void NativeModuleBase_Invocation_ArgumentInvalidCount()
        {
            var testModule = new TestNativeModule();

            testModule.Initialize();

            var reactInstance = new MockReactInstance();
            AssertEx.Throws<NativeArgumentsParseException>(
                () => testModule.Methods[nameof(TestNativeModule.Bar)].Invoke(reactInstance, new JArray()),
                ex => Assert.AreEqual("jsArguments", ex.ParamName));
        }
        public void NativeModuleBase_Invocation_ArgumentConversionException()
        {
            var testModule = new TestNativeModule();

            testModule.Initialize();

            var reactInstance = new MockReactInstance();
            AssertEx.Throws<NativeArgumentsParseException>(
                () => testModule.Methods[nameof(TestNativeModule.Bar)].Invoke(reactInstance, JArray.FromObject(new[] { default(object) })),
                ex => Assert.AreEqual("arguments", ex.ParamName));
        }
        public void NativeModuleBase_Invocation_ArgumentNull()
        {
            var testModule = new TestNativeModule();

            testModule.Initialize();

            var reactInstance = new MockReactInstance();
            AssertEx.Throws<ArgumentNullException>(
                () => testModule.Methods[nameof(TestNativeModule.Foo)].Invoke(null, new JArray()),
                ex => Assert.AreEqual("reactInstance", ex.ParamName));
            AssertEx.Throws<ArgumentNullException>(
                () => testModule.Methods[nameof(TestNativeModule.Foo)].Invoke(reactInstance, null),
                ex => Assert.AreEqual("jsArguments", ex.ParamName));
        }
        public void NativeModuleBase_ReflectionDelegateFactory_Perf()
        {
            var module        = new PerfNativeModule(ReflectionReactDelegateFactory.Instance);
            var reactInstance = new MockReactInstance();
            var args          = JArray.FromObject(new[] { 42 });

            module.Initialize();

            var n = 100000;

            for (var i = 0; i < n; ++i)
            {
                module.Methods[nameof(PerfNativeModule.Foo)].Invoke(reactInstance, args);
            }
        }
        public void NativeModuleBase_Invocation_ArgumentNull()
        {
            var testModule = new TestNativeModule();

            testModule.Initialize();

            var reactInstance = new MockReactInstance();

            AssertEx.Throws <ArgumentNullException>(
                () => testModule.Methods[nameof(TestNativeModule.Foo)].Invoke(null, new JArray()),
                ex => Assert.AreEqual("reactInstance", ex.ParamName));
            AssertEx.Throws <ArgumentNullException>(
                () => testModule.Methods[nameof(TestNativeModule.Foo)].Invoke(reactInstance, null),
                ex => Assert.AreEqual("jsArguments", ex.ParamName));
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        public void NativeModuleBase_Invocation_Promises_IncorrectArgumentCount()
        {
            var module = new PromiseNativeModule(() => null);

            module.Initialize();

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

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

            AssertEx.Throws <NativeArgumentsParseException>(
                () => module.Methods[nameof(PromiseNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] { 42 })),
                ex => Assert.AreEqual("jsArguments", ex.ParamName));
        }
Ejemplo n.º 8
0
        public void NativeModuleBase_Invocation_Promises_Resolve()
        {
            var module = new PromiseNativeModule(() => 17);

            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(PromiseNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] { 42, 43 }));
            Assert.AreEqual(42, id);
            Assert.IsTrue(args.SequenceEqual(new[] { 17 }));
        }
Ejemplo n.º 9
0
        public void NativeModuleBase_Invocation_Promises_NullCallback()
        {
            var module = new PromiseNativeModule(() => null);

            module.Initialize();

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

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

            module.Methods[nameof(PromiseNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] { 42, 43 }));
            Assert.AreEqual(1, args.Count);
            Assert.IsNull(args[0]);
        }
Ejemplo n.º 10
0
        public void NativeModuleBase_Invocation()
        {
            var fooCount   = 0;
            var barSum     = 0;
            var testModule = new TestNativeModule(() => fooCount++, x => barSum += x);

            testModule.Initialize();

            Assert.AreEqual(2, testModule.Methods.Count);

            var reactInstance = new MockReactInstance();

            testModule.Methods[nameof(TestNativeModule.Foo)].Invoke(reactInstance, new JArray());
            testModule.Methods[nameof(TestNativeModule.Foo)].Invoke(reactInstance, new JArray());
            Assert.AreEqual(2, fooCount);

            testModule.Methods[nameof(TestNativeModule.Bar)].Invoke(reactInstance, JArray.FromObject(new[] { 42 }));
            testModule.Methods[nameof(TestNativeModule.Bar)].Invoke(reactInstance, JArray.FromObject(new[] { 17 }));
            Assert.AreEqual(59, barSum);
        }
Ejemplo n.º 11
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.º 12
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));
        }
Ejemplo n.º 13
0
        public void InvokesReactInstanceWhenFetchedModuleIsCalled()
        {
            _registry = _registryBuilder
                        .Add(typeof(RCTEventEmitter))
                        .Add(typeof(AppRegistry))
                        .Add(typeof(TestJavaScriptModule))
                        .Build();

            var are      = new AutoResetEvent(false);
            var modules  = new List <string>();
            var methods  = new List <string>();
            var argsList = new List <JArray>();

            var reactInstance = new MockReactInstance((mod, met, args, tracingName) =>
            {
                modules.Add(mod);
                methods.Add(met);
                argsList.Add(args);
                are.Set();
            });

            var module = _registry.GetJavaScriptModule <TestJavaScriptModule>(reactInstance);

            module.Foo(42);

            are.WaitOne();

            Assert.AreEqual(1, modules.Count);
            Assert.AreEqual(1, methods.Count);
            Assert.AreEqual(1, modules.Count);

            Assert.AreEqual("TestJavaScriptModule", modules[0]);
            Assert.AreEqual("Foo", methods[0]);
            Assert.AreEqual(
                JArray.FromObject(new[] { 42 }).ToString(Formatting.None),
                argsList[0].ToString(Formatting.None));
        }
        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_Promises_Resolve()
        {
            var module = new PromiseNativeModule(() => 17);
            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(PromiseNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] { 42, 43 }));
            Assert.AreEqual(42, id);
            Assert.IsTrue(args.SequenceEqual(new[] { 17 }));
        }
        public void NativeModuleBase_Invocation_Promises_IncorrectArgumentCount()
        {
            var module = new PromiseNativeModule(() => null);
            module.Initialize();

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

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

            AssertEx.Throws<NativeArgumentsParseException>(
                () => module.Methods[nameof(PromiseNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] { 42 })),
                ex => Assert.AreEqual("jsArguments", ex.ParamName));
        }
        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_Promises_Reject()
        {
            var expectedMessage = "Foo bar baz";
            var exception = new Exception(expectedMessage);
            var module = new PromiseNativeModule(() => { throw exception; });
            module.Initialize();

            var id = default(int);
            var args = default(JArray);

            var reactInstance = new MockReactInstance((i, a) =>
            {
                id = i;
                args = a;
            });

            module.Methods[nameof(CallbackNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] { 42, 43 }));
            Assert.AreEqual(43, id);
            Assert.AreEqual(1, args.Count);
            var error = args[0] as JObject;
            Assert.IsNotNull(error);
            Assert.AreEqual(4, error.Count);
            var actualMessage = error.Value<string>("message");
            Assert.AreEqual(expectedMessage, actualMessage);
        }
        public void NativeModuleBase_Invocation_Promises_NullCallback()
        {
            var module = new PromiseNativeModule(() => null);
            module.Initialize();

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

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

            module.Methods[nameof(PromiseNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] { 42, 43 }));
            Assert.AreEqual(1, args.Count);
            Assert.IsNull(args[0]);
        }
        public void NativeModuleBase_ReflectionDelegateFactory_Perf()
        {
            var module = new PerfNativeModule(ReflectionReactDelegateFactory.Instance);
            var reactInstance = new MockReactInstance();
            var args = JArray.FromObject(new[] { 42 });

            module.Initialize();

            var n = 100000;
            for (var i = 0; i < n; ++i)
            {
                module.Methods[nameof(PerfNativeModule.Foo)].Invoke(reactInstance, args);
            }
        }
        public void NativeModuleBase_Invocation()
        {
            var fooCount = 0;
            var barSum = 0;
            var testModule = new TestNativeModule(() => fooCount++, x => barSum += x);

            testModule.Initialize();

            Assert.AreEqual(2, testModule.Methods.Count);

            var reactInstance = new MockReactInstance();
            testModule.Methods[nameof(TestNativeModule.Foo)].Invoke(reactInstance, new JArray());
            testModule.Methods[nameof(TestNativeModule.Foo)].Invoke(reactInstance, new JArray());
            Assert.AreEqual(2, fooCount);

            testModule.Methods[nameof(TestNativeModule.Bar)].Invoke(reactInstance, JArray.FromObject(new[] { 42 }));
            testModule.Methods[nameof(TestNativeModule.Bar)].Invoke(reactInstance, JArray.FromObject(new[] { 17 }));
            Assert.AreEqual(59, barSum);
        }
        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));
        }