im sorry i posted the wrong signature for RenderToHtml; i am moving away
from the other one
public string RenderToHtml(List<Result> results)
{
return "";
}
Im having trouble forming an expectation that this is called with an empty
list of result. does the expect.call() check that args are the same type?
On Mon, Nov 28, 2011 at 9:51 AM, Patrick Steele <[email protected]>wrote:
> Oh, sorry. I missed that part. Odd... I actually surprised that
> code even compiles since your RenderToHTML method doesn't accept a
> List<Result>.
>
> Can you post a complete, failing test case?
>
> ---
> Patrick Steele
> http://weblogs.asp.net/psteele
>
>
>
> On Mon, Nov 28, 2011 at 9:43 AM, Steven Solomon
> <[email protected]> wrote:
> > The strange thing is this expectation never even fails. It actually
> passes
> > but the RenderToHtml method is never called.
> >
> > On Mon, Nov 28, 2011 at 9:13 AM, Patrick Steele <
> [email protected]>
> > wrote:
> >>
> >> My guess is that you have an expectation defined as:
> >>
> >> mockRenderer.Expect(x =>
> >> x.RenderToHtml(Arg<List<Result>>.Matches(y =>
> >> y.Equals(new List<Result>())
> >> ))
> >> );
> >>
> >> That expectation has it's own List<Result> (a new one). Then, when
> >> your manager does its work, it creates its own List<Result>
> >> internally. It will be a different List<Result> than what was defined
> >> in your expectation so that's probably why it's failing.
> >>
> >> If you're expecting an empty list, there's a couple of different
> >> things you could do:
> >>
> >> 1. Use WhenCalled() on your stub object and do an Assert.Fail if the
> >> List<Result> passed to the method doesn't have a count of zero.
> >> 2. Use GetArgumentsForCallsMadeOn() after running the test to pull the
> >> argument (the List<Result>) that was sent to your stub and see if it
> >> has a count of zero.
> >>
> >> ---
> >> Patrick Steele
> >> http://weblogs.asp.net/psteele
> >>
> >>
> >>
> >> On Mon, Nov 28, 2011 at 9:05 AM, Steven Solomon
> >> <[email protected]> wrote:
> >> > public class Request
> >> > {
> >> > public virtual string ExecuteRequest() { ... }
> >> > }
> >> >
> >> > public class Translator
> >> > {
> >> > public virtual List<Result> Translate(String xml) { ... }
> >> > }
> >> >
> >> > // NOTE: this is the class where the expectation is ignored
> >> > public class Renderer
> >> > {
> >> > public virtual string RenderToHtml() { ... }
> >> > }
> >> >
> >> > On Fri, Nov 25, 2011 at 9:19 AM, Patrick Steele
> >> > <[email protected]>
> >> > wrote:
> >> >>
> >> >> Can you also show the signatures of the various methods you're
> mocking?
> >> >>
> >> >> ---
> >> >> Patrick Steele
> >> >> http://weblogs.asp.net/psteele
> >> >>
> >> >>
> >> >>
> >> >> On Wed, Nov 23, 2011 at 12:25 PM, Steven Solomon
> >> >> <[email protected]> wrote:
> >> >> > Hi all,
> >> >> >
> >> >> > I am trying to test that a manager class with call its
> collaborators
> >> >> > when i call GetRecommendations on it
> >> >> > however the mockRender expectation is ignored? I am trying to test
> >> >> > that the renderer will be called
> >> >> > with an empty list of results. Any insight into this is greatly
> >> >> > appreciated.
> >> >> >
> >> >> > var mocks = new MockRepository();
> >> >> >
> >> >> > var mockRequest = mocks.StrictMock<Request>("somequery");
> >> >> > var mockTranslator = mocks.StrictMock<Translator>();
> >> >> > var mockRenderer = mocks.StrictMock<Renderer>();
> >> >> >
> >> >> > Expect.Call(mockRequest.ExecuteRequest()).Return("xml");
> >> >> > Expect.Call(mockTranslator.Translate("xml"));
> >> >> > // we are expecting an empty list of results
> >> >> > mockRenderer.Expect(x =>
> >> >> > x.RenderToHtml(Arg<List<Result>>.Matches(y =>
> >> >> > y.Equals(new List<Result>())
> >> >> > ))
> >> >> > );
> >> >> >
> >> >> > mocks.ReplayAll();
> >> >> >
> >> >> > // SUT
> >> >> > Manager manager = new Manager(mockRequest, mockTranslator,
> >> >> > mockRenderer);
> >> >> > manager.GetRecommendations();
> >> >> >
> >> >> > mocks.VerifyAll();
> >> >> >
> >> >> > --
> >> >> > 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.
> >> >> >
> >> >> >
> >> >>
> >> >> --
> >> >> 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.
> >> >>
> >> >
> >> > --
> >> > 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.
> >> >
> >>
> >> --
> >> 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.
> >>
> >
> > --
> > 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.
> >
>
> --
> 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.
>
>
--
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.