Skip to content
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Windows.Presentation" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase">
Expand All @@ -136,22 +138,10 @@
<Compile Include="Bridge\Queue\MessageQueueThreadTests.cs" />
<Compile Include="Internal\Constants\DictionaryHelpers.cs" />
<Compile Include="Internal\DispatcherHelpers.cs" />
<Compile Include="Internal\MockInvocationHandler.cs" />
<Compile Include="Internal\MockPromise.cs" />
<Compile Include="Internal\MockReactInstance.cs" />
<Compile Include="Internal\MockViewManager.cs" />
<Compile Include="Modules\NetInfo\NetInfoModuleTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UIManager\AppRegistryTests.cs" />
<Compile Include="UIManager\DependencyObjectExtensionsTests.cs" />
<Compile Include="UIManager\PropertySetterTests.cs" />
<Compile Include="UIManager\ReactStylesDiffMapTests.cs" />
<Compile Include="UIManager\RootViewHelperTests.cs" />
<Compile Include="UIManager\ShadowNodeRegistryTests.cs" />
<Compile Include="UIManager\UIManagerModuleTests.cs" />
<Compile Include="UIManager\ViewAtIndexTests.cs" />
<Compile Include="UIManager\ViewManagerRegistryTests.cs" />
<Compile Include="UIManager\ViewManagersPropertyCacheTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand All @@ -176,8 +166,6 @@
<ItemGroup>
<ChakraCoreDll Include="$(SolutionDir)..\ChakraCore\Build\VcBuild\bin\$(Platform)_$(Configuration)\ChakraCore.*" />
</ItemGroup>
<Copy SourceFiles="@(ChakraCoreDll)"
DestinationFolder="$(OutputPath)"
ContinueOnError="false" />
<Copy SourceFiles="@(ChakraCoreDll)" DestinationFolder="$(OutputPath)" ContinueOnError="false" />
</Target>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using NUnit.Framework;
using Newtonsoft.Json.Linq;
using ReactNative.Bridge;
using System;
Expand All @@ -8,10 +8,10 @@

namespace ReactNative.Tests.Bridge
{
[TestClass]
[TestFixture]
public class NativeModuleBaseTests
{
[TestMethod]
[Test]
public void NativeModuleBase_ReactMethod_ThrowsNotSupported()
{
var actions = new Action[]
Expand All @@ -27,59 +27,59 @@ public void NativeModuleBase_ReactMethod_ThrowsNotSupported()

foreach (var action in actions)
{
AssertEx.Throws<NotSupportedException>(action);
Assert.Throws<NotSupportedException>(() => action.Invoke());
}
}

[TestMethod]
[Test]
public void NativeModuleBase_ReactMethod_Async_ThrowsNotImplemented()
{
AssertEx.Throws<NotImplementedException>(() => new AsyncNotImplementedNativeModule());
Assert.Throws<NotImplementedException>(() => new AsyncNotImplementedNativeModule());
}

[TestMethod]
[Test]
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));
ArgumentNullException ex1 = Assert.Throws<ArgumentNullException>(
() => testModule.Methods[nameof(TestNativeModule.Foo)].Invoke(null, new JArray()));
Assert.AreEqual("reactInstance", ex1.ParamName);
ArgumentNullException ex2 = Assert.Throws<ArgumentNullException>(
() => testModule.Methods[nameof(TestNativeModule.Foo)].Invoke(reactInstance, null));
Assert.AreEqual("jsArguments", ex2.ParamName);
}

[TestMethod]
[Test]
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));
NativeArgumentsParseException ex = Assert.Throws<NativeArgumentsParseException>(
() => testModule.Methods[nameof(TestNativeModule.Bar)].Invoke(reactInstance, new JArray()));
Assert.AreEqual("jsArguments", ex.ParamName);
}

[TestMethod]
[Test]
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));
NativeArgumentsParseException ex = Assert.Throws<NativeArgumentsParseException>(
() => testModule.Methods[nameof(TestNativeModule.Bar)].Invoke(reactInstance, JArray.FromObject(new[] {default(object)})));
Assert.AreEqual("arguments", ex.ParamName);
}

[TestMethod]
[Test]
public void NativeModuleBase_Invocation()
{
var fooCount = 0;
Expand All @@ -100,7 +100,7 @@ public void NativeModuleBase_Invocation()
Assert.AreEqual(59, barSum);
}

[TestMethod]
[Test]
public void NativeModuleBase_Invocation_Callbacks()
{
var callbackArgs = new object[] { 1, 2, 3 };
Expand All @@ -121,7 +121,7 @@ public void NativeModuleBase_Invocation_Callbacks()
Assert.IsTrue(args.Cast<object>().SequenceEqual(callbackArgs));
}

[TestMethod]
[Test]
public void NativeModuleBase_Invocation_Callbacks_InvalidArgumentThrows()
{
var callbackArgs = new object[] { 1, 2, 3 };
Expand All @@ -137,12 +137,12 @@ public void NativeModuleBase_Invocation_Callbacks_InvalidArgumentThrows()
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));
NativeArgumentsParseException ex = Assert.Throws<NativeArgumentsParseException>(
() => module.Methods[nameof(CallbackNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] {default(object)})));
Assert.AreEqual("arguments", ex.ParamName);
}

[TestMethod]
[Test]
public void NativeModuleBase_Invocation_Callbacks_NullCallback()
{
var module = new CallbackNativeModule(null);
Expand All @@ -161,7 +161,7 @@ public void NativeModuleBase_Invocation_Callbacks_NullCallback()
Assert.AreEqual(0, args.Count);
}

[TestMethod]
[Test]
public void NativeModuleBase_Invocation_Promises_Resolve()
{
var module = new PromiseNativeModule(() => 17);
Expand All @@ -181,7 +181,7 @@ public void NativeModuleBase_Invocation_Promises_Resolve()
Assert.IsTrue(args.SequenceEqual(new[] { 17 }));
}

[TestMethod]
[Test]
public void NativeModuleBase_CompiledDelegateFactory_Perf()
{
var module = new PerfNativeModule(CompiledReactDelegateFactory.Instance);
Expand All @@ -197,7 +197,7 @@ public void NativeModuleBase_CompiledDelegateFactory_Perf()
}
}

[TestMethod]
[Test]
public void NativeModuleBase_Invocation_Promises_InvalidArgumentThrows()
{
var module = new PromiseNativeModule(() => 17);
Expand All @@ -212,16 +212,16 @@ public void NativeModuleBase_Invocation_Promises_InvalidArgumentThrows()
args = a.ToObject<List<int>>();
});

AssertEx.Throws<NativeArgumentsParseException>(
() => module.Methods[nameof(PromiseNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] { default(object), 43 })),
ex => Assert.AreEqual("arguments", ex.ParamName));
NativeArgumentsParseException ex1 = Assert.Throws<NativeArgumentsParseException>(
() => module.Methods[nameof(PromiseNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] {default(object), 43})));
Assert.AreEqual("arguments", ex1.ParamName);

AssertEx.Throws<NativeArgumentsParseException>(
() => module.Methods[nameof(PromiseNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] { 42, default(object) })),
ex => Assert.AreEqual("arguments", ex.ParamName));
NativeArgumentsParseException ex2 = Assert.Throws<NativeArgumentsParseException>(
() => module.Methods[nameof(PromiseNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] {42, default(object)})));
Assert.AreEqual("arguments", ex2.ParamName);
}

[TestMethod]
[Test]
public void NativeModuleBase_Invocation_Promises_IncorrectArgumentCount()
{
var module = new PromiseNativeModule(() => null);
Expand All @@ -236,12 +236,12 @@ public void NativeModuleBase_Invocation_Promises_IncorrectArgumentCount()
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));
NativeArgumentsParseException ex = Assert.Throws<NativeArgumentsParseException>(
() => module.Methods[nameof(PromiseNativeModule.Foo)].Invoke(reactInstance, JArray.FromObject(new[] {42})));
Assert.AreEqual("jsArguments", ex.ParamName);
}

[TestMethod]
[Test]
public void NativeModuleBase_Invocation_Promises_Reject()
{
var expectedMessage = "Foo bar baz";
Expand All @@ -268,7 +268,7 @@ public void NativeModuleBase_Invocation_Promises_Reject()
Assert.AreEqual(expectedMessage, actualMessage);
}

[TestMethod]
[Test]
public void NativeModuleBase_Invocation_Promises_NullCallback()
{
var module = new PromiseNativeModule(() => null);
Expand All @@ -288,7 +288,7 @@ public void NativeModuleBase_Invocation_Promises_NullCallback()
Assert.IsNull(args[0]);
}

[TestMethod]
[Test]
public void NativeModuleBase_ReflectionDelegateFactory_Perf()
{
var module = new PerfNativeModule(ReflectionReactDelegateFactory.Instance);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using NUnit.Framework;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using ReactNative.Bridge;
Expand All @@ -8,27 +8,27 @@

namespace ReactNative.Tests.Bridge
{
[TestClass]
[TestFixture]
public class NativeModuleRegistryTests
{
[TestMethod]
[Test]
public void NativeModuleRegistry_ArgumentChecks()
{
var builder = new NativeModuleRegistry.Builder();
AssertEx.Throws<ArgumentNullException>(
() => builder.Add(null),
ex => Assert.AreEqual("module", ex.ParamName));
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(
() => builder.Add(null));
Assert.AreEqual("module", ex.ParamName);
}

[TestMethod]
[Test]
public void NativeModuleRegistry_Override_Disallowed()
{
var builder = new NativeModuleRegistry.Builder();
builder.Add(new OverrideDisallowedModule());
AssertEx.Throws<InvalidOperationException>(() => builder.Add(new OverrideDisallowedModule()));
Assert.Throws<InvalidOperationException>(() => builder.Add(new OverrideDisallowedModule()));
}

[TestMethod]
[Test]
public void NativeModuleRegistry_Override_Allowed()
{
var registry = new NativeModuleRegistry.Builder()
Expand All @@ -39,16 +39,16 @@ public void NativeModuleRegistry_Override_Allowed()
Assert.AreEqual(1, registry.Modules.Count());
}

[TestMethod]
[Test]
public void NativeModuleRegistry_ModuleWithNullName_Throws()
{
var builder = new NativeModuleRegistry.Builder();
AssertEx.Throws<ArgumentException>(
() => builder.Add(new NullNameModule()),
ex => Assert.AreEqual("module", ex.ParamName));
ArgumentException ex = Assert.Throws<ArgumentException>(
() => builder.Add(new NullNameModule()));
Assert.AreEqual("module", ex.ParamName);
}

[TestMethod]
[Test]
public void NativeModuleRegistry_WriteModuleDefinitions()
{
var registry = new NativeModuleRegistry.Builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using NUnit.Framework;
using Newtonsoft.Json.Linq;
using ReactNative.Bridge;
using System;
using System.Threading;

namespace ReactNative.Tests.Bridge
{
[TestClass]
[TestFixture]
public class PromiseTests
{
[TestMethod]
[Test]
public void Promise_Resolve()
{
var args = default(object[]);
Expand All @@ -31,7 +31,7 @@ public void Promise_Resolve()
Assert.AreSame(o, args[0]);
}

[TestMethod]
[Test]
public void Promise_Reject()
{
var args = default(object[]);
Expand All @@ -53,11 +53,11 @@ public void Promise_Reject()

var json = args[0] as JObject;
Assert.IsNotNull(json);
Assert.AreEqual(code, json["code"]);
Assert.AreEqual(message, json["message"]);
Assert.AreEqual(code, json["code"].ToString());
Assert.AreEqual(message, json["message"].ToString());
}

[TestMethod]
[Test]
public void Promise_Reject_UserInfo()
{
var args = default(object[]);
Expand All @@ -83,7 +83,7 @@ public void Promise_Reject_UserInfo()
Assert.IsNotNull(json);
var userInfo = json["userInfo"] as JObject;
Assert.IsNotNull(userInfo);
Assert.AreEqual("baz", userInfo["qux"]);
Assert.AreEqual("baz", userInfo["qux"].ToString());
}
}
}
20 changes: 20 additions & 0 deletions ReactWindows/ReactNative.Shared.Tests/Internal/MockCallback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using ReactNative.Bridge;
using System;

namespace ReactNative.Tests
{
class MockCallback : ICallback
{
private readonly Action<object[]> _action;

public MockCallback(Action<object[]> action)
{
_action = action;
}

public void Invoke(params object[] arguments)
{
_action(arguments);
}
}
}
Loading