public async Task ReactInstance_Initialize_Dispose() { var module = new TestNativeModule(); var registry = new NativeModuleRegistry.Builder() .Add(module) .Build(); var jsRegistry = new JavaScriptModuleRegistry.Builder().Build(); var executor = new MockJavaScriptExecutor { OnCallFunctionReturnFlushedQueue = (_, __, ___) => JValue.CreateNull(), OnFlushQueue = () => JValue.CreateNull(), OnInvokeCallbackAndReturnFlushedQueue = (_, __) => JValue.CreateNull() }; var builder = new ReactInstance.Builder() { QueueConfigurationSpec = ReactQueueConfigurationSpec.Default, Registry = registry, JavaScriptModuleRegistry = jsRegistry, JavaScriptExecutorFactory = () => executor, BundleLoader = JavaScriptBundleLoader.CreateFileLoader("ms-appx:///Resources/test.js"), NativeModuleCallExceptionHandler = _ => { }, }; var instance = await DispatcherHelpers.CallOnDispatcherAsync(() => builder.Build()); await DispatcherHelpers.RunOnDispatcherAsync(() => instance.Initialize()); var caught = false; await DispatcherHelpers.RunOnDispatcherAsync(() => { try { instance.Initialize(); } catch (InvalidOperationException) { caught = true; } }); Assert.IsTrue(caught); Assert.AreEqual(1, module.InitializeCalls); await DispatcherHelpers.CallOnDispatcherAsync(instance.DisposeAsync); Assert.AreEqual(1, module.OnReactInstanceDisposeCalls); // Dispose is idempotent await DispatcherHelpers.CallOnDispatcherAsync(instance.DisposeAsync); Assert.AreEqual(1, module.OnReactInstanceDisposeCalls); Assert.IsTrue(instance.IsDisposed); }
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_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("jsArguments", ex.ParamName)); }
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_ArgumentInvalidCount() { var testModule = new TestNativeModule(); testModule.Initialize(); var nopCallback = new InvokeCallback((_, __) => { }); AssertEx.Throws <NativeArgumentsParseException>( () => testModule.Methods[nameof(TestNativeModule.Bar)].Invoke(nopCallback, new JArray()), ex => Assert.AreEqual("jsArguments", ex.ParamName)); }
public async Task ReactInstance_Initialize_Dispose() { var module = new TestNativeModule(); var registry = new NativeModuleRegistry.Builder() .Add(module) .Build(); var jsRegistry = new JavaScriptModuleRegistry.Builder().Build(); var executor = new MockJavaScriptExecutor((p0, p1, p2) => JValue.CreateNull()); var builder = new ReactInstance.Builder() { QueueConfigurationSpec = ReactQueueConfigurationSpec.Default, Registry = registry, JavaScriptModuleRegistry = jsRegistry, JavaScriptExecutorFactory = () => executor, BundleLoader = JavaScriptBundleLoader.CreateFileLoader("ms-appx:///Resources/test.js"), NativeModuleCallExceptionHandler = _ => { }, }; var instance = await DispatcherHelpers.CallOnDispatcherAsync(() => builder.Build()); await DispatcherHelpers.RunOnDispatcherAsync(() => instance.Initialize()); var caught = false; await DispatcherHelpers.RunOnDispatcherAsync(() => { try { instance.Initialize(); } catch (InvalidOperationException) { caught = true; } }); Assert.IsTrue(caught); Assert.AreEqual(1, module.InitializeCalls); await DispatcherHelpers.RunOnDispatcherAsync(() => instance.Dispose()); Assert.AreEqual(1, module.OnReactInstanceDisposeCalls); // Dispose is idempotent await DispatcherHelpers.RunOnDispatcherAsync(() => instance.Dispose()); Assert.AreEqual(1, module.OnReactInstanceDisposeCalls); Assert.IsTrue(instance.IsDisposed); }
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_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_Invocation_ArgumentNull() { var testModule = new TestNativeModule(); testModule.Initialize(); var nopCallback = new InvokeCallback((_, __) => { }); AssertEx.Throws <ArgumentNullException>( () => testModule.Methods[nameof(TestNativeModule.Foo)].Invoke(null, new JArray()), ex => Assert.AreEqual("invokeCallback", ex.ParamName)); AssertEx.Throws <ArgumentNullException>( () => testModule.Methods[nameof(TestNativeModule.Foo)].Invoke(nopCallback, null), ex => Assert.AreEqual("jsArguments", ex.ParamName)); }
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() { var fooCount = 0; var barSum = 0; var testModule = new TestNativeModule(() => fooCount++, x => barSum += x); testModule.Initialize(); Assert.AreEqual(2, testModule.Methods.Count); var nopCallback = new InvokeCallback((_, __) => { }); testModule.Methods[nameof(TestNativeModule.Foo)].Invoke(nopCallback, new JArray()); testModule.Methods[nameof(TestNativeModule.Foo)].Invoke(nopCallback, new JArray()); Assert.AreEqual(2, fooCount); testModule.Methods[nameof(TestNativeModule.Bar)].Invoke(nopCallback, JArray.FromObject(new[] { 42 })); testModule.Methods[nameof(TestNativeModule.Bar)].Invoke(nopCallback, JArray.FromObject(new[] { 17 })); Assert.AreEqual(59, barSum); }
public async Task ReactInstance_GetModules() { var module = new TestNativeModule(); var registry = new NativeModuleRegistry.Builder() .Add(module) .Build(); var jsRegistry = new JavaScriptModuleRegistry.Builder() .Add <TestJavaScriptModule>() .Build(); var executor = new MockJavaScriptExecutor { OnCallFunctionReturnFlushedQueue = (_, __, ___) => JValue.CreateNull(), OnFlushQueue = () => JValue.CreateNull(), OnInvokeCallbackAndReturnFlushedQueue = (_, __) => JValue.CreateNull() }; var builder = new ReactInstance.Builder() { QueueConfigurationSpec = ReactQueueConfigurationSpec.Default, Registry = registry, JavaScriptModuleRegistry = jsRegistry, JavaScriptExecutorFactory = () => executor, BundleLoader = JavaScriptBundleLoader.CreateFileLoader("ms-appx:///Resources/test.js"), NativeModuleCallExceptionHandler = _ => { } }; var instance = await DispatcherHelpers.CallOnDispatcherAsync(() => builder.Build()); var actualModule = instance.GetNativeModule <TestNativeModule>(); Assert.AreSame(module, actualModule); var firstJSModule = instance.GetJavaScriptModule <TestJavaScriptModule>(); var secondJSModule = instance.GetJavaScriptModule <TestJavaScriptModule>(); Assert.AreSame(firstJSModule, secondJSModule); await DispatcherHelpers.CallOnDispatcherAsync(instance.DisposeAsync); }
public async Task ReactInstance_GetModules() { var module = new TestNativeModule(); var registry = new NativeModuleRegistry.Builder() .Add(module) .Build(); var jsRegistry = new JavaScriptModuleRegistry.Builder() .Add<TestJavaScriptModule>() .Build(); var executor = new MockJavaScriptExecutor { OnCallFunctionReturnFlushedQueue = (_, __, ___) => JValue.CreateNull(), OnFlushQueue = () => JValue.CreateNull(), OnInvokeCallbackAndReturnFlushedQueue = (_, __) => JValue.CreateNull() }; var builder = new ReactInstance.Builder() { QueueConfigurationSpec = ReactQueueConfigurationSpec.Default, Registry = registry, JavaScriptModuleRegistry = jsRegistry, JavaScriptExecutorFactory = () => executor, BundleLoader = JavaScriptBundleLoader.CreateFileLoader("ms-appx:///Resources/test.js"), NativeModuleCallExceptionHandler = _ => { } }; var instance = await DispatcherHelpers.CallOnDispatcherAsync(() => builder.Build()); var actualModule = instance.GetNativeModule<TestNativeModule>(); Assert.AreSame(module, actualModule); var firstJSModule = instance.GetJavaScriptModule<TestJavaScriptModule>(); var secondJSModule = instance.GetJavaScriptModule<TestJavaScriptModule>(); Assert.AreSame(firstJSModule, secondJSModule); await DispatcherHelpers.CallOnDispatcherAsync(instance.DisposeAsync); }
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); }