コード例 #1
0
ファイル: DelegateTests.cs プロジェクト: MeatDuckXp/Goodies-1
        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));
        }
コード例 #2
0
        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);
        }
コード例 #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);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
ファイル: DelegateTests.cs プロジェクト: MeatDuckXp/Goodies-1
        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));
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #11
0
ファイル: DelegateTests.cs プロジェクト: MeatDuckXp/Goodies-1
        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));
        }
コード例 #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);
        }
コード例 #13
0
ファイル: DelegateTests.cs プロジェクト: MeatDuckXp/Goodies-1
        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);
        }
コード例 #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);
        }
コード例 #15
0
ファイル: DelegateTests.cs プロジェクト: MeatDuckXp/Goodies-1
        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);
        }
コード例 #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);
        }
コード例 #17
0
 public static void cannot_cast_if_a_target_method_is_missing(Test t)
 {
     t.AssertThrows <InvalidCastException>(() => Duck.Cast <ISimplist>(typeof(TargetBad)));
 }
コード例 #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"));
        }
コード例 #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"));
        }
コード例 #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));
        }
コード例 #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));
        }