public void CanUseAnonymousDelegatesToCallVoidMethods() { demo.Expect(x => x.VoidNoArgs()) .Throws <ArgumentNullException>(); Assert.Throws <ArgumentNullException>(() => demo.VoidNoArgs()); }
public void CanUseAnonymousDelegatesToCallVoidMethods() { DoNotExpect.Call(delegate { demo.VoidNoArgs(); }); mocks.ReplayAll(); Assert.Throws <ExpectationViolationException>( "IDemo.VoidNoArgs(); Expected #0, Actual #1.", () => demo.VoidNoArgs()); }
public void CallbackThatThrows() { demo = (IDemo)mocks.StrictMock(typeof(IDemo)); demo.VoidNoArgs(); LastCall.Callback(new DelegateDefinations.NoArgsDelegate(ThrowFromCallback)); mocks.ReplayAll(); Assert.Throws<AddressAlreadyInUseException>(() => demo.VoidNoArgs()); }
public void CallbackThatThrows() { demo = (IDemo) mocks.StrictMock(typeof (IDemo)); demo.VoidNoArgs(); LastCall.Callback(new DelegateDefinations.NoArgsDelegate(ThrowFromCallback)); mocks.ReplayAll(); demo.VoidNoArgs(); }
public void CanUseAnonymousDelegatesToCallVoidMethods() { demo.Expect(x => x.VoidNoArgs()) .Repeat.Never(); demo.VoidNoArgs(); 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 CanFailIfCalledMoreThanOnceUsingDynamicMock() { MockRepository mocks = new MockRepository(); IDemo demo = mocks.DynamicMock <IDemo>(); demo.VoidNoArgs(); LastCall.Repeat.Once(); // doesn't realy matter demo.VoidNoArgs(); LastCall.Repeat.Never(); mocks.ReplayAll(); Assert.Throws <ExpectationViolationException>("IDemo.VoidNoArgs(); Expected #0, Actual #1.", demo.VoidNoArgs); }
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 DyamicMockAcceptUnexpectedCall() { IDemo demo = MockRepository.Mock <IDemo>(); demo.VoidNoArgs(); demo.VerifyAllExpectations(); }
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("", "", "")); }
public void SetupResultUsingOrdered() { SetupResult.On(demo).Call(demo.Prop).Return("Ayende"); using (mocks.Ordered()) { demo.VoidNoArgs(); LastCall.On(demo).Repeat.Twice(); } mocks.ReplayAll(); demo.VoidNoArgs(); for (int i = 0; i < 30; i++) { Assert.Equal("Ayende", demo.Prop); } demo.VoidNoArgs(); mocks.VerifyAll(); }
public void CallbackCanFailExpectationByReturningFalse() { demo.VoidNoArgs(); LastCall.On(demo).Callback(NoArgsMethodFalse); mocks.Replay(demo); Assert.Throws <ExpectationViolationException>("IDemo.VoidThreeArgs(1, \"Ayende\", 3.14); Expected #0, Actual #1.", () => demo.VoidThreeArgs(1, "Ayende", 3.14f)); }
public void CallbackThatThrows() { demo = (IDemo)mocks.StrictMock(typeof(IDemo)); demo.VoidNoArgs(); LastCall.Callback(new DelegateDefinations.NoArgsDelegate(ThrowFromCallback)); mocks.ReplayAll(); Assert.Throws <AddressAlreadyInUseException>(demo.VoidNoArgs); }
public void DyamicMockAcceptUnexpectedCall() { IDemo demo = MockRepository.Mock <IDemo>(); demo.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); demo.VoidNoArgs(); demo.VerifyAllExpectations(); }
public void DyamicMockAcceptUnexpectedCall() { MockRepository mocks = new MockRepository(); IDemo demo = (IDemo)mocks.DynamicMock(typeof(IDemo)); mocks.ReplayAll(); demo.VoidNoArgs(); mocks.VerifyAll(); }
public void NaturalSyntaxForCallingMethods() { IDemo demo = MockRepository.Mock <IDemo>(); demo.Expect(x => x.VoidNoArgs()); demo.VoidNoArgs(); demo.VerifyExpectations(); }
public void IgnoreArgumentsAfterDo() { MockRepository mocks = new MockRepository(); IDemo demo = mocks.DynamicMock <IDemo>(); bool didDo = false; demo.VoidNoArgs(); LastCall .Do(SetToTrue(out didDo)) .IgnoreArguments(); mocks.ReplayAll(); demo.VoidNoArgs(); Assert.True(didDo, "Do has not been executed!"); mocks.VerifyAll(); }
public void CanMoveToRecordFromVerifiedWithoutClearingExpectations() { MockRepository mocks = new MockRepository(); IDemo mock = mocks.StrictMock <IDemo>(); mock.VoidNoArgs(); mocks.ReplayAll(); mock.VoidNoArgs(); mocks.VerifyAll(); mocks.BackToRecord(mock, BackToRecordOptions.None); mock.VoidNoArgs(); mocks.ReplayAll(); mock.VoidNoArgs(); mocks.VerifyAll(); }
public void MockObjectThrowsForUnexpectedCall() { IDemo demo = MockRepository.Mock <IDemo>(); demo.VoidNoArgs(); Assert.Throws <ExpectationViolationException>( () => demo.VerifyExpectations(true)); }
public void MockObjectThrowsForUnexpectedCall() { MockRepository mocks = new MockRepository(); IDemo demo = mocks.StrictMock <IDemo>(); mocks.ReplayAll(); demo.VoidNoArgs(); mocks.VerifyAll();//will never get here }
public void MockObjectThrowsForUnexpectedCall() { MockRepository mocks = new MockRepository(); IDemo demo = (IDemo)mocks.StrictMock(typeof(IDemo)); mocks.ReplayAll(); Assert.Throws <ExpectationViolationException>( "IDemo.VoidNoArgs(); Expected #0, Actual #1.", () => demo.VoidNoArgs()); }
public void CanMoveToRecordFromReplyWithoutClearingExpectations() { MockRepository mocks = new MockRepository(); IDemo mock = mocks.StrictMock <IDemo>(); mock.VoidNoArgs(); mocks.ReplayAll(); mocks.BackToRecord(mock, BackToRecordOptions.None); mock.VoidNoArgs(); mocks.ReplayAll(); mock.VoidNoArgs(); Assert.Throws <ExpectationViolationException>( "IDemo.VoidNoArgs(); Expected #1, Actual #0.", () => mocks.VerifyAll()); }
public void MockObjectThrowsForUnexpectedCall_AAA() { //Arrange IDemo demo = MockRepository.GenerateStrictMock <IDemo>(); //Act demo.VoidNoArgs(); //Assert is a different, we expect an exception }
public void DyamicMockAcceptUnexpectedCall() { MockRepository mocks = new MockRepository(); IDemo demo = mocks.DynamicMock <IDemo>(); mocks.ReplayAll(); demo.VoidNoArgs(); Assert.Pass(); mocks.VerifyAll();//works like a charm }
public void NaturalSyntaxForCallingMethods() { IDemo demo = MockRepository.Mock <IDemo>(); demo.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); demo.Expect(x => x.VoidNoArgs()); demo.VoidNoArgs(); demo.VerifyExpectations(); }
public void DyamicMockAcceptUnexpectedCall_AAA() { //Arrange IDemo demo = MockRepository.GenerateMock <IDemo>(); //Act demo.VoidNoArgs(); //Assert Assert.Pass(); }
public void WillPrintLogInfoWithStackTrace() { TraceWriterWithStackTraceExpectationWriter expectationWriter = new TraceWriterWithStackTraceExpectationWriter(); StringWriter writer = new StringWriter(); expectationWriter.AlternativeWriter = writer; RhinoMocks.Logger = expectationWriter; MockRepository mocks = new MockRepository(); IDemo mock = mocks.StrictMock <IDemo>(); mock.VoidNoArgs(); mocks.ReplayAll(); mock.VoidNoArgs(); mocks.VerifyAll(); Assert.Contains("WillPrintLogInfoWithStackTrace", writer.GetStringBuilder().ToString()); }
public void SetupResultUsingOrdered() { demo.Expect(x => x.Prop) .Return("Ayende") .Repeat.Any(); demo.Expect(x => x.VoidNoArgs()) .Repeat.Twice(); demo.VoidNoArgs(); for (int i = 0; i < 30; i++) { Assert.Equal("Ayende", demo.Prop); } demo.VoidNoArgs(); 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(); }
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 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 MockObjectThrowsForUnexpectedCall_WhenVerified_IfFirstExceptionWasCaught() { IDemo demo = MockRepository.Mock <IDemo>(); try { demo.VoidNoArgs(); } catch (Exception) { } Assert.Throws <ExpectationViolationException>( () => demo.VerifyExpectations(true)); }
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 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("", "", "")); }
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); }
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(); }
private static void CanCreateADynamicMultiMockFromTwoInterfacesCommon(MockRepository mocks, IDemo demo, IEditableObject editable) { Assert.NotNull(demo); Assert.NotNull(editable); // Set expectation on one member on each interface Expect.Call(demo.ReadOnly).Return("foo"); editable.BeginEdit(); mocks.ReplayAll(); // Drive two members on each interface to check dynamic nature Assert.Equal("foo", demo.ReadOnly); demo.VoidNoArgs(); editable.BeginEdit(); editable.EndEdit(); mocks.VerifyAll(); }
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 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("", "", ""); }