Ejemplo n.º 1
0
        public void SerializesDotNetObjectWrappersInKnownFormat()
        {
            // Arrange
            var runtime = new TestJSInProcessRuntime {
                NextResultJson = null
            };
            var obj1 = new object();
            var obj2 = new object();
            var obj3 = new object();

            // Act
            // Showing we can pass the DotNetObject either as top-level args or nested
            var syncResult = runtime.Invoke <object>("test identifier",
                                                     new DotNetObjectRef(obj1),
                                                     new Dictionary <string, object>
            {
                { "obj2", new DotNetObjectRef(obj2) },
                { "obj3", new DotNetObjectRef(obj3) }
            });

            // Assert: Handles null result string
            Assert.Null(syncResult);

            // Assert: Serialized as expected
            var call = runtime.InvokeCalls.Single();

            Assert.Equal("test identifier", call.Identifier);
            Assert.Equal("[\"__dotNetObject:1\",{\"obj2\":\"__dotNetObject:2\",\"obj3\":\"__dotNetObject:3\"}]", call.ArgsJson);

            // Assert: Objects were tracked
            Assert.Same(obj1, runtime.ArgSerializerStrategy.FindDotNetObject(1));
            Assert.Same(obj2, runtime.ArgSerializerStrategy.FindDotNetObject(2));
            Assert.Same(obj3, runtime.ArgSerializerStrategy.FindDotNetObject(3));
        }
Ejemplo n.º 2
0
    public void SerializesDotNetObjectWrappersInKnownFormat()
    {
        // Arrange
        var runtime = new TestJSInProcessRuntime {
            NextResultJson = null
        };
        var obj1 = new object();
        var obj2 = new object();
        var obj3 = new object();

        // Act
        // Showing we can pass the DotNetObject either as top-level args or nested
        var syncResult = runtime.Invoke <DotNetObjectReference <object> >("test identifier",
                                                                          DotNetObjectReference.Create(obj1),
                                                                          new Dictionary <string, object>
        {
            { "obj2", DotNetObjectReference.Create(obj2) },
            { "obj3", DotNetObjectReference.Create(obj3) },
        });

        // Assert: Handles null result string
        Assert.Null(syncResult);

        // Assert: Serialized as expected
        var call = runtime.InvokeCalls.Single();

        Assert.Equal("test identifier", call.Identifier);
        Assert.Equal("[{\"__dotNetObject\":1},{\"obj2\":{\"__dotNetObject\":2},\"obj3\":{\"__dotNetObject\":3}}]", call.ArgsJson);

        // Assert: Objects were tracked
        Assert.Same(obj1, runtime.GetObjectReference(1).Value);
        Assert.Same(obj2, runtime.GetObjectReference(2).Value);
        Assert.Same(obj3, runtime.GetObjectReference(3).Value);
    }
Ejemplo n.º 3
0
    public void JSInProcessObjectReference_Dispose_DisallowsFurtherInteropCalls()
    {
        // Arrange
        var jsRuntime = new TestJSInProcessRuntime();
        var jsObject  = new JSInProcessObjectReference(jsRuntime, 0);

        // Act
        _ = jsObject.DisposeAsync();

        // Assert
        Assert.Throws <ObjectDisposedException>(() => jsObject.Invoke <object>("test", "arg1", "arg2"));
    }
Ejemplo n.º 4
0
    public void JSInProcessObjectReference_Invoke_CallsUnderlyingJSRuntimeInvoke()
    {
        // Arrange
        var jsRuntime = new TestJSInProcessRuntime();
        var jsObject  = new JSInProcessObjectReference(jsRuntime, 0);

        // Act
        jsObject.Invoke <object>("test", "arg1", "arg2");

        // Assert
        Assert.Equal(1, jsRuntime.InvokeJSInvocationCount);
    }
Ejemplo n.º 5
0
    public void DispatchesSyncCallsAndDeserializesResults()
    {
        // Arrange
        var runtime = new TestJSInProcessRuntime
        {
            NextResultJson = "{\"intValue\":123,\"stringValue\":\"Hello\"}"
        };

        // Act
        var syncResult = runtime.Invoke <TestDTO>("test identifier 1", "arg1", 123, true) !;
        var call       = runtime.InvokeCalls.Single();

        // Assert
        Assert.Equal(123, syncResult.IntValue);
        Assert.Equal("Hello", syncResult.StringValue);
        Assert.Equal("test identifier 1", call.Identifier);
        Assert.Equal("[\"arg1\",123,true]", call.ArgsJson);
    }
Ejemplo n.º 6
0
        public void SyncCallResultCanIncludeDotNetObjects()
        {
            // Arrange
            var runtime = new TestJSInProcessRuntime
            {
                NextResultJson = "[\"__dotNetObject:2\",\"__dotNetObject:1\"]"
            };
            var obj1 = new object();
            var obj2 = new object();

            // Act
            var syncResult = runtime.Invoke <object[]>("test identifier",
                                                       new DotNetObjectRef(obj1),
                                                       "some other arg",
                                                       new DotNetObjectRef(obj2));
            var call = runtime.InvokeCalls.Single();

            // Assert
            Assert.Equal(new[] { obj2, obj1 }, syncResult);
        }
Ejemplo n.º 7
0
    public void SyncCallResultCanIncludeDotNetObjects()
    {
        // Arrange
        var runtime = new TestJSInProcessRuntime
        {
            NextResultJson = "[{\"__dotNetObject\":2},{\"__dotNetObject\":1}]"
        };
        var obj1 = new object();
        var obj2 = new object();

        // Act
        var syncResult = runtime.Invoke <DotNetObjectReference <object>[]>(
            "test identifier",
            DotNetObjectReference.Create(obj1),
            "some other arg",
            DotNetObjectReference.Create(obj2)) !;
        var call = runtime.InvokeCalls.Single();

        // Assert
        Assert.Equal(new[] { obj2, obj1 }, syncResult.Select(r => r.Value));
    }