Yep that worked ok.
Now, to change the subject very slightly, now I am understanding the
one assert per test strategy, what tests would be recommended for
testing the following pseaudo method:
public Result SearchAgainstSeveralSystems (string SearchTerm)
{
System1Result = System1.Search(SearchTerm);
System2Result = System2.Search(SearchTerm);
Result result = new Result;
Result.SystemResults.Add(System1Result);
Result.SystemResults.Add(System2Result);
}
my understanding would be make sure you hit the various systems:
search_that_system1_is_searched_against (mocking system1, and stubbing
system2 and result.SystemResults.Add
search_that_system2_is_searched_against (mocking system2, and stubbing
system1 and result.SystemResults.Add
then, maybe 2 searches for
search_that_results_get_added_to_results (stubbing both systems and
mocking the result.SystemResults.Add method expecting two invocations)
Then, should there be a test that asserts the returned result is the
result object? Suppose not as its just a return command but I could
always mistakenly return another Result object.
Alternatively, instead of mocking the result.SystemResults.Add method,
I could simply do a couple of tests that Assert(result.SystemResults
[0], Is.SameAs (a dummy object returned from stubbed systems).
Does this make sense? Problem is that the test doesn't have a handle
to the Result object and therefore, can't have a direct assert against
it.
Cheers
On Nov 18, 3:43 pm, Patrick Steele <
patrick.ste...@gmail.com> wrote:
> If ArticleSearchCriteria has virtual members, I think you could mock
> the ServiceAreas collection and set an expectation on the "Add"
> method. Assuming you have something like this:
>
> class ArticleSearchCriteria
> {
> public virtual IList<ServiceArea> ServiceAreas { get; set; }
>
> }
>
> You could create a mock IList<ServiceArea> and set an expectation on
> the Add method. Then stub ArticleSearchCritera.ServiceAreas property
> to return your mocked IList<ServiceArea> (below is AAA syntax and
> typed on-the-fly):
>
> var saList = MockRepository.GenerateMock<IList<ServiceArea>>();
> var searchCriteria = MockRepository.GenerateStub<ArticleSearchCriteria>();
> s.ServiceAreas = saList; // I think you can just do the assign with AAA syntax
>
> Now tell Rhino mocks you expect an Add of your resultFromDAO:
>
> saList.Expect(c => c.Add(resultFromDAO));
>
> I think that'll get you going.
>
> ---
> Patrick Steelehttp://
weblogs.asp.net/psteele
>
> On Wed, Nov 18, 2009 at 9:50 AM, Goatified Creature
>