Mocking MSMQ
I searched how to mock the System.Messaging.MessageQueue class in order to unit test a project.
I tested some solutions and here is my choice :
First, I created an interface with defines the MessageQueue functions I would like to use.
Here is a simplified version with Send metohd in focus.
public interface IMessageQueue
{
void Send(object message);
}
For real implementation I use a wrapper class with the interface
public class RealMessageQueue : IMessageQueue
{
private System.Messaging.MessageQueue myQueue =
new System.Messaging.MessageQueue(@".\Private$\MyQueue");
public void Send(object message)
{
myQueue.Send(message);
}
}
I can now pass a mock object to my unit tests.