コード例 #1
0
ファイル: NetVariantTests.cs プロジェクト: xiaohszx/qmlnet
        public void Can_store_variant_list()
        {
            using (var variant = new NetVariant())
                using (var variantList = new NetVariantList())
                {
                    using (var value1 = NetVariant.From(3))
                    {
                        variantList.Add(value1);
                    }

                    variant.VariantType.Should().Be(NetVariantType.Invalid);
                    variant.NetVariantList = variantList;
                    variant.VariantType.Should().Be(NetVariantType.NetVariantList);

                    using (var resultVariantList = variant.NetVariantList)
                    {
                        resultVariantList.Should().NotBeNull();
                        resultVariantList.Count.Should().Be(variantList.Count);
                        using (var value1 = resultVariantList.Get(0))
                            using (var value2 = variantList.Get(0))
                            {
                                value1.Int.Should().Be(3);
                                value2.Int.Should().Be(3);
                            }
                    }
                }
        }
コード例 #2
0
        public void Can_call_method_with_multiple_parameters()
        {
            _mock.Setup(x => x.MultipleParams(20, 100));

            var del = (Net.Internal.CodeGen.CodeGen.InvokeMethodDelegate)BuildInvokeMethodDelegate(nameof(TestObject.MultipleParams));

            using (var netReference = NetReference.CreateForObject(_mock.Object))
            {
                Task task = null;
                del(netReference, NetVariantList.From(NetVariant.From(20), NetVariant.From <long>(100)), null, ref task);
                _mock.Verify(x => x.MultipleParams(20, 100));
            }
        }
コード例 #3
0
        private void Test <TResult>(Expression <Action <TestObject> > expression, TResult value)
        {
            _mock.Reset();
            _mock.Setup(expression);

            var del = (Net.Internal.CodeGen.CodeGen.InvokeMethodDelegate)BuildInvokeMethodDelegate(((MethodCallExpression)expression.Body).Method.Name);

            using (var netReference = NetReference.CreateForObject(_mock.Object))
            {
                using (var result = new NetVariant())
                {
                    Task task = null;
                    del(netReference, NetVariantList.From(NetVariant.From(value)), result, ref task);
                    _mock.Verify(expression, Times.Once);
                }
            }
        }
コード例 #4
0
        public void Can_use_multiple_parameters_with_return_type()
        {
            _mock.Setup(x => x.MultipleParamsWithReturn(20, 30)).Returns(40);

            var del = (Net.Internal.CodeGen.CodeGen.InvokeMethodDelegate)BuildInvokeMethodDelegate(nameof(TestObject.MultipleParamsWithReturn));

            using (var netReference = NetReference.CreateForObject(_mock.Object))
            {
                using (var result = new NetVariant())
                {
                    Task task = null;
                    del(netReference, NetVariantList.From(NetVariant.From <int>(20), NetVariant.From <long>(30)), result, ref task);
                    _mock.Verify(x => x.MultipleParamsWithReturn(20, 30), Times.Once);
                    result.VariantType.Should().Be(NetVariantType.Int);
                    result.Int.Should().Be(40);
                }
            }
        }