I thought only mocks could verify expectations? Does that work for stubs too?
--- Patrick Steele http://weblogs.asp.net/psteele On Mon, Dec 7, 2009 at 4:24 AM, bill richards <[email protected]> wrote: > As far as my understanding goes (so, this is only an opinion, I > guess), it seems that the difference between Stub and Expect is one of > style, though there are instances when you might not neccesarily want > to stub anything, and therefore Expect would be the member of > choice ... > > An example: > > > // Arrange > var aggregator = MockRepository.GenerateStub<IEventAggregator>(); > var event = MockRepository.GenerateStub<MyEvent>(); > aggregator.Stub(a=>a.GetEvent<MyEvent>()).Return(event); // we know > that this is going to be called, we want to check the correct value is > returned > > // Act > var objectUnderTest = new MyTestableObject(aggregator); > > // Assert > Assert.That(objectUnderTest.Event, Is.EqualTo(event)); > > * NOTE * This is really about me knowing the internal workings of > MyTestableObject -maybe this object actually needs re-factoring > because it seems that "stuff" happens in the constructor. Another way > of testing this exact same code would be .... > > // Arrange > var aggregator = MockRepository.GenerateStub<IEventAggregator>(); > var event = MockRepository.GenerateStub<MyEvent>(); > aggregator.Expect(a=>a.GetEvent<MyEvent>().Return(event); // we are > expecting that a.GetEvent<MyEvent>() will be called > > // Act > var objectUnderTest = new MyTestableObject(aggregator); > > // Assert > aggregator.VerifyAllExpectations(); > > > On Dec 6, 10:05 pm, Fabien Arcellier <[email protected]> > wrote: >> Thanks for your reply. I understand all of it :) >> >> These exemples are taken from the documentation and convert to follow >> AAA >> pattern.http://www.ayende.com/wiki/Rhino+Mocks+Method+Options+Interface.ashx >> >> I have taken this test because it is very easy to understand. >> >> I'd like to know the difference between to methods t.Stub<> and >> t.Expect<> associate with a Mock object. >> >> You only details the execution of stub method. What in the case of >> Expect method ? >> I got the same result in the two test (they pass) >> >> It's this point I try to clarify. >> >> Fabien >> >> On 6 déc, 21:43, bill richards <[email protected]> wrote: >> >> >> >> > AAA Syntax does not use Record()/Play() >> >> > // Arrange >> > var view = MockRepository.GenerateStub<IView>(); >> > view.Stub(v => v.Ask(Arg<string>.IsAny, Arg<string>.IsAny)).Return >> > (null); >> >> > // Act >> > var result = view.Ask("1", null); >> >> > // Assert >> > Assert.That(result, Is.Null); >> >> > ... but, the only thing about this test is .... it's only testing the >> > Mocking Framework (or is that the intention here?). >> >> > The test reads ... >> >> > // Arrange >> > Mocking framework generate a mock of the IView interface please. >> > Mocking framework, when I invoke IView.Ask(string, string), please pay >> > not attention to the values of the call, and give me a return value of >> > null >> >> > // Act. >> > Mocking framework, here's that method call I told you about >> >> > // Assert >> > Unit testing framework, please tell me if the Mocking framework gave >> > me a return value of null >> >> > On Dec 6, 9:25 pm, Fabien Arcellier <[email protected]> >> > wrote: >> >> > > Hello, >> >> > > I have rewritten every exemple in the documentation exemple by using >> > > AAA syntax (arrange, act, assert). >> > > There is one things I don't understand. >> >> > > What is the difference between the t.Stub<> and t.Expect<> ? >> >> > > According to the documentation comments in RhinoMocksExtention.cs, >> > > Stub doesn't create any expectation. >> >> > > What does it means ? >> > > Do you have an article to detail what is the expectation contest ? >> >> > > One exemple to illustrate my question with Expect : >> >> > > [Test] >> > > public void setReturnValueWhateverArguments_AAA() >> > > { >> > > //Assert >> > > this.view.Replay(); >> > > this.view.Expect(v => v.Ask(null, null)).Return >> > > (null).IgnoreArguments(); >> >> > > //Act >> > > object obj = this.view.Ask("1", null); >> >> > > //Assert >> > > Assert.AreEqual(null, obj); >> > > this.view.VerifyAllExpectations(); >> > > } >> >> > > One exemple to illustrate my question with Stub: >> >> > > [Test] >> > > public void setReturnValueWhateverArguments_AAA() >> > > { >> > > //Assert >> > > this.view.Replay(); >> > > this.view.Stub(v => v.Ask(null, null)).Return >> > > (null).IgnoreArguments(); >> >> > > //Act >> > > object obj = this.view.Ask("1", null); >> >> > > //Assert >> > > Assert.AreEqual(null, obj); >> > > this.view.VerifyAllExpectations();//I think this line is >> > > not important in this case >> > > } >> >> > > Is there any difference on the interpretation ? >> >> > > Do you have any article about this topic ? -- You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.
