public static void Positive() { Console.WriteLine("Calling I1.Func on I4Class - expecting I4.Func"); I4Class i4Class = new I4Class(); I1 i1 = (I1)i4Class; Test.Assert(i1.Func(10) == 14, "Expecting I1.Func to land on I4.Func"); Console.WriteLine("Calling I1.Func on I8Class - expecting I8.Func"); I8Class i8Class = new I8Class(); i1 = (I1)i8Class; Test.Assert(i1.Func(10) == 18, "Expecting I1.Func to land on I8.Func"); Console.WriteLine("Calling GI1.Func on GI4Class<object> - expecting GI4.Func<S>"); var gi4Class = new GI4Class <object>(); Type[] types; var gi1 = (GI1 <object>)gi4Class; Test.Assert(gi1.Func <string>(out types) == 4, "Expecting GI1<T>.Func to land on GII4<T>.Func<S>"); Test.Assert(types[0] == typeof(object), "T must be object"); Test.Assert(types[1] == typeof(string), "S must be string"); }
public static void Negative() { FooClass fooObj = new FooClass(); IFoo foo = (IFoo)fooObj; Console.WriteLine("Calling IFoo.Foo on Foo - expecting exception."); try { foo.Foo(10); Test.Assert(false, "Expecting exception on Foo"); } catch (Exception ex) { Console.WriteLine("Exception caught: " + ex.ToString()); } I47Class i47Class = new I47Class(); I1 i1 = (I1)i47Class; Console.WriteLine("Calling I1.Func on I47Class - expecting exception"); try { i1.Func(10); Test.Assert(false, "Expecting exception on I47Class"); } catch (Exception ex) { Console.WriteLine("Exception caught: " + ex.ToString()); } var gi23Class = new GI23Class <object>(); GI1 <object> gi1 = (GI1 <object>)gi23Class; Console.WriteLine("Calling GI1<T>.Func on GI23Class<S> - expecting exception"); try { Type[] types; gi1.Func <string>(out types); Test.Assert(false, "Expecting exception on GI23Class"); } catch (Exception ex) { Console.WriteLine("Exception caught: " + ex.ToString()); } }