--
Post: moq...@googlegroups.com
Unsubscribe: moqdisc-u...@googlegroups.com
var mock = Mock.Of<IFoo>(f => f.Do(It.IsAny<int>()) == Mock.Of<IBar>(b => b.IsCool == true));
:)
/kzu from galaxy tab
Ok, but what does it do? in this example
> var mock = Mock.Of<IFoo>(f => f.Do(It.IsAny<int>()) == Mock.Of<IBar>(b => b.IsCool == true));
I know `mock` will be of type IFoo. but I'm not sure what happens what happens when IFoo.Do(42) is called. I would assume it returns an IBar that has IsCool set to true, but it's really hard to tell.
On Mon, Apr 18, 2011 at 12:01, Tim Kellogg <timothy...@gmail.com> wrote:
And a follow up question... I see that Mock.Of takes a predicate expression. Why a predicate? what happens when the predicate returns true/false?Thanks,
Tim Kellogg
On Mon, Apr 18, 2011 at 8:49 AM, Tim Kellogg <timothy...@gmail.com> wrote:Damn...I'll have to read the docs more often. Thanks Daniel :)
Tim Kellogg
On Mon, Apr 18, 2011 at 8:46 AM, Daniel Cazzulino <kzu.net@gmail.com> wrote:
that's what Moq v4 already provides.the lambda expressions to Of allow you to recursively set any result and its properties/methods in turn too.in v4, Mock.Of<T> gives you a T, not a Mock<T>.this syntax is only used for setups, not verify (although that's also a good idea!)
On Mon, Apr 18, 2011 at 10:42, Tim Kellogg <timothy...@gmail.com> wrote:Daniel,In your emails yesterday, what did you mean by this?
> var mock = Mock.Of<IFoo>(f => f.Do(It.IsAny<int>()) == Mock.Of<IBar>(b => b.IsCool == true));
I didn't plan on adding setups to `.Of<>()` but it's not a bad idea. Can you describe what you had in mind when you wrote this?I have a couple issues with it's implications. (1) it implies we might be doing either setups or verifications from `Of`. (2) I can't think of a way to do both setups and verifications from the same method, so you need to decide what you meant. I don't have a problem with doing shorthand operations, but we need to decide what the requirements are. (3) you use the == operator on a Mock<> object (you would normally do `Mock.Of<IBar>(b => b.IsCool == true).Object`, so this might have been a confusing example).
Tim Kellogg
I imagine you know, but Resharper's code cleanup is completely
configurable. If that's a feature you want I'd just recommend that you
create a code cleanup profile for your tests that doesn't have that
cleanup behavior. And, if you really wanted, you could even create a
pattern so that R# suggests you add a '== <bool>' when called from
Mock.Of<>(). Similarly, you could disable the default warning and
create two patterns, one that suggest you remove it in normal code and
one that recommends it within Mock.Of.
--Kaleb
var foo = Mock.Of<IFoo>(x => x.MethodReturningBool());
or for false:
var foo = Mock.Of<IFoo>(x => !x.MethodReturningBool());
And the right way to do the verify is exactly what you put:
Mock.Get(somethingCreatedWithMockOf).Verify(foo => foo.Execute("ping"));
--
Post: moq...@googlegroups.com
Unsubscribe: moqdisc-u...@googlegroups.com