public void Can_read_properties_from_js_object() { var testObject = new JsValueTests.JsTestsQml.TestObject(); dynamic result = null; Mock.Setup(x => x.Method(It.IsAny <INetJsValue>())).Callback(new Action <dynamic>(jsValue => { result = jsValue; })); Mock.Setup(x => x.GetTestObject()).Returns(testObject); RunQmlTest( "test", @" var netObject = test.getTestObject() test.method({ test1: 34, test2: 'test3', test3: netObject, test4: { test5: 'test5' } }) "); Mock.Verify(x => x.Method(It.IsAny <INetJsValue>()), Times.Exactly(1)); Mock.Verify(x => x.GetTestObject(), Times.Exactly(1)); ((object)result.nonExistant).Should().BeNull(); ((int)result.test1).Should().Be(34); ((string)result.test2).Should().Be("test3"); ((object)result.test3).Should().BeSameAs(testObject); ((string)result.test4.test5).Should().Be("test5"); }
public void Can_invoke_js_callback_with_net_instance() { var testObject = new JsValueTests.JsTestsQml.TestObject(); Mock.Setup(x => x.Method(It.IsAny <INetJsValue>())) .Callback(new Action <dynamic>(x => { x(testObject); })); NetTestHelper.RunQml(qmlApplicationEngine, @" import QtQuick 2.0 import tests 1.0 JsTestsQml { id: test Component.onCompleted: function() { test.method(function(param1) { param1.testMethod() param1.testMethod() }) } } "); Mock.Verify(x => x.Method(It.IsAny <INetJsValue>()), Times.Once); testObject.CalledCount.Should().Be(2); }
public void Can_set_properties() { var testObject = new JsValueTests.JsTestsQml.TestObject(); dynamic result = null; Mock.Setup(x => x.GetTestObject()).Returns(testObject); Mock.Setup(x => x.Method(It.IsAny <INetJsValue>(), It.IsAny <INetJsValue>())) .Callback(new Action <dynamic, dynamic>((source, destination) => { destination.dest1 = source.source1; destination.dest2 = source.source2; destination.dest3 = source.source3; destination.dest4 = source.source4; })); Mock.Setup(x => x.Method(It.IsAny <INetJsValue>())) .Callback(new Action <dynamic>(value => { result = value; })); NetTestHelper.RunQml(qmlApplicationEngine, @" import QtQuick 2.0 import tests 1.0 JsTestsQml { id: test Component.onCompleted: function() { var netObject = test.getTestObject() var source = { source1: 123, source2: 'value', source3: netObject, source4: { } } var destination = { } test.method(source, destination) test.method(destination) } } "); Mock.Verify(x => x.Method(It.IsAny <INetJsValue>()), Times.Exactly(1)); Mock.Verify(x => x.Method(It.IsAny <INetJsValue>(), It.IsAny <INetJsValue>()), Times.Exactly(1)); Mock.Verify(x => x.GetTestObject(), Times.Exactly(1)); ((object)result).Should().NotBeNull(); ((int)result.dest1).Should().Be(123); ((string)result.dest2).Should().Be("value"); ((object)result.dest3).Should().BeSameAs(testObject); ((object)result.dest4).Should().BeAssignableTo <INetJsValue>(); }
public void Can_invoke_js_callback_with_net_instance() { var testObject = new JsValueTests.JsTestsQml.TestObject(); Mock.Setup(x => x.Method(It.IsAny <INetJsValue>())) .Callback(new Action <dynamic>(x => { x(testObject); })); RunQmlTest( "test", @" test.method(function(param1) { param1.testMethod() param1.testMethod() }) "); Mock.Verify(x => x.Method(It.IsAny <INetJsValue>()), Times.Once); testObject.CalledCount.Should().Be(2); }
public void Can_read_properties_from_js_object() { var testObject = new JsValueTests.JsTestsQml.TestObject(); dynamic result = null; Mock.Setup(x => x.Method(It.IsAny <INetJsValue>())).Callback(new Action <dynamic>(jsValue => { result = jsValue; })); Mock.Setup(x => x.GetTestObject()).Returns(testObject); NetTestHelper.RunQml(qmlApplicationEngine, @" import QtQuick 2.0 import tests 1.0 JsTestsQml { id: test Component.onCompleted: function() { var netObject = test.getTestObject() test.method({ test1: 34, test2: 'test3', test3: netObject, test4: { test5: 'test5' } }) } } "); Mock.Verify(x => x.Method(It.IsAny <INetJsValue>()), Times.Exactly(1)); Mock.Verify(x => x.GetTestObject(), Times.Exactly(1)); ((object)result.nonExistant).Should().BeNull(); ((int)result.test1).Should().Be(34); ((string)result.test2).Should().Be("test3"); ((object)result.test3).Should().BeSameAs(testObject); ((string)result.test4.test5).Should().Be("test5"); }