You are trying to provide the value after the actual code was executed.

On Fri, Nov 21, 2008 at 1:16 AM, Cvetomir Todorov <
[EMAIL PROTECTED]> wrote:

> Hi,
>
> I am testing this piece of code
>
>     internal class QueryProcessor
>     {
>         private readonly ITokenizer _tokenizer;
>
>         public QueryProcessor(ITokenizer tokenizer)
>         {
>             _tokenizer = tokenizer;
>         }
>
>         public IList<IDocument> SearchFor(string query, IIndex index)
>         {
>             IList<string> tokens = _tokenizer.Tokenize(query);
>
>             foreach (string token in tokens)
>             {
>                 index.GetPostings(token);
>             }
>
>             return null;
>         }
>     }
>
> This is the test I am interested in:
>
>         [Test]
>         public void Query_ShouldBeTokenized()
>         {
>             // arrange
>             string query = "some query";
>             ITokenizer tokenizerMock =
> MockRepository.GenerateMock<ITokenizer>();
>             tokenizerMock.Expect(x => x.Tokenize(query)).Return(new
> List<string>());
>
>             // act
>             var target = new QueryProcessor(tokenizerMock);
>             target.SearchFor(query, Dummies.Create<IIndex>());
>
>             // assert
>             tokenizerMock.VerifyAllExpectations();
>         }
>
> I want to be sure that the query is tokenized. Because later the tokens
> must be used I have to explicitly say what the return value is. Otherwise
> when tokens.GetEnumerator is called in the production code it will result in
> a null reference exception.
>
> But how can this be achieved with the new AAA syntax?
>
> When I remove the Expect in the arrange and in the assert instead of
> VerifyAllExpectation I say:
>
> tokenizerMock.AssertWasCalled(x => x.Tokenize(query), call =>
> call.Return(new List<string>()));
>
> it compiles just fine but the not-null list is not returned.
>
> --
> Software modules coupling is the path to the dark side.
> Coupling leads to complexity.
> Complexity leads to confusion.
> Confusion leads to suffering.
> Once you start down the dark path, forever will it dominate your destiny,
> consume you it will!
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to