comments for kzu @ http://haacked.com/archive/2009/09/29/moq-sequences.aspx

1 view
Skip to first unread message

gerry_lowry (alliston ontario canada (705) 250-0112)

unread,
Nov 20, 2009, 3:00:17 PM11/20/09
to moq...@googlegroups.com
http://haacked.com/archive/2009/09/29/moq-sequences.aspx

three of the four last comments (as of a few minutes ago) seem to be addressed
implicitly to Daniel a.k.a. kzu ... one of the comments is explicitly addressed to Daniel.

just curious ... any plans to implement sequencing "out of the box"
to use Roy Osherove's phrase? (sixth last comment at above link).


Gerry

Daniel Cazzulino

unread,
Nov 20, 2009, 3:13:06 PM11/20/09
to moq...@googlegroups.com
Sounds fair. The last comment is the best IMO.
What if you could sequence just by calling .Returns (or .Throws) more than once? So we'd have overwrite behavior for the first call to .Returns, but not successive ones:

mock.Setup(x => x.Do()).Returns(2);
// overwrites the previous one, current behavior:
mock.Setup(x => x.Do()).Returns(5);

// sequencing
mock.Setup(x => x.Do())
        .Returns(2)
        .Returns(3)
        .Throws<InvalidOperationException>();

I do like the shortcut for returning many values in order:

// essencially the same as above call
mock.Setup(x => x.Do())
        .Returns(2, 3)
        .Throws<InvalidOperationException>();

Not sure if a simple overload receiving T, params T[] sequence, is OK or if a more explicit method name such as ReturnsOrdered is better... thoughts?


/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471


Jason Jarrett

unread,
Nov 20, 2009, 4:43:26 PM11/20/09
to moq...@googlegroups.com
This may be a little too verbose, but I do like the readability with the "dot" syntax.

mock.Setup(x => x.Do())
        .Returns(2)
        .AndThenReturns(3)
        .AndThenReturns(4)
        .AndThenThrows<InvalidOperationException>();

Daniel Cazzulino

unread,
Nov 20, 2009, 6:17:55 PM11/20/09
to moq...@googlegroups.com
there's no need for the "AndThen", IMO. The fact that you're chaining it after the previous call should be enough indication that it's an "andthen", just like .Setup().Callback().Returns().Callback() works

makes sense?


/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471


Andrew Kazyrevich

unread,
Nov 20, 2009, 6:24:06 PM11/20/09
to moq...@googlegroups.com
mock.Setup(x => x.Do())
        .Returns(2)
        .Returns(3)
        .Throws<InvalidOperationException>();

This sounds really neat. Surely no need for "AndThen" etc.


The second one with params - "mock.Setup(x => x.Do()).Returns(2, 5, 10)" feels more confusing and anyway if the last call should throw or whatever, we still have to use ".Throws" etc.


Daniel Cazzulino

unread,
Nov 20, 2009, 6:35:10 PM11/20/09
to moq...@googlegroups.com
yup, more explicit is better IMO.


/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471


Jason Jarrett

unread,
Nov 20, 2009, 8:08:09 PM11/20/09
to moq...@googlegroups.com
+1 for the feature. 

I do like the consistency of the below...

mock.Setup(x => x.Do())
        .Returns(2)
        .Returns(3)
        .Throws<InvalidOperationException>();


Ben Taylor UK

unread,
Nov 21, 2009, 5:50:53 AM11/21/09
to Moq Discussions
Another +1 for the feature.

I also like:

mock.Setup(x => x.Do())
.Returns(2)
.Returns(3)
.Throws<InvalidOperationException>();


On Nov 21, 1:08 am, Jason Jarrett <sta...@gmail.com> wrote:
> +1 for the feature.
>
> I do like the consistency of the below...
>
> mock.Setup(x => x.Do())
>         .Returns(2)
>         .Returns(3)
>         .Throws<InvalidOperationException>();
>
> On Fri, Nov 20, 2009 at 3:35 PM, Daniel Cazzulino <k...@clariusconsulting.net
>
> > wrote:
> > yup, more explicit is better IMO.
>
> > /kzu
>
> > --
> > Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1
> > 425.329.3471
>
> >>>>> (705) 250-0112) <gerry.lo...@abilitybusinesscomputerservices.com>wrote:
Reply all
Reply to author
Forward
0 new messages