public void UsingPredicate() { demo.Expect(x => x.VoidStringArg(Arg <string> .Matches(s => (s.Length == 2 && s.EndsWith("b"))))); demo.VoidStringArg("ab"); demo.VerifyExpectations(); }
public void LastCallIgnoreArguments() { demo.VoidStringArg("hello"); LastCall.IgnoreArguments(); mocks.ReplayAll(); demo.VoidStringArg("bye"); }
public void CanUseAnonymousDelegatesToCallVoidMethods_WithStringArg() { DoNotExpect.Call(delegate { demo.VoidStringArg("Ayende"); }); mocks.ReplayAll(); Assert.Throws <ExpectationViolationException>( "IDemo.VoidStringArg(\"Ayende\"); Expected #0, Actual #1.", () => demo.VoidStringArg("Ayende")); }
public void CallbackIsCalled() { demo.VoidStringArg("Ayende"); LastCall.On(demo).Callback <string>(StringMethod); mocks.Replay(demo); demo.VoidStringArg(""); mocks.Verify(demo); Assert.True(callbackCalled); }
private static void RecordOrdered(MockRepository mocks, IDemo demo) { using (mocks.Ordered()) { demo.ReturnStringNoArgs(); LastCall.On(demo).Return(null); demo.VoidNoArgs(); LastCall.On(demo).Repeat.Twice(); demo.VoidStringArg("Hello"); demo.VoidStringArg("World"); } }
public void Matches() { demoMock.Expect(x => x.VoidStringArg(Arg <string> .Matches(Is.Equal("hallo") || Text.EndsWith("b")))) .Repeat.Times(3); demoMock.VoidStringArg("hallo"); demoMock.VoidStringArg("ab"); demoMock.VoidStringArg("bb"); demoMock.VerifyExpectations(); }
public void NaturalSyntaxForCallingMethods_WithArguments() { MockRepository mocks = new MockRepository(); IDemo demo = mocks.StrictMock <IDemo>(); using (mocks.Record()) { Expect.Call(() => demo.VoidStringArg("blah")); } using (mocks.Playback()) { demo.VoidStringArg("blah"); } }
public void CanCallMethodWithParameters_WithoutSpecifyingParameters_WillAcceptAnyParameter() { MockRepository mocks = new MockRepository(); IDemo demo = mocks.StrictMock <IDemo>(); using (mocks.Record()) { Expect.Call(() => demo.VoidStringArg("blah")).IgnoreArguments(); } using (mocks.Playback()) { demo.VoidStringArg("asd"); } }
public void NaturalSyntaxForCallingMethods_WithArguments_WhenCalledWithDifferentArgument() { MockRepository mocks = new MockRepository(); IDemo demo = mocks.StrictMock <IDemo>(); using (mocks.Record()) { Expect.Call(() => demo.VoidStringArg("blah")); } Throws.Exception <ExpectationViolationException>(@"IDemo.VoidStringArg(""arg""); Expected #0, Actual #1. IDemo.VoidStringArg(""blah""); Expected #1, Actual #0.", delegate { demo.VoidStringArg("arg"); }); }
public void NaturalSyntaxForCallingMethods_WithArguments() { IDemo demo = MockRepository.Mock <IDemo>(); demo.Expect(x => x.VoidStringArg("blah")); demo.VoidStringArg("blah"); demo.VerifyExpectations(); }
public void NaturalSyntaxForCallingMethods_WithArguments_WhenCalledWithDifferentArgument() { IDemo demo = MockRepository.Mock <IDemo>(); demo.Expect(x => x.VoidStringArg("blah")); demo.VoidStringArg("arg"); Assert.Throws <ExpectationViolationException>( () => demo.VerifyExpectations(true)); }
public void CanUseAnonymousDelegatesToCallVoidMethods_WithStringArg() { demo.Expect(x => x.VoidStringArg("Ayende")) .Repeat.Never(); demo.VoidStringArg("Ayende"); Assert.Throws <ExpectationViolationException>( () => demo.VerifyExpectations()); }
public void RecursiveExpectationsOnUnordered() { demo = (IDemo)mocks.StrictMock(typeof(IDemo)); demo.VoidNoArgs(); LastCall.On(demo).Callback(new DelegateDefinations.NoArgsDelegate(CallMethodOnDemo)); demo.VoidStringArg("Ayende"); mocks.Replay(demo); demo.VoidNoArgs(); mocks.Verify(demo); }
public void CallbackIsCalled() { demo.Expect(x => x.VoidStringArg("Ayende")) .IgnoreArguments() .WhenCalled <string>(x => StringMethod(x)); demo.VoidStringArg(""); demo.VerifyExpectations(true); Assert.True(callbackCalled); }
public void CanCallMethodWithParameters_WithoutSpecifyingParameters_WillAcceptAnyParameter() { IDemo demo = MockRepository.Mock <IDemo>(); demo.Expect(x => x.VoidStringArg("blah")) .IgnoreArguments(); demo.VoidStringArg("asd"); demo.VerifyExpectations(); }
public void NaturalSyntaxForCallingMethods_WithArguments() { IDemo demo = MockRepository.Mock <IDemo>(); demo.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); demo.Expect(x => x.VoidStringArg("blah")); demo.VoidStringArg("blah"); demo.VerifyExpectations(); }
public void MockInterface() { MockRepository mocks = new MockRepository(); IDemo demo = (IDemo)mocks.StrictMock(typeof(IDemo)); Expect.Call(demo.ReturnIntNoArgs()).Return(54); demo.VoidStringArg("54"); mocks.ReplayAll(); contextSwitcher.DoStuff(demo); mocks.VerifyAll(); }
public void MockInterfaceUnexpectedCall() { MockRepository mocks = new MockRepository(); IDemo demo = (IDemo)mocks.StrictMock(typeof(IDemo)); Expect.Call(demo.ReturnIntNoArgs()).Return(34); demo.VoidStringArg("bang"); mocks.ReplayAll(); Assert.Throws <ExpectationViolationException>( "IDemo.VoidStringArg(\"34\"); Expected #0, Actual #1.\r\nIDemo.VoidStringArg(\"bang\"); Expected #1, Actual #0.", () => contextSwitcher.DoStuff(demo)); }
public void RecursiveExpectationsOnOrdered() { demo = (IDemo)mocks.StrictMock(typeof(IDemo)); using (mocks.Ordered()) { demo.VoidNoArgs(); LastCall.On(demo).Callback(CallMethodOnDemo); demo.VoidStringArg("Ayende"); } mocks.Replay(demo); Assert.Throws <ExpectationViolationException>( "Unordered method call! The expected call is: 'Ordered: { IDemo.VoidNoArgs(callback method: RhinoMockTests.CallMethodOnDemo); }' but was: 'IDemo.VoidStringArg(\"Ayende\");'", () => demo.VoidNoArgs()); }
public void MockInterfaceWithSameName() { MockRepository mocks = new MockRepository(); IDemo demo = (IDemo)mocks.StrictMock(typeof(IDemo)); Expect.Call(demo.ReturnIntNoArgs()).Return(54); demo.VoidStringArg("54"); Other.IDemo remotingDemo = (Other.IDemo)mocks.StrictMock(typeof(Other.IDemo)); remotingDemo.ProcessString("in"); mocks.ReplayAll(); contextSwitcher.DoStuff(demo); contextSwitcher.DoStuff(remotingDemo); mocks.VerifyAll(); }
public void NaturalSyntaxForCallingMethods_WithArguments_WhenNotCalled_WouldFailVerification() { MockRepository mocks = new MockRepository(); IDemo demo = mocks.StrictMock <IDemo>(); using (mocks.Record()) { Expect.Call(() => demo.VoidStringArg("blah")); } Throws.Exception <ExpectationViolationException>("IDemo.VoidStringArg(\"blah\"); Expected #1, Actual #0.", delegate { mocks.VerifyAll(); }); }
public void SteppingFromInnerOrderringToOuterWithoutFullifingAllOrderringInInnerThrows() { demo = (IDemo)mocks.StrictMock(typeof(IDemo)); demo.VoidThreeStringArgs("", "", ""); using (mocks.Ordered()) { demo.VoidNoArgs(); demo.VoidStringArg("Ayende"); } mocks.Replay(demo); demo.VoidNoArgs(); Assert.Throws <ExpectationViolationException>( "Unordered method call! The expected call is: 'Ordered: { IDemo.VoidStringArg(\"Ayende\"); }' but was: 'IDemo.VoidThreeStringArgs(\"\", \"\", \"\");'", () => demo.VoidThreeStringArgs("", "", "")); }
private static void RecordOrdered(MockRepository mocks, IDemo demo) { using (mocks.Ordered()) { demo.ReturnStringNoArgs(); LastCall.On(demo).Return(null); demo.VoidNoArgs(); LastCall.On(demo).Repeat.Twice(); demo.VoidStringArg("Hello"); demo.VoidStringArg("World"); } }
public void SteppingFromInnerOrderringToOuterWithoutFullifingAllOrderringInInnerThrows() { demo = (IDemo)mocks.StrictMock(typeof(IDemo)); demo.VoidThreeStringArgs("", "", ""); using (mocks.Ordered()) { demo.VoidNoArgs(); demo.VoidStringArg("Ayende"); } mocks.Replay(demo); demo.VoidNoArgs(); string expectedMessage = "Unordered method call! The expected call is: 'Ordered: { IDemo.VoidStringArg(\"Ayende\"); }' but was: 'IDemo.VoidThreeStringArgs(\"\", \"\", \"\");'"; ExpectationViolationException ex = Assert.Throws<ExpectationViolationException>( () => demo.VoidThreeStringArgs("", "", "")); Assert.Equal(expectedMessage, ex.Message); }
public void RecursiveExpectationsOnUnordered() { demo = (IDemo)mocks.StrictMock(typeof(IDemo)); demo.VoidNoArgs(); LastCall.On(demo).Callback(new DelegateDefinations.NoArgsDelegate(CallMethodOnDemo)); demo.VoidStringArg("Ayende"); mocks.Replay(demo); demo.VoidNoArgs(); mocks.Verify(demo); }
public void RecursiveExpectationsOnOrdered() { demo = (IDemo)mocks.StrictMock(typeof(IDemo)); using (mocks.Ordered()) { demo.VoidNoArgs(); LastCall.On(demo).Callback(CallMethodOnDemo); demo.VoidStringArg("Ayende"); } mocks.Replay(demo); string expectedMessage = "Unordered method call! The expected call is: 'Ordered: { IDemo.VoidNoArgs(callback method: RhinoMockTests.CallMethodOnDemo); }' but was: 'IDemo.VoidStringArg(\"Ayende\");'"; ExpectationViolationException ex = Assert.Throws<ExpectationViolationException>( () => demo.VoidNoArgs()); Assert.Equal(expectedMessage, ex.Message); }
public void DoStuff(IDemo mock) { int n = mock.ReturnIntNoArgs(); mock.VoidStringArg(n.ToString()); }
public void UsingPredicate() { demo.VoidStringArg(null); LastCall.Constraints( Is.Matching <string>(delegate(string s) { return(s.Length == 2); }) && Is.Matching <string>(delegate(string s) { return(s.EndsWith("b")); })); mocks.Replay(demo); demo.VoidStringArg("ab"); mocks.VerifyAll(); }
public void DoStuff(IDemo mock) { int n = mock.ReturnIntNoArgs(); mock.VoidStringArg(n.ToString()); }
public void RecursiveExpectationsOnOrdered() { demo = (IDemo) mocks.StrictMock(typeof (IDemo)); using (mocks.Ordered()) { demo.VoidNoArgs(); LastCall.On(demo).Callback(CallMethodOnDemo); demo.VoidStringArg("Ayende"); } mocks.Replay(demo); demo.VoidNoArgs(); }
public void SteppingFromInnerOrderringToOuterWithoutFullifingAllOrderringInInnerThrows() { demo = (IDemo) mocks.StrictMock(typeof (IDemo)); demo.VoidThreeStringArgs("", "", ""); using (mocks.Ordered()) { demo.VoidNoArgs(); demo.VoidStringArg("Ayende"); } mocks.Replay(demo); demo.VoidNoArgs(); demo.VoidThreeStringArgs("", "", ""); }