Mocking ConnectionFactory

1,861 views
Skip to first unread message

Ben Joyce

unread,
Aug 7, 2014, 5:16:28 AM8/7/14
to rabbitm...@googlegroups.com
Hello.

I'm working with RabbitMQ in the .NET environment, using the classic RabbitMQ Client, and have run in to some trouble related to unit testing/mocking the ConnectionFactory.

ConnectionFactory doesn't derive from any interface which makes it a bit hard to mock as there doesn't seem to be a way to call CreateConnection without it actually trying to create an actual connection to the host.

Anyone been here and found a solution?  All I can do at the moment is to provide a mock of IConnection instead, meaning I have to new-up the connection outside of my class, injecting it via the constructor... I'd rather just have to provide a mock of ConnectionManager instead and let that provide the child objects (Connection, and then Model).

Hope that makes sense.  Any thoughts appreciated.

Ben

Michael Klishin

unread,
Aug 7, 2014, 6:03:47 AM8/7/14
to Ben Joyce, rabbitm...@googlegroups.com
Ben,

Yes, currently that's the optimal way. We can introduce an interface for connection factory in 3.4.0.

MK
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Joyce

unread,
Aug 7, 2014, 6:27:19 AM8/7/14
to rabbitm...@googlegroups.com, ben....@gmail.com, mic...@rabbitmq.com
Hi Michael.

Ok, thanks for getting back so quick and confirming the functionality/best practice.

Looking forward to 3.4.0 :)

Cheers,

Ben

Michael Klishin

unread,
Aug 7, 2014, 8:25:59 AM8/7/14
to rabbitm...@googlegroups.com, Ben Joyce
 On 7 August 2014 at 14:27:25, Ben Joyce (ben....@gmail.com) wrote:
> > Looking forward to 3.4.0 :)

Ben,

I've started putting together an interface and so far it has just
1 method:

IConnection CreateConnection();

I'll change some ConnectionFactory public fields to be properties (an appropriate
change for 3.4.0) and then what else may be required by the few library parts
that accept ConnectionFactory.

Anything else you'd like to see in the API?
--
MK

Staff Software Engineer, Pivotal/RabbitMQ

Michael Klishin

unread,
Aug 7, 2014, 11:19:25 AM8/7/14
to rabbitm...@googlegroups.com, Ben Joyce
On 7 August 2014 at 16:25:59, Michael Klishin (mic...@rabbitmq.com) wrote:
> > I've started putting together an interface

and here's what I ended up with:

http://hg.rabbitmq.com/rabbitmq-dotnet-client/rev/f240e2ddaa26 

Ben Joyce

unread,
Aug 8, 2014, 4:30:06 PM8/8/14
to Michael Klishin, rabbitm...@googlegroups.com
Hi Michael.  Again thanks for the speedy reply.

What you suggest sounds fine, at least for what I want to do in my unit testing.

Can't think of anything else at the mo.

Ben

Ben Joyce

unread,
Aug 8, 2014, 4:30:40 PM8/8/14
to Michael Klishin, rabbitm...@googlegroups.com
Great!

If you want me to test the interface let me know.

Ben

Michael Klishin

unread,
Aug 9, 2014, 12:00:33 AM8/9/14
to Ben Joyce, rabbitm...@googlegroups.com


On 9 August 2014 at 00:30:43, Ben Joyce (ben....@gmail.com) wrote:
> > If you want me to test the interface let me know.

That'd be helpful. Should be in the nightly builds already:
https://www.rabbitmq.com/nightly-builds.html
Reply all
Reply to author
Forward
0 new messages