public void CanUseNonRecordReplayModel_Stub_WillNotThrowIfExpectationIsNotMet() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); demo.Stub(x => x.DoSomething()).Return(1); mocks.Replay(demo); mocks.VerifyAll(); }
public void CanUseNonRecordReplayModel_Stub() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); demo.Stub(x => x.DoSomething()).Return(1); mocks.Replay(demo); Assert.Equal(1, demo.DoSomething()); }
public void TypeShouldBeInferredFromMockNotReference() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <Foo54>(0); demo.Stub(x => x.DoSomethingElse()); mocks.Replay(demo); demo.DoSomethingElse(); demo.AssertWasCalled(x => x.DoSomethingElse()); }
public void CanUseNonRecordReplayModel_Stub_AndThenVerify_WhenNotCalled_WillCauseError() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); demo.Stub(x => x.DoSomething()).Return(1); mocks.Replay(demo); Assert.Throws <ExpectationViolationException>( "IFoo54.DoSomething(); Expected #1, Actual #0.", () => demo.AssertWasCalled(x => x.DoSomething())); }
public void CanUseNonRecordReplayModel_Stub_OnVoidMethod() { MockRepository mocks = new MockRepository(); IFoo54 demo = mocks.DynamicMock <IFoo54>(); demo.Stub(x => x.DoSomethingElse()).Throw(new InvalidOperationException("foo")); mocks.Replay(demo); try { demo.DoSomethingElse(); Assert.False(true, "Should throw"); } catch (InvalidOperationException e) { Assert.Equal("foo", e.Message); } }