コード例 #1
0
        public void NativeModuleRegistry_WriteModuleDefinitions()
        {
            var registry = new NativeModuleRegistry.Builder()
                .Add(new TestNativeModule())
                .Build();

            using (var stringWriter = new StringWriter())
            {
                using (var writer = new JsonTextWriter(stringWriter))
                {
                    registry.WriteModuleDescriptions(writer);
                }

                var json = JArray.Parse(stringWriter.ToString());
                Assert.AreEqual(1, json.Count);

                var module = json[0] as JArray;
                Assert.IsNotNull(module);
                Assert.IsTrue(module.Count >= 3);

                var moduleName = module[0];
                Assert.AreEqual("Test", moduleName.ToString());

                var methods = json[0][2] as JArray;
                Assert.IsNotNull(methods);

                var methodNames = methods.ToObject<string[]>();
                Assert.IsTrue(methodNames.Contains("Foo"));
                Assert.IsTrue(methodNames.Contains("Bar"));
            }
        }
コード例 #2
0
        public void NativeModuleRegistry_WriteModuleDefinitions()
        {
            var registry = new NativeModuleRegistry.Builder(new ReactContext())
                           .Add(new TestNativeModule())
                           .Build();

            using (var stringWriter = new StringWriter())
            {
                using (var writer = new JsonTextWriter(stringWriter))
                {
                    registry.WriteModuleDescriptions(writer);
                }

                var json = JArray.Parse(stringWriter.ToString());
                Assert.AreEqual(1, json.Count);

                var module = json[0] as JArray;
                Assert.IsNotNull(module);
                Assert.IsTrue(module.Count >= 3);

                var moduleName = module[0];
                Assert.AreEqual("Test", moduleName.ToString());

                var methods = json[0][2] as JArray;
                Assert.IsNotNull(methods);

                var methodNames = methods.ToObject <string[]>();
                Assert.IsTrue(methodNames.Contains("Foo"));
                Assert.IsTrue(methodNames.Contains("Bar"));
            }
        }
コード例 #3
0
        public void NativeModuleRegistry_WriteModuleDefinitions()
        {
            var registry = new NativeModuleRegistry.Builder()
                           .Add(new TestNativeModule())
                           .Build();

            using (var stringWriter = new StringWriter())
            {
                using (var writer = new JsonTextWriter(stringWriter))
                {
                    registry.WriteModuleDescriptions(writer);
                }

                var actual = JObject.Parse(stringWriter.ToString());
                Assert.AreEqual(1, actual.Properties().Count());

                var moduleDef = actual.GetValue("Test") as JObject;
                Assert.IsNotNull(moduleDef);

                var moduleId = moduleDef.GetValue("moduleID");
                Assert.IsNotNull(moduleId);
                Assert.AreEqual("0", moduleId.ToString());

                var methods = moduleDef.GetValue("methods") as JObject;
                Assert.IsNotNull(methods);

                var fooMethod = methods.GetValue("Foo") as JObject;
                Assert.IsNotNull(fooMethod);

                var barMethod = methods.GetValue("Bar") as JObject;
                Assert.IsNotNull(barMethod);

                var fooMethodId = fooMethod.GetValue("methodID");
                var barMethodId = barMethod.GetValue("methodID");
                Assert.AreNotEqual(fooMethodId.ToString(), barMethodId.ToString());
                Assert.IsTrue(fooMethodId.ToString() == "0" || fooMethodId.ToString() == "1");
                Assert.IsTrue(barMethodId.ToString() == "0" || barMethodId.ToString() == "1");
            }
        }