Esempio n. 1
0
        public static void can_cast_to_simple_generic_interface_method(Test t)
        {
            Func <int, int> target = n => n + 1;
            var             proxy  = Duck.Cast <IAdder <int> >(target);

            t.Assert(3, proxy.AddOne(2));
        }
        public static void can_cast_proxy_to_another_interface_supported_by_wrapped_object(Test t)
        {
            var target = new Combined();
            var proxy  = Duck.Cast <ISimplist>(target);

            Duck.Cast <IAdder>(proxy);
        }
Esempio n. 3
0
        public static void can_call_a_void_method_with_parameter_via_proxy(Test t)
        {
            IWithNumber proxy = Duck.Cast <IWithNumber>(typeof(TargetWithParameter));

            proxy.Execute(2);
            t.Assert(2, TargetWithParameter.Number);
        }
        public static void can_create_proxy_for_interface_that_inherits_other_interfaces(Test t)
        {
            var target = new Combined();
            var proxy  = Duck.Cast <ISimplistWithAdder>(target);

            t.Assert(3, proxy.AddOne(2));
        }
Esempio n. 5
0
        public static void can_call_a_void_method_with_parameter_that_returns_something(Test t)
        {
            Func <int, int> target = n => n + 1;
            var             proxy  = Duck.Cast <IAdder>(target);

            t.Assert(3, proxy.AddOne(2));
        }
        public static void can_call_a_void_method_via_proxy(Test t)
        {
            var       target = new TargetSimplist();
            ISimplist proxy  = Duck.Cast <ISimplist>(target);

            proxy.Execute();
            t.Assert(1, target.calls);
        }
        public static void can_cast_to_simple_generic_interface_with_property(Test t)
        {
            var target = new TargetSimplistProperty();
            var proxy  = Duck.Cast <ISimplistProperty <int> >(target);

            proxy.Value = 2;
            t.Assert(2, target.Value);
        }
        public static void can_cast_to_simple_property(Test t)
        {
            var target = new TargetSimplistProperty();
            var proxy  = Duck.Cast <ISimplistProperty>(target);

            proxy.Value = 2;
            t.Assert(2, target.Value);
        }
Esempio n. 9
0
        public static void can_call_a_void_method_via_proxy(Test t)
        {
            TargetSimplist.calls = 0;
            ISimplist proxy = Duck.Cast <ISimplist>(typeof(TargetSimplist));

            proxy.Execute();
            t.Assert(1, TargetSimplist.calls);
        }
Esempio n. 10
0
        public static void can_call_a_void_method_with_parameter_via_proxy(Test t)
        {
            var         target = new TargetWithParameter();
            IWithNumber proxy  = Duck.Cast <IWithNumber>(target);

            proxy.Execute(2);
            t.Assert(2, target.Number);
        }
Esempio n. 11
0
        public static void can_cast_proxy_to_another_interface_supported_by_wrapped_object(Test t)
        {
            Func <int, int> target = n => n + 1;
            var             proxy  = Duck.Cast <IAdder>(target);
            var             proxy2 = Duck.Cast <IAdder <int> >(proxy); // note: cast the proxy

            t.Assert(3, proxy2.AddOne(2));
        }
Esempio n. 12
0
        public static void can_cast_to_method_with_out_parameter(Test t)
        {
            var target = new TargetWithOutMethod();
            var proxy  = Duck.Cast <IMethodWithOut>(target);
            int val;

            proxy.Execute(out val);
            t.Assert(1, val);
        }
Esempio n. 13
0
        public static void can_call_a_void_method_via_proxy(Test t)
        {
            int       calls  = 0;
            Action    target = () => calls++;
            ISimplist proxy  = Duck.Cast <ISimplist>(target);

            proxy.Execute();
            t.Assert(1, calls);
        }
Esempio n. 14
0
        public static void can_cast_to_method_with_ref_parameter(Test t)
        {
            var target = new TargetWithOutMethod();
            var proxy  = Duck.Cast <IMethodWithRef>(target);
            int val    = 1;

            proxy.AddOne(ref val);
            t.Assert(2, val);
        }
Esempio n. 15
0
        public static void can_call_a_void_method_with_parameter_via_proxy(Test t)
        {
            int          number = 0;
            Action <int> target = n => number = n;
            IWithNumber  proxy  = Duck.Cast <IWithNumber>(target);

            proxy.Execute(2);
            t.Assert(2, number);
        }
Esempio n. 16
0
        public static void can_duck_type_an_event(Test t)
        {
            var          proxy  = Duck.Cast <IEventer>(typeof(TargetEvent));
            EventHandler hander = (sender, args) => { };

            proxy.SimpleEvent += hander;
            t.Assert(1, TargetEvent.count);
            proxy.SimpleEvent -= hander;
            t.Assert(0, TargetEvent.count);
        }
Esempio n. 17
0
 public static void cannot_cast_if_a_target_method_is_missing(Test t)
 {
     t.AssertThrows <InvalidCastException>(() => Duck.Cast <ISimplist>(typeof(TargetBad)));
 }
Esempio n. 18
0
        public static void proxy_inherited_interface_types(Test t)
        {
            var proxy = Duck.Cast <IExistDeleter>(typeof(System.IO.File));

            t.Assert(true, proxy.Exists(@"c:\Windows\notepad.exe"));
        }
Esempio n. 19
0
        public static void can_proxy_system_io_file(Test t)
        {
            var proxy = Duck.Cast <IExister>(typeof(System.IO.File));

            t.Assert(true, proxy.Exists(@"c:\Windows\notepad.exe"));
        }
Esempio n. 20
0
        public static void can_call_a_void_method_with_parameter_that_returns_something(Test t)
        {
            var proxy = Duck.Cast <IAdder>(typeof(Adder));

            t.Assert(3, proxy.AddOne(2));
        }
Esempio n. 21
0
        public static void cannot_cast_if_a_target_method_is_missing(Test t)
        {
            var target = new TargetBad();

            t.AssertThrows <InvalidCastException>(() => Duck.Cast <ISimplist>(target));
        }