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); }
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)); }
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); }
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); }
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); }
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)); }
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); }
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); }
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); }
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); }
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); }
public static void cannot_cast_if_a_target_method_is_missing(Test t) { t.AssertThrows <InvalidCastException>(() => Duck.Cast <ISimplist>(typeof(TargetBad))); }
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")); }
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")); }
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)); }
public static void cannot_cast_if_a_target_method_is_missing(Test t) { var target = new TargetBad(); t.AssertThrows <InvalidCastException>(() => Duck.Cast <ISimplist>(target)); }