// Prepare mock repository MockRepository mocks = new MockRepository(); IDependency dependency = mocks.CreateMock<IDependency>();object result;With.Mocks( mocks ).Expecting( delegate { // Record expectations Expect.Call( dependency.SomeMethod() ).Return( null ); }) .Verify(delegate { // Replay and validate interaction IComponent underTest = new ComponentImplementation( dependency ); result = underTest.TestMethod(); });// Post-interaction assertions Assert.IsNull( result );
// Prepare mock repository MockRepository mocks = new MockRepository(); IDependency dependency = mocks.CreateMock<IDependency>(); IAnotherDependency anotherDependency = mocks.CreateMock<IAnotherDependency>();object result;With.Mocks( mocks ).ExpectingInSameOrder( delegate { // Record expectations which must be met in the exact same order Expect.Call( dependency.SomeMethod() ).Return( null ); anotherDependency.SomeOtherMethod(); }) .Verify(delegate { // Replay and validate interaction IComponent underTest = new ComponentImplementation( dependency, anotherDependency ); result = underTest.TestMethod(); });// Post-interaction assertions Assert.IsNull( result );
With.Mocks(delegate { IDemo demo = Mocker.Current.CreateMock<IDemo>(); Expect.Call(demo.ReturnIntNoArgs()).Return(5); Mocker.Current.ReplayAll(); Assert.AreEqual(5, demo.ReturnIntNoArgs()); });
MockRepository mocks = new MockRepository(); With.Mocks(mocks, delegate { IDemo demo = Mocker.Current.CreateMock<IDemo>(); Expect.Call(demo.ReturnIntNoArgs()).Return(5); Mocker.Current.ReplayAll(); Assert.AreEqual(5, demo.ReturnIntNoArgs()); });