[Test] public void CanBeCustomisedByOverridingCallMethod() { IMock mock = new CustomMock(typeof(IBlah)); IBlah blah = (IBlah)mock.MockInstance; Assertion.AssertEquals("CUSTOM", blah.DoStuff("hello")); mock.Verify(); }
[Test] public void CanMockMembersInheritedFromBaseInterfaces() { IMock mock = new DynamicMock(typeof(IBlah)); mock.ExpectAndReturn("GetSuperString", "some string"); IBlah b = (IBlah)mock.MockInstance; Assertion.AssertEquals("some string", b.GetSuperString()); }
[Test] public void NamedDynamicMockImplementsAnInterface() { IMock mock = new DynamicMock(typeof(IBlah), "XBlah"); mock.ExpectAndReturn("DoStuff", "world", "hello"); IBlah blah = (IBlah)mock.MockInstance; Assertion.AssertEquals("world", blah.DoStuff("hello")); mock.Verify(); }
public static int Main() { FooBar fooBar = new FooBar(); IFoo foo = (IFoo)fooBar; IBar bar = (IBar)fooBar; IBlah blah = (IBlah)fooBar; Console.WriteLine("Calling IFoo.Foo on FooBar - expecting default method on IFoo.Foo. "); Test.Assert(foo.Foo(10) == 11, "Calling IFoo.Foo on FooBar"); Console.WriteLine("Calling IBar.Bar on FooBar - expecting default method on IBar.Bar. "); Test.Assert(bar.Bar(10) == 20, "Calling IBar.Bar on FooBar"); Console.WriteLine("Calling IBlah.Blah on FooBar - expecting default method on IBlah.Blah from Base. "); Test.Assert(blah.Blah(10) == 16, "Calling IBlah.Blah on FooBar"); Console.WriteLine("Calling FooBar.CallBlahProtected - expecting protected methods on interface can be called"); Test.Assert(fooBar.CallBlahProtected() == 3, "Calling FooBar.CallBlahProtected"); return(Test.Ret()); }
private static void MultiOverride() { FooBarBlahImpl fooBarBlah = new FooBarBlahImpl(); IFoo foo = (IFoo)fooBarBlah; Console.WriteLine("Calling IFoo.Foo methods on FooBarBlahImpl..."); Test.Assert(foo.Foo1(0) == 11111, "Calling IFoo.Foo1 on FooBarBlahImpl"); Test.Assert(foo.Foo2(0) == 22222, "Calling IFoo.Foo2 on FooBarBlahImpl"); Test.Assert(foo.Foo3(0) == 33333, "Calling IFoo.Foo3 on FooBarBlahImpl"); Test.Assert(foo.Foo4(0) == 33333, "Calling IFoo.Foo4 on FooBarBlahImpl"); Test.Assert(foo.Foo5(0) == 33333, "Calling IFoo.Foo5 on FooBarBlahImpl"); Test.Assert(foo.Foo6(6) == 66, "Calling IFoo.Foo6 on FooBarBlahImpl"); Test.Assert(foo.Foo7(7) == 77, "Calling IFoo.Foo7 on FooBarBlahImpl"); Test.Assert(foo.Foo8(8) == 88, "Calling IFoo.Foo8 on FooBarBlahImpl"); Test.Assert(foo.Foo9(9) == 99, "Calling IFoo.Foo9 on FooBarBlahImpl"); IBar bar = (IBar)fooBarBlah; Console.WriteLine("Calling IBar.Bar methods on FooBarBlahImpl..."); Test.Assert(bar.Bar1(0) == 11111, "Calling IBar.Bar1 on FooBarBlahImpl"); Test.Assert(bar.Bar2(0) == 22222, "Calling IBar.Bar2 on FooBarBlahImpl"); Test.Assert(bar.Bar3(0) == 33333, "Calling IBar.Bar3 on FooBarBlahImpl"); Test.Assert(bar.Bar4(0) == 33333, "Calling IBar.Bar4 on FooBarBlahImpl"); Test.Assert(bar.Bar5(0) == 33333, "Calling IBar.Bar5 on FooBarBlahImpl"); Test.Assert(bar.Bar6(0) == 66, "Calling IBar.Bar6 on FooBarBlahImpl"); Test.Assert(bar.Bar7(0) == 77, "Calling IBar.Bar7 on FooBarBlahImpl"); Test.Assert(bar.Bar8(0) == 88, "Calling IBar.Bar8 on FooBarBlahImpl"); Test.Assert(bar.Bar9(0) == 99, "Calling IBar.Bar9 on FooBarBlahImpl"); IBlah blah = (IBlah)fooBarBlah; Console.WriteLine("Calling IBlah.Blah methods on FooBarBlahImpl..."); Test.Assert(blah.Blah1(0) == 11111, "Calling IBlah.Blah1 on FooBarBlahImpl"); Test.Assert(blah.Blah2(0) == 22222, "Calling IBlah.Blah1 on FooBarBlahImpl"); Test.Assert(blah.Blah3(0) == 33333, "Calling IBlah.Blah1 on FooBarBlahImpl"); }
public ThingThatNeedsIBlahAndSomethingElse(IBlah blah, ICollection collection) { if (blah == null) throw new ArgumentNullException("blah"); if (collection == null) throw new ArgumentNullException("collection"); }
public Baz(IBlah blah) { this.blah = blah; }
public Something(IBlah blah) { _blah = blah; }
private static void SingleOverride() { IBarImpl barImpl = new IBarImpl(); IFoo foo = (IFoo)barImpl; Console.WriteLine("Calling IFoo.Foo methods on IBarImpl..."); Test.Assert(foo.Foo1(1) == 11, "Calling IFoo.Foo1 on IBarImpl"); Test.Assert(foo.Foo2(2) == 22, "Calling IFoo.Foo2 on IBarImpl"); Test.Assert(foo.Foo3(3) == 33, "Calling IFoo.Foo3 on IBarImpl"); Test.Assert(foo.Foo4(4) == 44, "Calling IFoo.Foo4 on IBarImpl"); Test.Assert(foo.Foo5(5) == 55, "Calling IFoo.Foo5 on IBarImpl"); Test.Assert(foo.Foo6(0) == 6, "Calling IFoo.Foo6 on IBarImpl"); Test.Assert(foo.Foo7(0) == 7, "Calling IFoo.Foo7 on IBarImpl"); Test.Assert(foo.Foo8(0) == 8, "Calling IFoo.Foo8 on IBarImpl"); Test.Assert(foo.Foo9(0) == 9, "Calling IFoo.Foo9 on IBarImpl"); IBar bar = (IBar)barImpl; Console.WriteLine("Calling IBar.Bar methods on IBarImpl..."); Test.Assert(bar.Bar1(0) == 11, "Calling IBar.Bar1 on IBarImpl"); Test.Assert(bar.Bar2(0) == 22, "Calling IBar.Bar2 on IBarImpl"); Test.Assert(bar.Bar3(0) == 33, "Calling IBar.Bar3 on IBarImpl"); Test.Assert(bar.Bar4(0) == 44, "Calling IBar.Bar4 on IBarImpl"); Test.Assert(bar.Bar5(0) == 55, "Calling IBar.Bar5 on IBarImpl"); Test.Assert(bar.Bar6(0) == 66, "Calling IBar.Bar6 on IBarImpl"); Test.Assert(bar.Bar7(0) == 77, "Calling IBar.Bar7 on IBarImpl"); Test.Assert(bar.Bar8(0) == 88, "Calling IBar.Bar8 on IBarImpl"); Test.Assert(bar.Bar9(0) == 99, "Calling IBar.Bar9 on IBarImpl"); IBlahImpl blahImpl = new IBlahImpl(); foo = (IFoo)blahImpl; Test.Assert(foo.Foo1(1) == 11, "Calling IFoo.Foo1 on IBlahImpl"); Test.Assert(foo.Foo2(2) == 22, "Calling IFoo.Foo2 on IBlahImpl"); Test.Assert(foo.Foo3(3) == 33, "Calling IFoo.Foo3 on IBlahImpl"); Test.Assert(foo.Foo4(4) == 44, "Calling IFoo.Foo4 on IBlahImpl"); Test.Assert(foo.Foo5(5) == 55, "Calling IFoo.Foo5 on IBlahImpl"); Test.Assert(foo.Foo6(6) == 66, "Calling IFoo.Foo6 on IBlahImpl"); Test.Assert(foo.Foo7(7) == 77, "Calling IFoo.Foo7 on IBlahImpl"); Test.Assert(foo.Foo8(8) == 88, "Calling IFoo.Foo8 on IBlahImpl"); Test.Assert(foo.Foo9(9) == 99, "Calling IFoo.Foo9 on IBlahImpl"); bar = (IBar)blahImpl; Console.WriteLine("Calling IBar.Bar methods on IBlahImpl..."); Test.Assert(bar.Bar1(1) == 111, "Calling IBar.Bar1 on IBlahImpl"); Test.Assert(bar.Bar2(2) == 222, "Calling IBar.Bar2 on IBlahImpl"); Test.Assert(bar.Bar3(3) == 333, "Calling IBar.Bar3 on IBlahImpl"); Test.Assert(bar.Bar4(4) == 444, "Calling IBar.Bar4 on IBlahImpl"); Test.Assert(bar.Bar5(5) == 555, "Calling IBar.Bar5 on IBlahImpl"); Test.Assert(bar.Bar6(0) == 66, "Calling IBar.Bar6 on IBlahImpl"); Test.Assert(bar.Bar7(0) == 77, "Calling IBar.Bar7 on IBlahImpl"); Test.Assert(bar.Bar8(0) == 88, "Calling IBar.Bar8 on IBlahImpl"); Test.Assert(bar.Bar9(0) == 99, "Calling IBar.Bar9 on IBlahImpl"); IBlah blah = (IBlah)blahImpl; Console.WriteLine("Calling IBlah.Blah methods on IBlahImpl..."); Test.Assert(blah.Blah1(0) == 111, "Calling IBlah.Blah1 on IBlahImpl"); Test.Assert(blah.Blah2(2) == 2222, "Calling IBlah.Blah1 on IBlahImpl"); Test.Assert(blah.Blah3(3) == 3333, "Calling IBlah.Blah1 on IBlahImpl"); }