public void CanExpect() { demo.Expect(x => x.Prop) .Return("Ayende"); Assert.Equal("Ayende", demo.Prop); }
public void CanSetupExpectations() { demo.Expect(x => x.ReturnIntNoArgs()) .Return(30); Assert.Equal(30, demo.ReturnIntNoArgs()); Assert.Equal(0, demo.ReturnIntNoArgs()); }
private static void RecordOrdered(IDemo demo) { demo.Expect(x => x.ReturnStringNoArgs()) .Return(null); demo.Expect(x => x.VoidNoArgs()) .Repeat.Twice(); demo.Expect(x => x.VoidStringArg("Hello")); demo.Expect(x => x.VoidStringArg("World")); }
public void MockInterface() { IDemo demo = MockRepository.Mock <IDemo>(); demo.Expect(x => x.ReturnIntNoArgs()) .Return(54); demo.Expect(x => x.VoidStringArg("54")); contextSwitcher.DoStuff(demo); demo.VerifyAllExpectations(); }
public void RecursiveExpectationsOnUnordered() { demo = (IDemo)MockRepository.GenerateStrictMock(typeof(IDemo)); demo.Expect(x => x.VoidNoArgs()) .Callback(new DelegateDefinations.NoArgsDelegate(CallMethodOnDemo)); demo.Expect(x => x.VoidStringArg("Ayende")); demo.VoidNoArgs(); demo.VerifyAllExpectations(); }
public void MockInterfaceUnexpectedCall() { IDemo demo = MockRepository.Mock <IDemo>(); demo.Expect(x => x.ReturnIntNoArgs()) .Return(34); demo.Expect(x => x.VoidStringArg("bang")); contextSwitcher.DoStuff(demo); Assert.Throws <ExpectationViolationException>( () => demo.VerifyExpectations(true)); }
public void RecursiveExpectationsOnOrdered() { demo = (IDemo)MockRepository.GenerateStrictMock(typeof(IDemo)); demo.Expect(x => x.VoidNoArgs()) .Callback(CallMethodOnDemo); demo.Expect(x => x.VoidStringArg("Ayende")); 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 SteppingFromInnerOrderringToOuterWithoutFullifingAllOrderringInInnerThrows() { demo = (IDemo)MockRepository.GenerateStrictMock(typeof(IDemo)); demo.Expect(x => x.VoidThreeStringArgs("", "", "")); demo.Expect(x => x.VoidNoArgs()); demo.Expect(x => x.VoidStringArg("Ayende")); demo.VoidNoArgs(); Assert.Throws <ExpectationViolationException>( "Unordered method call! The expected call is: 'Ordered: { IDemo.VoidStringArg(\"Ayende\"); }' but was: 'IDemo.VoidThreeStringArgs(\"\", \"\", \"\");'", () => demo.VoidThreeStringArgs("", "", "")); }
public void MockInterface() { IDemo demo = MockRepository.Mock <IDemo>(); demo.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); demo.Expect(x => x.ReturnIntNoArgs()) .Return(54); demo.Expect(x => x.VoidStringArg("54")); contextSwitcher.DoStuff(demo); demo.VerifyAllExpectations(); }
public void CanFailIfCalledMoreThanOnceUsingDynamicMock() { IDemo demo = Repository.Mock <IDemo>(); demo.Expect(x => x.VoidNoArgs()) .Repeat.Once(); demo.Expect(x => x.VoidNoArgs()) .Repeat.Never(); Assert.Throws <ExpectationViolationException>( "IDemo.VoidNoArgs(); Expected #0, Actual #1.", demo.VoidNoArgs); }
public void CanSetupResultForMethodAndIgnoreArgs() { demo.Expect(x => x.StringArgString(null)) .IgnoreArguments() .Return("Ayende") .Repeat.Any(); Assert.Equal("Ayende", demo.StringArgString("a")); Assert.Equal("Ayende", demo.StringArgString("b")); demo.VerifyAllExpectations(); }
public void CantCallOriginalMethodOnInterface() { IDemo demo = MockRepository.Mock <IDemo>(); Assert.Throws <InvalidOperationException>( () => demo.Expect(x => x.ReturnIntNoArgs()) .CallOriginalMethod()); }
public void ShouldNotExpect() { demo.Expect(x => x.StringArgString("Ayende")) .Repeat.Never(); demo.StringArgString("Ayende"); Assert.Throws <ExpectationViolationException>( () => demo.VerifyExpectations()); }
public void TryingToGetEventRaiserFromNonEvenTrhows() { IDemo demo = MockRepository.GenerateStrictMock <IDemo>(); Assert.Throws <InvalidOperationException>( "The last method call EnumNoArgs was not an event add / remove method", () => demo.Expect(x => x.EnumNoArgs()) .GetEventRaiser()); }
public void NaturalSyntaxForCallingMethods() { IDemo demo = MockRepository.Mock <IDemo>(); demo.Expect(x => x.VoidNoArgs()); demo.VoidNoArgs(); demo.VerifyExpectations(); }
public void NaturalSyntaxForCallingMethods_WithArguments_WhenNotCalled_WouldFailVerification() { IDemo demo = MockRepository.Mock <IDemo>(); demo.Expect(x => x.VoidStringArg("blah")); Assert.Throws <ExpectationViolationException>( () => demo.VerifyExpectations()); }
public void CallbackThatThrows() { demo = (IDemo)MockRepository.GenerateStrictMock(typeof(IDemo)); demo.Expect(x => x.VoidNoArgs()) .Callback(new DelegateDefinations.NoArgsDelegate(ThrowFromCallback)); Assert.Throws <AddressAlreadyInUseException>(demo.VoidNoArgs); }
public void NaturalSyntaxForCallingMethods_WithArguments() { IDemo demo = MockRepository.Mock <IDemo>(); demo.Expect(x => x.VoidStringArg("blah")); demo.VoidStringArg("blah"); demo.VerifyExpectations(); }
public void MockInterfaceWithSameName() { IDemo demo = MockRepository.Mock <IDemo>(); Other.IDemo remotingDemo = MockRepository.Mock <Other.IDemo>(); demo.Expect(x => x.ReturnIntNoArgs()) .Return(54); demo.Expect(x => x.VoidStringArg("54")); remotingDemo.Expect(x => x.ProcessString("in")); contextSwitcher.DoStuff(demo); contextSwitcher.DoStuff(remotingDemo); demo.VerifyAllExpectations(); remotingDemo.VerifyAllExpectations(); }
public void CantCallOriginalMethodOnInterface() { IDemo demo = MockRepository.Mock <IDemo>(); demo.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); Assert.Throws <InvalidOperationException>( () => demo.Expect(x => x.ReturnIntNoArgs()) .CallOriginalMethod()); }
public void MockInterfaceExpectException() { IDemo demo = MockRepository.Mock <IDemo>(); demo.Expect(x => x.ReturnIntNoArgs()) .Throws <InvalidOperationException>(); Assert.Throws <InvalidOperationException>( () => contextSwitcher.DoStuff(demo)); }
public void GetArgsOfEpectedAndActualMethodCallOnException() { demo = (IDemo)MockRepository.GenerateStrictMock(typeof(IDemo)); demo.Expect(x => x.VoidThreeStringArgs("a", "b", "c")); Assert.Throws <ExpectationViolationException>( "IDemo.VoidThreeStringArgs(\"c\", \"b\", \"a\"); Expected #0, Actual #1.\r\nIDemo.VoidThreeStringArgs(\"a\", \"b\", \"c\"); Expected #1, Actual #0.", () => demo.VoidThreeStringArgs("c", "b", "a")); }
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 UsingReturnAndThenIgnoreArgs() { IDemo demo = MockRepository.Mock <IDemo>(); demo.Expect(x => x.StringArgString(null)) .IgnoreArguments() .Return("ayende"); Assert.Equal("ayende", demo.StringArgString("rahien")); demo.VerifyExpectations(true); }
public void NaturalSyntaxForCallingMethods() { IDemo demo = MockRepository.Mock <IDemo>(); demo.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); demo.Expect(x => x.VoidNoArgs()); demo.VoidNoArgs(); 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 MockRepositoryClearsArgData() { Arg <int> .Is.Equal(4); Arg <int> .Is.Equal(4); demoMock = MockRepository.Mock <IDemo>(); demoMock.Expect(x => x.VoidThreeArgs( Arg <int> .Is.Equal(4), Arg.Text.Contains("World"), Arg <float> .Is.Equal(3.14f))); }
public void CanCallMethodWithParameters_WithoutSpecifyingParameters_WillAcceptAnyParameter() { IDemo demo = MockRepository.Mock <IDemo>(); demo.Expect(x => x.VoidStringArg("blah")) .IgnoreArguments(); demo.VoidStringArg("asd"); demo.VerifyExpectations(); }
public void MockRepositoryClearsArgData() { Arg <int> .Is.Equal(4); Arg <int> .Is.Equal(4); demoMock = MockRepository.Mock <IDemo>(); demoMock.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); demoMock.Expect(x => x.VoidThreeArgs( Arg <int> .Is.Equal(4), Arg.Text.Contains("World"), Arg <float> .Is.Equal(3.14f))); }
public void MockInterfaceExpectException() { IDemo demo = MockRepository.Mock <IDemo>(); demo.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); demo.Expect(x => x.ReturnIntNoArgs()) .Throws <InvalidOperationException>(); Assert.Throws <InvalidOperationException>( () => contextSwitcher.DoStuff(demo)); }
private static void CanCreateAStrictMultiMockFromTwoInterfacesCommon(IDemo demo) { demo.Expect(x => x.ReturnIntNoArgs()) .Return(1); IDisposable disposable = demo as IDisposable; Assert.NotNull(disposable); disposable.Expect(x => x.Dispose()); Assert.Equal(1, demo.ReturnIntNoArgs()); disposable.Dispose(); demo.VerifyAllExpectations(); }
public void RecursiveExpectationsOnUnordered() { demo = (IDemo)MockRepository.GenerateStrictMock(typeof(IDemo)); demo.Expect(x => x.VoidNoArgs()) .Callback(new DelegateDefinations.NoArgsDelegate(CallMethodOnDemo)); demo.Expect(x => x.VoidStringArg("Ayende")); demo.VoidNoArgs(); demo.VerifyAllExpectations(); }
public void GetArgsOfEpectedAndActualMethodCallOnException() { demo = (IDemo)MockRepository.GenerateStrictMock(typeof(IDemo)); demo.Expect(x => x.VoidThreeStringArgs("a", "b", "c")); Assert.Throws<ExpectationViolationException>( "IDemo.VoidThreeStringArgs(\"c\", \"b\", \"a\"); Expected #0, Actual #1.\r\nIDemo.VoidThreeStringArgs(\"a\", \"b\", \"c\"); Expected #1, Actual #0.", () => demo.VoidThreeStringArgs("c", "b", "a")); }
private static void CanCreateADynamicMultiMockFromTwoInterfacesCommon(IDemo demo, IEditableObject editable) { Assert.IsNotNull(demo, "IDemo null"); Assert.IsNotNull(editable, "IEditableObject null"); // Set expectation on one member on each interface demo.Expect(x => demo.ReadOnly).Return("foo"); editable.Expect(x => x.BeginEdit()); // Drive two members on each interface to check dynamic nature Assert.AreEqual("foo", demo.ReadOnly); demo.VoidNoArgs(); editable.BeginEdit(); editable.EndEdit(); demo.VerifyAllExpectations(); }
public void SteppingFromInnerOrderringToOuterWithoutFullifingAllOrderringInInnerThrows() { demo = (IDemo) MockRepository.GenerateStrictMock(typeof (IDemo)); demo.Expect(x => x.VoidThreeStringArgs("", "", "")); demo.Expect(x => x.VoidNoArgs()); demo.Expect(x => x.VoidStringArg("Ayende")); demo.VoidNoArgs(); Assert.Throws<ExpectationViolationException>( "Unordered method call! The expected call is: 'Ordered: { IDemo.VoidStringArg(\"Ayende\"); }' but was: 'IDemo.VoidThreeStringArgs(\"\", \"\", \"\");'", () => demo.VoidThreeStringArgs("", "", "")); }
public void CallbackThatThrows() { demo = (IDemo) MockRepository.GenerateStrictMock(typeof (IDemo)); demo.Expect(x => x.VoidNoArgs()) .Callback(new DelegateDefinations.NoArgsDelegate(ThrowFromCallback)); Assert.Throws<AddressAlreadyInUseException>(demo.VoidNoArgs); }
public void MockRepositoryClearsArgData() { Arg<int>.Is.Equal(4); Arg<int>.Is.Equal(4); // create new MockRepository to see if the Arg data has been cleared demoMock = MockRepository.GenerateStrictMock<IDemo>(); demoMock.Expect(x => x.VoidThreeArgs(Arg<int>.Is.Equal(4), Arg.Text.Contains("World"), Arg<float>.Is.Equal(3.14f))); }
private static void RecordOrdered(IDemo demo) { demo.Expect(x => x.ReturnStringNoArgs()) .Return(null); demo.Expect(x => x.VoidNoArgs()) .Repeat.Twice(); demo.Expect(x => x.VoidStringArg("Hello")); demo.Expect(x => x.VoidStringArg("World")); }
public void RecursiveExpectationsOnOrdered() { demo = (IDemo)MockRepository.GenerateStrictMock(typeof(IDemo)); demo.Expect(x => x.VoidNoArgs()) .Callback(CallMethodOnDemo); demo.Expect(x => x.VoidStringArg("Ayende")); 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 MockRepositoryClearsArgData() { Arg<int>.Is.Equal(4); Arg<int>.Is.Equal(4); demoMock = MockRepository.Mock<IDemo>(); demoMock.Expect(x => x.VoidThreeArgs( Arg<int>.Is.Equal(4), Arg.Text.Contains("World"), Arg<float>.Is.Equal(3.14f))); }