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 }
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(); }
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 }
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(); }
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")); } }); }