public void UsingTheWithMocksExceptingInSameOrderVerifyConstruct_ShouldTakeCareOfOrder() { MockRepository mocks = new MockRepository(); IDemo demo = mocks.StrictMock <IDemo>(); bool verificationFailed; try { With.Mocks(mocks).ExpectingInSameOrder(delegate { Expect.Call(demo.ReturnIntNoArgs()).Return(1); Expect.Call(demo.ReturnStringNoArgs()).Return("2"); }) .Verify(delegate { demo.ReturnStringNoArgs(); demo.ReturnIntNoArgs(); }); verificationFailed = false; } catch (ExpectationViolationException) { verificationFailed = true; } Assert.True(verificationFailed, "Verification was supposed to fail, because the mocks are called in the wrong order"); }
public void ExpectNever() { demo.ReturnStringNoArgs(); LastCall.Repeat.Never(); mocks.ReplayAll(); Assert.Throws <ExpectationViolationException>("IDemo.ReturnIntNoArgs(); Expected #0, Actual #1.", () => demo.ReturnIntNoArgs()); }
public void SetupMyOwnRepository() { MockRepository mocks = new MockRepository(); IDemo demo = mocks.StrictMock <IDemo>(); With.Mocks(mocks, delegate { Expect.Call(demo.ReturnStringNoArgs()).Return("Hi"); Mocker.Current.ReplayAll(); Assert.Equal("Hi", demo.ReturnStringNoArgs()); }); }
public void ExpectationExceptionWithDynamicMock() { demo.Expect(x => x.ReturnIntNoArgs()) .Return(30); Assert.Null(demo.ReturnStringNoArgs()); Assert.Throws <ExpectationViolationException>( () => demo.VerifyAllExpectations()); }
public void ExpectationExceptionWithDynamicMock() { Expect.Call(demo.ReturnIntNoArgs()).Return(30); mocks.ReplayAll(); Assert.Null(demo.ReturnStringNoArgs()); doNotVerifyOnTearDown = true; Assert.Throws <ExpectationViolationException>( "IDemo.ReturnIntNoArgs(); Expected #1, Actual #0.", () => mocks.Verify(demo)); }
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"); } }
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"); } }