コード例 #1
0
        public void Virtual_public_method_called_from_ctor_is_not_called_during_partial_mock_construction()
        {
            string mockedResult = "mocked result";

            MockRepository mockRepository = new MockRepository();
            ConcretePublicMethodCalledFromCtor concretePublicMethodCalledFromCtor = mockRepository.PartialMock <ConcretePublicMethodCalledFromCtor>();

            Expect.Call(concretePublicMethodCalledFromCtor.SimplyHereSoThereIsSomethingToMock()).Return(mockedResult);

            mockRepository.ReplayAll();

            string result = concretePublicMethodCalledFromCtor.SimplyHereSoThereIsSomethingToMock();

            mockRepository.VerifyAll();

            Assert.Equal(mockedResult, result);
            Assert.Equal(true, concretePublicMethodCalledFromCtor.WasAbstractMethodCalledFromCtor);
        }
コード例 #2
0
        public void Virtual_public_method_called_from_ctor_is_not_called_during_partial_mock_construction()
        {
            string mockedResult = "mocked result";

            ConcretePublicMethodCalledFromCtor concretePublicMethodCalledFromCtor =
                MockRepository.Partial <ConcretePublicMethodCalledFromCtor>();

            concretePublicMethodCalledFromCtor.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

            concretePublicMethodCalledFromCtor.Expect(x => x.SimplyHereSoThereIsSomethingToMock())
            .Return(mockedResult);

            string result = concretePublicMethodCalledFromCtor.SimplyHereSoThereIsSomethingToMock();

            Assert.Equal(mockedResult, result);
            Assert.Equal(true, concretePublicMethodCalledFromCtor.WasAbstractMethodCalledFromCtor);

            concretePublicMethodCalledFromCtor.VerifyAllExpectations();
        }