Beispiel #1
0
        public void InvokesReactInstanceWhenFetchedModuleIsCalled()
        {
            _registry = _registryBuilder
                        .Add(typeof(RCTEventEmitter))
                        .Add(typeof(AppRegistry))
                        .Add(typeof(TestJavaScriptModule))
                        .Build();

            var are = new AutoResetEvent(false);

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

            _mockReactInstance.Expects.One.Method(
                _ => _.InvokeFunction(null, null, null, null))
            .With(
                nameof(TestJavaScriptModule),
                nameof(TestJavaScriptModule.Foo),
                JArray.FromObject(new[] { 42 }),
                NMock.Is.StringContaining("_"))
            .Will(Invoke.Action(() => are.Set()));

            module.Foo(42);

            are.WaitOne();
        }
Beispiel #2
0
 public void ThrowsWhenUnknownModuleRequested()
 {
     _registry = _registryBuilder.Build();
     Assert.That(
         () => _registry.GetJavaScriptModule <TestJavaScriptModule>(_mockReactInstance.MockObject),
         Throws.InvalidOperationException);
 }
        public void InvokesReactInstanceWhenFetchedModuleIsCalled()
        {
            var registry = new JavaScriptModuleRegistry();

            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));
        }