Пример #1
0
        public void CanUseNonRecordReplayModel_Expect()
        {
            MockRepository mocks = new MockRepository();
            IFoo54         demo  = mocks.DynamicMock <IFoo54>();

            demo.Expect(x => x.DoSomething()).Return(1).Repeat.Once();
            mocks.Replay(demo);
            Assert.Equal(1, demo.DoSomething());
            demo.Expect(x => x.DoSomething()).Return(15).Repeat.Once();
            Assert.Equal(15, demo.DoSomething());

            mocks.VerifyAll();
        }
Пример #2
0
        public void WhenNoExpectationIsSetup_WillReturnDefaultValues()
        {
            MockRepository mocks = new MockRepository();
            IFoo54         demo  = mocks.DynamicMock <IFoo54>();

            Assert.Equal(0, demo.DoSomething());
        }
Пример #3
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());
        }
Пример #4
0
        public void CanAssertNotCalledOnPropertyAccess()
        {
            MockRepository mocks = new MockRepository();
            IFoo54         demo  = mocks.DynamicMock <IFoo54>();

            mocks.Replay(demo);

            demo.DoSomething();

            demo.AssertWasNotCalled(x => x.FooBar);
        }
Пример #5
0
        public void CanAssertOnMethodCall()
        {
            MockRepository mocks = new MockRepository();
            IFoo54         demo  = mocks.DynamicMock <IFoo54>();

            mocks.Replay(demo);

            demo.DoSomething();

            demo.AssertWasCalled(x => x.DoSomething());
        }
Пример #6
0
        public void UsingExpectWithoutSettingReturnValueThrows()
        {
            MockRepository mocks = new MockRepository();
            IFoo54         demo  = mocks.DynamicMock <IFoo54>();

            demo.Expect(x => x.DoSomething());
            mocks.Replay(demo);
            Assert.Throws <InvalidOperationException>(
                "Method 'IFoo54.DoSomething();' requires a return value or an exception to throw.",
                () => Assert.Equal(1, demo.DoSomething()));
        }