Beispiel #1
0
        public void can_create_proxy_for_interface_that_inherits_other_interfaces()
        {
            var target = new Combined();
            var proxy  = Duck.Cast <ISimplistWithAdder>(target);

            Assert.AreEqual(3, proxy.AddOne(2));
        }
Beispiel #2
0
        public void can_call_a_void_method_with_parameter_via_proxy()
        {
            IWithNumber proxy = Duck.Cast <IWithNumber>(typeof(TargetWithParameter));

            proxy.Execute(2);
            Assert.AreEqual(2, TargetWithParameter.Number);
        }
Beispiel #3
0
        public void can_call_a_void_method_with_parameter_that_returns_something()
        {
            Func <int, int> target = n => n + 1;
            var             proxy  = Duck.Cast <IAdder>(target);

            Assert.AreEqual(3, proxy.AddOne(2));
        }
Beispiel #4
0
        public void can_cast_proxy_to_another_interface_supported_by_wrapped_object()
        {
            var target = new Combined();
            var proxy  = Duck.Cast <ISimplist>(target);

            Duck.Cast <IAdder>(proxy);
        }
Beispiel #5
0
        public void can_cast_to_simple_generic_interface_method()
        {
            Func <int, int> target = n => n + 1;
            var             proxy  = Duck.Cast <IAdder <int> >(target);

            Assert.AreEqual(3, proxy.AddOne(2));
        }
Beispiel #6
0
        /// <summary>
        /// Saves a Transaction object with transport to the smartcontract.
        /// </summary>
        private void SaveTransactionWithTransport(Transaction transaction)
        {
            var function = Duck.Cast <IFunction>(Contract.GetFunction("addTransactionWithTransport"));

            var task = function.SendTransactionAsync(
                System.Configuration.ConfigurationManager.AppSettings["accountAddress"],
                new HexBigInteger(4712388),
                new HexBigInteger(0),
                transaction.BatchId,
                transaction.TransactionId,
                transaction.Quantity,
                Convert.ToInt32(transaction.ItemPrice * 100.00),
                DateTimeUtil.ConvertToTimestamp(transaction.OrderTime),
                transaction.From,
                transaction.To,
                transaction.Transport.Transporter,
                DateTimeUtil.ConvertToTimestamp(transaction.Transport.PickupDate),
                DateTimeUtil.ConvertToTimestamp(transaction.Transport.DeliverDate));

            task.ContinueWith(response =>
            {
                _logger.Log(response.Result);

                return(response.Result);
            });

            task.Wait();
        }
Beispiel #7
0
        public void MethodExistsOnSubjectWithTwoMethods()
        {
            var duck = Duck.Cast <IDuckSampleTwoMethods>(new DuckSample());

            Assert.That(duck.MethodExists <IDuckSampleTwoMethods>(a => a.Action()), Is.True);
            Assert.That(duck.MethodExists <IDuckSampleTwoMethods>(a => a.AnotherAction()), Is.False);
        }
Beispiel #8
0
        /// <inheritdoc />
        public void ExecuteTransportUpdate(TransportUpdate update)
        {
            var function = Duck.Cast <IFunction>(Contract.GetFunction("updateTransport"));

            var transporter = update.Transport.Transporter ?? "";
            var pickupDate  = DateTimeUtil.ConvertToTimestamp(update.Transport.PickupDate);
            var deliverDate = DateTimeUtil.ConvertToTimestamp(update.Transport.DeliverDate);

            var task = function.SendTransactionAsync(
                System.Configuration.ConfigurationManager.AppSettings["accountAddress"],
                new HexBigInteger(4712388),
                new HexBigInteger(0),
                update.TransactionId,
                transporter,
                pickupDate,
                deliverDate);

            task.ContinueWith(response =>
            {
                _logger.Log("Update executed: " + response.Result);
                return(response);
            });

            task.Wait();
        }
Beispiel #9
0
        public void can_call_a_void_method_via_proxy()
        {
            TargetSimplist.calls = 0;
            ISimplist proxy = Duck.Cast <ISimplist>(typeof(TargetSimplist));

            proxy.Execute();
            Assert.AreEqual(1, TargetSimplist.calls);
        }
        public void WorksWithAnonymousTypes()
        {
            var test = Duck.Cast <ITest>(
                new { Value = 1d });

            Assert.That(test, Is.Not.Null);
            Assert.That(test.Value, Is.EqualTo(1d));
        }
Beispiel #11
0
        public void MultiArgDuckWithConversionsSucceeds()
        {
            var o    = new MultiArgRetValSample();
            var duck = Duck.Cast <IMultiArgRetValSample>(o);

            Assert.That(duck, Is.Not.Null);
            Assert.That(duck.Append("A", 1), Is.EqualTo("A1"));
        }
Beispiel #12
0
        public void can_call_a_void_method_with_parameter_via_proxy()
        {
            var         target = new TargetWithParameter();
            IWithNumber proxy  = Duck.Cast <IWithNumber>(target);

            proxy.Execute(2);
            Assert.AreEqual(2, target.Number);
        }
Beispiel #13
0
        public void can_call_a_void_method_via_proxy()
        {
            var       target = new TargetSimplist();
            ISimplist proxy  = Duck.Cast <ISimplist>(target);

            proxy.Execute();
            Assert.AreEqual(1, target.calls);
        }
Beispiel #14
0
        public void can_cast_proxy_to_another_interface_supported_by_wrapped_object()
        {
            Func <int, int> target = n => n + 1;
            var             proxy  = Duck.Cast <IAdder>(target);
            var             proxy2 = Duck.Cast <IAdder <int> >(proxy); // note: cast the proxy

            Assert.AreEqual(3, proxy2.AddOne(2));
        }
Beispiel #15
0
        public void can_cast_to_simple_generic_interface_with_property()
        {
            var target = new TargetSimplistProperty();
            var proxy  = Duck.Cast <ISimplistProperty <int> >(target);

            proxy.Value = 2;
            Assert.AreEqual(2, target.Value);
        }
Beispiel #16
0
        public void can_cast_to_simple_property()
        {
            var target = new TargetSimplistProperty();
            var proxy  = Duck.Cast <ISimplistProperty>(target);

            proxy.Value = 2;
            Assert.AreEqual(2, target.Value);
        }
Beispiel #17
0
        public void can_call_a_void_method_with_parameter_via_proxy()
        {
            int          number = 0;
            Action <int> target = n => number = n;
            IWithNumber  proxy  = Duck.Cast <IWithNumber>(target);

            proxy.Execute(2);
            Assert.AreEqual(2, number);
        }
Beispiel #18
0
        public void can_call_a_void_method_via_proxy()
        {
            int       calls  = 0;
            Action    target = () => calls++;
            ISimplist proxy  = Duck.Cast <ISimplist>(target);

            proxy.Execute();
            Assert.AreEqual(1, calls);
        }
Beispiel #19
0
        public void can_cast_to_method_with_out_parameter()
        {
            var target = new TargetWithOutMethod();
            var proxy  = Duck.Cast <IMethodWithOut>(target);
            int val;

            proxy.Execute(out val);
            Assert.AreEqual(1, val);
        }
Beispiel #20
0
        public void can_cast_to_method_with_ref_parameter()
        {
            var target = new TargetWithOutMethod();
            var proxy  = Duck.Cast <IMethodWithRef>(target);
            int val    = 1;

            proxy.AddOne(ref val);
            Assert.AreEqual(2, val);
        }
Beispiel #21
0
        public void can_duck_type_an_event()
        {
            var          proxy  = Duck.Cast <IEventer>(typeof(TargetEvent));
            EventHandler hander = (sender, args) => { };

            proxy.SimpleEvent += hander;
            Assert.AreEqual(1, TargetEvent.count);
            proxy.SimpleEvent -= hander;
            Assert.AreEqual(0, TargetEvent.count);
        }
Beispiel #22
0
        public EthereumTransactionDao(ILogger logger)
        {
            _logger = logger;

            var webNode = new Web3(System.Configuration.ConfigurationManager.AppSettings["ethUrl"])
            {
                TransactionManager = { DefaultGasPrice = 0 }
            };

            Contract = Duck.Cast <IContract>(webNode.Eth.GetContract(AbiHelper.GetTransactionManagerAbi(), System.Configuration.ConfigurationManager.AppSettings["contractAddress"]));
        }
Beispiel #23
0
        public void DuckWithMatchingRefParamsSucceeds()
        {
            var o    = new SampleWithRef();
            var duck = Duck.Cast <ISampleWithRef>(o);

            Assert.That(duck, Is.Not.Null);
            int value = 41;

            duck.ChangeAnswer(ref value);
            Assert.That(value, Is.EqualTo(42));
        }
Beispiel #24
0
        public static int DuckCast(SampleClass[] testObjects)
        {
            int sum = 0;

            for (int i = 0; i < _testSize; ++i)
            {
                var result = Duck.Cast <IGetAnswer>(testObjects[i]);
                sum += result.GetAnswer();
            }
            return(sum);
        }
Beispiel #25
0
        public void DuckWithConvOutParamsSucceeds()
        {
            var o    = new SampleWithOut();
            var duck = Duck.Cast <ISampleWithConvOut>(o);

            Assert.That(duck, Is.Not.Null);
            long value;

            duck.GetAnswer(out value);
            Assert.That(value, Is.EqualTo(42));
        }
Beispiel #26
0
        public void DuckWithConvOutParamsAndRetValSucceeds()
        {
            var o    = new SampleWithConvOutAndRetVal();
            var duck = Duck.Cast <ISampleWithConvOutAndRetVal>(o);

            Assert.That(duck, Is.Not.Null);
            long value;
            long retVal = duck.GetAnswer(out value);

            Assert.That(value, Is.EqualTo(42));
            Assert.That(retVal, Is.EqualTo(33));
        }
        public void ObjectInitializerCompatible()
        {
            var    sample = new CompatibleSample <int>();
            object result = Duck.Cast <IAdd <int> >(sample);

            var sampleEnumerable    = result as IEnumerable;
            var sampleEnumerableInt = result as IEnumerable <int>;
            var sampleAdd           = result as IAdd <int>;

            Assert.That(sampleEnumerable, Is.Not.Null);
            Assert.That(sampleEnumerableInt, Is.Not.Null);
            Assert.That(sampleAdd, Is.Not.Null);
        }
Beispiel #28
0
        public void cannot_cast_if_a_target_method_is_missing()
        {
            var target = new TargetBad();

            Assert.Throws <InvalidCastException>(() => Duck.Cast <ISimplist>(target));
        }
        public void MissingMethodExceptionIsThrown()
        {
            var duck = Duck.Cast <ISample>(new object());

            Assert.Throws <MissingMethodException>(() => duck.Action());
        }
Beispiel #30
0
 void IXmlSerializable.ReadXml(XmlReader reader)
 {
     Value = Duck.Cast <IParser <TKey> >(typeof(TKey)).Parse(reader.ReadElementContentAsString());
 }