public void ShouldAssignTheSameCallSequenceToCreatedMocksThatWasAssignedToIt() { var callSequence = new CallSequence(MockBehavior.Strict); var repository = new MockRepository(MockBehavior.Default) { CallSequence = callSequence }; var mock = repository.Create<IFoo>(); Assert.Equal(callSequence, mock.CallSequence); }
public void ShouldAllowVerifyingSettingPropertyInSequence() { var something = "something"; var sequence = new CallSequence(); var mock1 = new Mock<RoleWithProperty> { CallSequence = sequence }; mock1.Object.Anything = something; mock1.Object.Anything = something + something; sequence.Verify( mock1.CallToSet(m => m.Anything = something), mock1.CallToSet(m => m.Anything = something + something) ); }
public void ShouldIgnoreCallsInbetweenMatchingCalls() { var sequence = new CallSequence(); var mock1 = new Mock<RoleWithSingleSimplestMethod> { CallSequence = sequence }; var mock2 = new Mock<RoleWithSingleSimplestMethod> { CallSequence = sequence }; var mock3 = new Mock<RoleWithSingleSimplestMethod> { CallSequence = sequence }; mock1.Object.Do(); mock3.Object.Do(); mock2.Object.Do(); sequence.Verify( mock1.CallTo(m => m.Do()), mock2.CallTo(m => m.Do()) ); }
public void ShouldAllowAMixOfSequencedAndNonSequencedMocks() { var sequence = new CallSequence(); var mock1 = new Mock<RoleWithSingleSimplestMethod> { CallSequence = sequence }; var mock2 = new Mock<RoleWithSingleSimplestMethod> { CallSequence = sequence }; var mock3 = new Mock<RoleWithSingleSimplestMethod>(); mock1.Object.Do(); mock3.Object.Do(); mock2.Object.Do(); sequence.Verify( mock1.CallTo(a => a.Do()), mock2.CallTo(b => b.Do()) ); }
public void ShouldAllowVerifyingGettingPropertyInSequence() { var sequence = new CallSequence(); string something; var mock1 = new Mock<RoleWithProperty> { CallSequence = sequence }; something = mock1.Object.Anything; something = mock1.Object.AnythingElse; sequence.Verify( mock1.CallToGet(m => m.Anything), mock1.CallToGet(m => m.AnythingElse)); sequence.Verify( mock1.CallToGet(m => m.Anything), mock1.CallToGet(m => m.AnythingElse)); }
public void ShouldNotSupportCyclicSequencing() { var sequence = new CallSequence(MockBehavior.Strict); var a = new Mock<IFoo>() { CallSequence = sequence }; var b = new Mock<IFoo>() { CallSequence = sequence }; a.Object.Do(200); b.Object.Do(100); Assert.Throws<MockException>(() => sequence.Verify( a.CallTo(m => m.Do(100)), b.CallTo(m => m.Do(200)) ) ); }
public void ShouldIgnoreCallsInbetweenUnmatchingCalls() { var sequence = new CallSequence(); var mock1 = new Mock<RoleWithSingleSimplestMethod> { CallSequence = sequence }; var mock2 = new Mock<RoleWithSingleSimplestMethod> { CallSequence = sequence }; var mock3 = new Mock<RoleWithSingleSimplestMethod> { CallSequence = sequence }; mock2.Object.Do(); mock3.Object.Do(); mock1.Object.Do(); Assert.Throws<MockException>(() => sequence.Verify( mock1.CallTo(m => m.Do()), mock2.CallTo(m => m.Do()) ) ); }
public void ShouldPassVerificationOfCallsMadeExactlyInTheVerifiedSequence() { var strictSequence = new CallSequence(MockBehavior.Strict); var a = new Mock<IFoo>() { CallSequence = strictSequence }; var b = new Mock<IFoo>() { CallSequence = strictSequence }; a.Object.Do(100); b.Object.Do(200); strictSequence.Verify( a.CallTo(x => x.Do(100)), b.CallTo(x => x.Do(200)) ); }
public void ShouldThrowMockExceptionWhenExactSequenceIsNotMatched() { var strictSequence = new CallSequence(MockBehavior.Strict); var a = new Mock<IFoo>() { CallSequence = strictSequence }; var b = new Mock<IFoo>() { CallSequence = strictSequence }; b.Object.Do(200); Assert.Throws<MockException>(() => strictSequence.Verify( a.CallTo(m => m.Do(100)) ) ); }
public void ShouldThrowExceptionWhenVerifiedPropertySetDoNotMatchActual() { var something = "something"; var sequence = new CallSequence(); var mock1 = new Mock<RoleWithProperty> { CallSequence = sequence }; mock1.Object.Anything = something; mock1.Object.Anything = something + something; Assert.Throws<MockException>( () => sequence.Verify( mock1.CallToSet(m => m.Anything = something + something), mock1.CallToSet(m => m.Anything = something) ) ); }
public void ShouldThrowExceptionWhenVerifiedPropertyGetDoNotMatchActual() { string something; var sequence = new CallSequence(); var mock1 = new Mock<RoleWithProperty> { CallSequence = sequence }; something = mock1.Object.Anything; something = mock1.Object.AnythingElse; Assert.Throws<MockException>( () => sequence.Verify( mock1.CallToGet(m => m.AnythingElse), mock1.CallToGet(m => m.Anything) ) ); }
public void ShouldThrowExceptionWhenCallsAreNotMadeInOrderInCallSequence() { var sequence = new CallSequence(); var mock1 = new Mock<RoleWithSingleSimplestMethod> { CallSequence = sequence }; var mock2 = new Mock<RoleWithSingleSimplestMethod> { CallSequence = sequence }; mock2.Object.Do(); mock1.Object.Do(); Assert.Throws<MockException>(() => sequence.Verify( mock1.CallTo(m => m.Do()), mock2.CallTo(m => m.Do()) ) ); }
public void ShouldSupportMockChainingWithUnmatchingCalls() { var sequence = new CallSequence(); var mock1 = new Mock<RoleForRecursiveMocking>() { CallSequence = sequence, DefaultValue = DefaultValue.Mock }; mock1.Object.Do().Do(); sequence.Verify( mock1.CallTo(m => m.Do().Do()) ); Assert.Throws<MockException>( () => sequence.Verify( mock1.CallTo(m => m.Do().Do()), mock1.CallTo(m => m.Do()) ) ); }
public void ShouldRecognizeSequenceOfCallsMadeOnTheSameMock() { var sequence = new CallSequence(); var mock1 = new Mock<RoleWithArgumentAndReturnValue> {CallSequence = sequence}; mock1.Object.Do(1); mock1.Object.Do(2); mock1.Object.Do(3); sequence.Verify( mock1.CallTo(m => m.Do(2)), mock1.CallTo(m => m.Do(3)) ); Assert.Throws<MockException>( () => sequence.Verify( mock1.CallTo(m => m.Do(2)), mock1.CallTo(m => m.Do(3)), mock1.CallTo(m => m.Do(1)) ) ); }
public void ShouldProperlyRecognizeNonMatchingArgumentsInSequentialVerification() { var sequence = new CallSequence(); var mock1 = new Mock<RoleWithArgumentAndReturnValue> {CallSequence = sequence}; var mock2 = new Mock<RoleWithArgumentAndReturnValue> {CallSequence = sequence}; mock2.Object.Do(1); mock1.Object.Do(2); mock2.Object.Do(3); Assert.Throws<MockException>(() => sequence.Verify( mock1.CallTo(m => m.Do(2)), mock2.CallTo(m => m.Do(1)) ) ); }
public void ShouldNotThrowAnyExceptionWhenCallsAreMadeInOrderInCallSequence() { var sequence = new CallSequence(); var mock1 = new Mock<RoleWithSingleSimplestMethod> { CallSequence = sequence }; var mock2 = new Mock<RoleWithSingleSimplestMethod> { CallSequence = sequence }; mock1.Object.Do(); mock2.Object.Do(); sequence.Verify( mock1.CallTo(m => m.Do()), mock2.CallTo(m => m.Do()) ); }