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 DyamicMockAcceptUnexpectedCall() { IDemo demo = MockRepository.Mock <IDemo>(); demo.VoidNoArgs(); demo.VerifyAllExpectations(); }
public void DyamicMockAcceptUnexpectedCall() { IDemo demo = MockRepository.Mock <IDemo>(); demo.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault); demo.VoidNoArgs(); demo.VerifyAllExpectations(); }
public void ExpectationExceptionWithDynamicMock() { demo.Expect(x => x.ReturnIntNoArgs()) .Return(30); Assert.Null(demo.ReturnStringNoArgs()); Assert.Throws <ExpectationViolationException>( () => demo.VerifyAllExpectations()); }
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(); }
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 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 IgnoreArgumentsAfterDo() { bool didDo = false; IDemo demo = MockRepository.Mock <IDemo>(); demo.Expect(x => x.VoidNoArgs()) .IgnoreArguments() .DoInstead(SetToTrue(out didDo)); demo.VoidNoArgs(); Assert.True(didDo, "Do has not been executed!"); demo.VerifyAllExpectations(); }
public void PropertyBehaviorForSingleProperty_AAA() { //Arrange IDemo demo = MockRepository.GenerateStrictMock <IDemo>(); demo.Expect(d => d.Prop).PropertyBehavior(); //Act & Assert for (int i = 0; i < 49; i++) { demo.Prop = "ayende" + i; Assert.AreEqual("ayende" + i, demo.Prop); } demo.VerifyAllExpectations(); }
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(); // disposable.VerifyAllExpectations(); }
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(); }
private static void CanCreateADynamicMultiMockFromTwoInterfacesCommon(IDemo demo, IEditableObject editable) { Assert.NotNull(demo); Assert.NotNull(editable); // 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.Equal("foo", demo.ReadOnly); demo.VoidNoArgs(); editable.BeginEdit(); editable.EndEdit(); demo.VerifyAllExpectations(); }
public void Dispose() { demo.VerifyAllExpectations(); }
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 MockParameterToStringShouldBeIgnoredIfItIsInVerifyState() { demo.Expect(x => x.VoidConcreteDemo(demoParam)); Assert.Throws <ExpectationViolationException>(() => 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(); }