コード例 #1
0
        public void MockObjectDelegateWithNoParams()
        {
            ObjectDelegateWithNoParams d = MockRepository.Mock <ObjectDelegateWithNoParams>();

            d.Expect(x => x())
            .Return("abc");

            d.Expect(x => x())
            .Return("def");

            Assert.Equal("abc", d());
            Assert.Equal("def", d());
            Assert.Null(d());

            Assert.Throws <ExpectationViolationException>(
                () => d.VerifyExpectations(true));
        }
コード例 #2
0
        public void CallingMockedDelegatesWithoutOn()
        {
            ObjectDelegateWithNoParams d1 = MockRepository.Mock <ObjectDelegateWithNoParams>();

            d1.Expect(x => x())
            .Return(1);

            Assert.Equal(1, d1());
        }
コード例 #3
0
        public void CallingMockedDelegatesWithoutOn()
        {
            ObjectDelegateWithNoParams d1 = MockRepository.Mock <ObjectDelegateWithNoParams>();

            d1.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

            d1.Expect(x => x())
            .Return(1);

            Assert.Equal(1, d1());
        }
コード例 #4
0
        public void MockTwoDelegatesWithTheSameName()
        {
            ObjectDelegateWithNoParams d1 = MockRepository.Mock <ObjectDelegateWithNoParams>();

            Tests.ObjectDelegateWithNoParams d2 = MockRepository.Mock <Tests.ObjectDelegateWithNoParams>();

            d1.Expect(x => x())
            .Return(1);

            d2.Expect(x => x())
            .Return(2);

            Assert.Equal(1, d1());
            Assert.Equal(2, d2());

            d1.VerifyAllExpectations();
            d2.VerifyAllExpectations();
        }
コード例 #5
0
        public void MockTwoDelegatesWithTheSameName()
        {
            ObjectDelegateWithNoParams d1 = MockRepository.Mock <ObjectDelegateWithNoParams>();

            d1.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

            Tests.ObjectDelegateWithNoParams d2 = MockRepository.Mock <Tests.ObjectDelegateWithNoParams>();
            d2.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

            d1.Expect(x => x())
            .Return(1);

            d2.Expect(x => x())
            .Return(2);

            Assert.Equal(1, d1());
            Assert.Equal(2, d2());

            d1.VerifyAllExpectations();
            d2.VerifyAllExpectations();
        }