diff --git a/ReactNative.Tests/Bridge/NativeModuleRegistryTests.cs b/ReactNative.Tests/Bridge/NativeModuleRegistryTests.cs
index 8507add9ce..be0b4a43da 100644
--- a/ReactNative.Tests/Bridge/NativeModuleRegistryTests.cs
+++ b/ReactNative.Tests/Bridge/NativeModuleRegistryTests.cs
@@ -1,7 +1,10 @@
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
using ReactNative.Bridge;
using System;
-using System.Collections.Generic;
+using System.IO;
+using System.Linq;
namespace ReactNative.Tests.Bridge
{
@@ -28,9 +31,12 @@ namespace ReactNative.Tests.Bridge
[TestMethod]
public void NativeModuleRegistry_Override_Allowed()
{
- var builder = new NativeModuleRegistry.Builder();
- builder.Add(new OverrideAllowedModule());
- builder.Add(new OverrideAllowedModule());
+ var registry = new NativeModuleRegistry.Builder()
+ .Add(new OverrideAllowedModule())
+ .Add(new OverrideAllowedModule())
+ .Build();
+
+ Assert.AreEqual(1, registry.Modules.Count());
}
[TestMethod]
@@ -42,6 +48,47 @@ namespace ReactNative.Tests.Bridge
ex => Assert.AreEqual("module", ex.ParamName));
}
+ [TestMethod]
+ 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");
+ }
+ }
+
class OverrideDisallowedModule : NativeModuleBase
{
public override string Name
@@ -82,5 +129,22 @@ namespace ReactNative.Tests.Bridge
}
}
}
+
+ class TestNativeModule : NativeModuleBase
+ {
+ public override string Name
+ {
+ get
+ {
+ return "Test";
+ }
+ }
+
+ [ReactMethod]
+ public void Foo(int x) { }
+
+ [ReactMethod]
+ public void Bar(string x) { }
+ }
}
}
diff --git a/ReactNative/Bridge/CatalystInstance.cs b/ReactNative/Bridge/CatalystInstance.cs
index b0938f288d..dd1770fc79 100644
--- a/ReactNative/Bridge/CatalystInstance.cs
+++ b/ReactNative/Bridge/CatalystInstance.cs
@@ -87,7 +87,7 @@ namespace ReactNative.Bridge
});
}
- public void InvokeFunction(int moduleId, int methodId, JArray arguments, string tracingName)
+ public /* TODO: internal? */ void InvokeFunction(int moduleId, int methodId, JArray arguments, string tracingName)
{
_catalystQueueConfiguration.JSQueueThread.RunOnQueue(() =>
{
diff --git a/ReactNative/Bridge/NativeModuleRegistry.cs b/ReactNative/Bridge/NativeModuleRegistry.cs
index 4d0550ae13..9da026fe0e 100644
--- a/ReactNative/Bridge/NativeModuleRegistry.cs
+++ b/ReactNative/Bridge/NativeModuleRegistry.cs
@@ -56,6 +56,24 @@ namespace ReactNative.Bridge
throw new InvalidOperationException("No module instance for type '{0}'.");
}
+ ///
+ /// Write the module descriptions to the given .
+ ///
+ /// The JSON writer.
+ public /* TODO: internal? */ void WriteModuleDescriptions(JsonWriter writer)
+ {
+ using (Tracer.Trace(Tracer.TRACE_TAG_REACT_BRIDGE, "CreateJSON"))
+ {
+ writer.WriteStartObject();
+ foreach (var moduleDef in _moduleTable)
+ {
+ writer.WritePropertyName(moduleDef.Name);
+ moduleDef.WriteModuleDescription(writer);
+ }
+ writer.WriteEndObject();
+ }
+ }
+
///
/// Invoke a method on a native module.
///
@@ -109,24 +127,6 @@ namespace ReactNative.Bridge
}
}
- ///
- /// Write the module descriptions to the given .
- ///
- /// The JSON writer.
- internal /* TODO: public? */ void WriteModuleDescriptions(JsonWriter writer)
- {
- using (Tracer.Trace(Tracer.TRACE_TAG_REACT_BRIDGE, "CreateJSON"))
- {
- writer.WriteStartObject();
- foreach (var moduleDef in _moduleTable)
- {
- writer.WritePropertyName(moduleDef.Name);
- moduleDef.WriteModuleDescription(writer);
- }
- writer.WriteEndObject();
- }
- }
-
class ModuleDefinition
{
private readonly int _id;