Example #1
0
        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();
        }
Example #2
0
        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());
        }
Example #3
0
        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());
        }
Example #4
0
        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()));
        }
Example #5
0
        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);
            }
        }