Moq'ing complex objects

1,394 views
Skip to first unread message

Andrew Ryan

unread,
Jan 12, 2010, 4:06:49 PM1/12/10
to Moq Discussions
I have a class with a method that calls out with
Dictionary<string,string> like:

<code>

public class Foo
{
public void Execute( string name, Dictionary<string,string props>
();
}

</code>

The props is complex class that uses reference equality, and I don't
have access to the actual object (it's buried deep in code). However,
I want to test that the method Execute to see if it ran, not caring
what the value of props is.

How do I do this?

Chris Missal

unread,
Jan 12, 2010, 5:36:27 PM1/12/10
to moq...@googlegroups.com
try your code similar to this:
mock.Setup(x => x.Execute(It.IsAny<Dictionary<string, string>>()))
</untested> :)






--
Chris Missal
http://chrismissal.lostechies.com/

Emanuele DelBono

unread,
Jan 13, 2010, 3:24:25 AM1/13/10
to moq...@googlegroups.com
A little modification on Chris's code:

mock.Verify(x => x.Execute(It.IsAny<String>(),
It.IsAny<Dictionary<string, string>>()));

ema
http://blog.codiceplastico.com

Andrew Ryan

unread,
Jan 13, 2010, 2:35:07 PM1/13/10
to Moq Discussions
Very, VERY nice... this is the hotness....

On Jan 13, 3:24 am, Emanuele DelBono <codiceplast...@gmail.com> wrote:
> A little modification on Chris's code:
>
> mock.Verify(x => x.Execute(It.IsAny<String>(),
> It.IsAny<Dictionary<string, string>>()));
>

> emahttp://blog.codiceplastico.com


>
>
>
> On Tue, Jan 12, 2010 at 10:06 PM, Andrew Ryan <andrew1...@gmail.com> wrote:
> > I have a class with a method that calls out with
> > Dictionary<string,string> like:
>
> > <code>
>
> > public class Foo
> > {
> >    public void Execute( string name, Dictionary<string,string props>
> > ();
> > }
>
> > </code>
>
> > The props is  complex class that uses reference equality, and I don't
> > have access to the actual object (it's buried deep in code). However,
> > I want to test that the method Execute to see if it ran, not caring
> > what the value of props is.
>
> > How do I do this?
>
> > --
> > Post: moq...@googlegroups.com

> > Unsubscribe: moqdisc-u...@googlegroups.com- Hide quoted text -
>
> - Show quoted text -

Reply all
Reply to author
Forward
0 new messages