Пример #1
0
        public void StubNeverFailsTheTest()
        {
            IGetResults resultGetter = MockRepository.Mock <IGetResults>();

            resultGetter.Stub(x => x.GetSomeNumber("a"))
            .Return(1);

            int result = resultGetter.GetSomeNumber("b");

            Assert.Equal(0, result);
            resultGetter.VerifyExpectations(); //<- should not fail the test methinks
        }
Пример #2
0
        public void CanGetSetupResultFromStub()
        {
            IGetResults resultGetter = MockRepository.Mock <IGetResults>();

            resultGetter.Stub(x => x.GetSomeNumber("a"))
            .Return(1);

            int result = resultGetter.GetSomeNumber("a");

            Assert.Equal(1, result);
            resultGetter.VerifyExpectations();
        }
Пример #3
0
        public void StubNeverFailsTheTest()
        {
            MockRepository repository   = new MockRepository();
            IGetResults    resultGetter = repository.Stub <IGetResults>();

            using (repository.Record())
            {
                resultGetter.GetSomeNumber("a");
                LastCall.Return(1);
            }

            int result = resultGetter.GetSomeNumber("b");

            Assert.Equal(0, result);
            repository.VerifyAll(); //<- should not fail the test methinks
        }
Пример #4
0
        public void CanGetSetupResultFromStub()
        {
            MockRepository repository   = new MockRepository();
            IGetResults    resultGetter = repository.Stub <IGetResults>();

            using (repository.Record())
            {
                resultGetter.GetSomeNumber("a");
                LastCall.Return(1);
            }

            int result = resultGetter.GetSomeNumber("a");

            Assert.Equal(1, result);
            repository.VerifyAll();
        }
Пример #5
0
        public void CannotCallLastCallConstraintsMoreThanOnce()
        {
            MockRepository repository   = new MockRepository();
            IGetResults    resultGetter = repository.Stub <IGetResults>();

            Assert.Throws <InvalidOperationException>(
                "You have already specified constraints for this method. (IGetResults.GetSomeNumber(contains \"b\");)",
                () =>
            {
                using (repository.Record())
                {
                    resultGetter.GetSomeNumber("a");
                    LastCall.Constraints(Text.Contains("b"));
                    LastCall.Constraints(Text.Contains("a"));
                }
            });
        }