Can you not create two different instances of a mocked type???

9 views
Skip to first unread message

yesthatmcgurk

unread,
Sep 2, 2008, 2:27:55 PM9/2/08
to Moq Discussions
Am I going insane here?

var mock1 = new Mock<ILog>();
var mock2 = new Mock<ILog>();

var omg = object.ReferenceEquals(mock1.Object, mock2.Object)

Should omg be true or false? I would completely assume it should be
false, but just recently I noticed that I was getting the same mock
object (omg would be true).

Is this design? Is there something weird going on? And what do I do
when I want two different instances of the same mocked object?

Daniel Cazzulino

unread,
Sep 2, 2008, 2:38:47 PM9/2/08
to moq...@googlegroups.com
This passes with the current version of Moq:

        [Fact]
        public void GetsTwoDifferentMocks()
        {
            var mock1 = new Mock<IFoo>();
            var mock2 = new Mock<IFoo>();

            var omg = object.ReferenceEquals(mock1.Object, mock2.Object);

            Assert.False(omg);

yesthatmcgurk

unread,
Sep 2, 2008, 2:41:05 PM9/2/08
to Moq Discussions
I'm using version 2.5.1.153, and it would fail. What is the "current"
version?
> > when I want two different instances of the same mocked object?- Hide quoted text -
>
> - Show quoted text -

yesthatmcgurk

unread,
Sep 2, 2008, 2:42:31 PM9/2/08
to Moq Discussions
Okay, ignore that. I'm an idiot.
> > - Show quoted text -- Hide quoted text -

Daniel Cazzulino

unread,
Sep 2, 2008, 3:06:26 PM9/2/08
to moq...@googlegroups.com
latest on the site: http://code.google.com/p/moq/

is 2.5.3

and it passes. I can't think of a reason why it wouldn't be the same case with previous versions...

yesthatmcgurk

unread,
Sep 3, 2008, 10:34:00 AM9/3/08
to Moq Discussions
My bad. I was discombobulated over an unrelated MoQ issue (see the
post about unregistering events) and was looking at the type name,
thinking that because the two mocks had the same type name that they
were the same instance. I'm an idiot.

On Sep 2, 3:06 pm, "Daniel Cazzulino" <dan...@cazzulino.com> wrote:
> latest on the site:http://code.google.com/p/moq/
>
> is 2.5.3
>
> and it passes. I can't think of a reason why it wouldn't be the same case
> with previous versions...
>
> On Tue, Sep 2, 2008 at 3:41 PM, yesthatmcgurk <yesthatmcg...@gmail.com>wrote:
>
>
>
>
>
> > I'm using version 2.5.1.153, and it would fail.  What is the "current"
> > version?
>
> > On Sep 2, 2:38 pm, "Daniel Cazzulino" <dan...@cazzulino.com> wrote:
> > > This passes with the current version of Moq:
>
> > >         [Fact]
> > >         public void GetsTwoDifferentMocks()
> > >         {
> > >             var mock1 = new Mock<IFoo>();
> > >             var mock2 = new Mock<IFoo>();
>
> > >             var omg = object.ReferenceEquals(mock1.Object, mock2.Object);
>
> > >             Assert.False(omg);
> > >         }
>
> > > On Tue, Sep 2, 2008 at 3:27 PM, yesthatmcgurk <yesthatmcg...@gmail.com
> > >wrote:
>
> > > > Am I going insane here?
>
> > > > var mock1 = new Mock<ILog>();
> > > > var mock2 = new Mock<ILog>();
>
> > > > var omg = object.ReferenceEquals(mock1.Object, mock2.Object)
>
> > > > Should omg be true or false?  I would completely assume it should be
> > > > false, but just recently I noticed that I was getting the same mock
> > > > object (omg would be true).
>
> > > > Is this design?  Is there something weird going on?  And what do I do
> > > > when I want two different instances of the same mocked object?- Hide
> > quoted text -
>
> > > - Show quoted text -- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages