Hi Guys, Sorry to bump, I just wondered whether I had commited a terrible sin, or maybe my question is a little dumb!!
Cheers! On Nov 16, 2:52 pm, Goatified Creature <[email protected]> wrote: > Hi, I have been trying to write a unit test in C# for a Manager > method. I am mocking two DAOS. However, the parameter passed to the > manager method will be further populated by the manager and passed as > an argument to one DAO. I wish to place a constraint on the DAO call > to ensure this property was populated correctly. Maybe this is easier > to demonstrate through code.... > > // the manager to test > SearchManager managerToTest = new SearchManager(); > > // mock the two DAOs > MockRepository mocks = new MockRepository(); > ISearchDAO mockedSearchDAO = mocks.StrictMock<ISearchDAO> > (); > IServiceAreaDAO mockedServiceAreaDAO = > mocks.StrictMock<IServiceAreaDAO>(); > > // create a search criteria object that does not have it's > ServiceAreas collection populated > ArticleSearchCriteria criteria = new ArticleSearchCriteria > (); > > // now the manager method will populate the ServiceAreas > property of criteria with a collection of > // matching ServiceArea objects matching the below int > array > int[] serviceAreaIds = { 345435 }; > ServiceArea serviceArea = new ServiceArea(); > > // and these will be the pretend results > ArticleSearchResult resultFromDAO = new ArticleSearchResult > (); > > using (mocks.Record()) > { > Expect.Call(mockedServiceAreaDAO.GetById > (345435)).Return(serviceArea); > > // Now, here, I want a contraint to say > // ensure criteria.ServiceAreas contains the above > serviceArea object. This will be > // set before calling the below DAO method. > Expect.Call(mockedSearchDAO.SearchForArticles > (criteria)).Return(resultFromDAO); > > } > using (mocks.Playback()) > { > // inject DAO dependencies > managerToTest.SearchDAO = mockedSearchDAO; > managerToTest.ServiceAreaDAO = mockedServiceAreaDAO; > > // call the method ensuring correct results. This > works fine > Assert.That(managerToTest.SearchForArticles(criteria, > serviceAreaIds), Is.SameAs(resultFromDAO)); > > // Now, I shouldn't be validating the ServiceAreas > collection was populated through the assert methodology > Assert.That(criteria.ServiceAreas, Has.Member > (serviceArea)); > } > > I have been tearing my receding hair out all afternoon through the > Rhino Mocks documentation to understand how to test this scenario. > > Cheers!!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
