The difference between the two calls
new MockRepository().GenerateStub<ISomeType>()
Mocks.GenerateStub<ISomeType>();
is about the methodology you are using for your tests, i.e. are you using
Play/Record syntax (the former), or are you using AAA syntax (the latter).
On Monday, February 27, 2012 9:45:15 PM UTC, Ryeknow wrote:
> I was introduced to Rhino Mocks via the book the Art of Unit Testing
> and just starting using it a few days ago. From the examples I read,
> all of the unit tests used the Record & Replay model, the author did
> mentioned that support for the Arrange, Act, and Assert model
> exists.
>
> I've been scouring the internet, reading documentation, etc to try to
> find out how to go about doing this to test if a method is returning
> an expected value. Below is my code:
>
> public interface IPilotManager {
> List<Pilot> Search(Pilot p);
> int Save(Pilot p);
> }
>
> public class Pilot {
> public int PilotID { get; set; }
> public string FirstName { get; set; }
> public string MiddleInitial { get; set; }
> public string LastName { get; set; }
> }
>
> And below is my unit test:
>
> [TestMethod]
> public void PilotSearch_SearchCriteriaSpecified_PilotFound() {
> //This logic fails because the call to the Search method in the Assert
> line doesn't return the List of Pilots
> IPilotManager pilotMngrStub = Mocks.Stub<IPilotManager>();
> pilotMngrStub.Expect(p => p.Search(null)).Return(new List<Pilot>()
> { TestPilot });
> Assert.IsTrue(pilotMngrStub.Search(null).Contains(TestPilot),
> "Failed");
>
> //This logic passes. The call to Search returns a List of pilots in
> the Search method.
> IPilotManager pilotMngrStub =
> MockRepository.GenerateStub<IPilotManager>();
> pilotMngrStub.Expect(p => p.Search(null)).Return(new List<Pilot>()
> { TestPilot });
> Assert.IsTrue(pilotMngrStub.Search(null).Contains(TestPilot),
> "Failed");
> }
>
> What is the difference between the two? I thought the
> MockRepository.GenerateStub was introduced as a way to reduce book
> keeping (as the documentation states), but it looks like there is a
> difference that I'm not picking up.
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rhinomocks/-/zm8J4Qb3I4kJ.
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.