So the basic problem here is that you have a hard dependency on the MessageQueue object. Generally when I have a situation like this, I'll create an interface, like IQueue and then create an implementation of IQueue for MessageQueue.
Then you can inject the IQueue dependency with Moq and test that your class is functioning as expected.
Something like this:
public interface IQueue
{
bool Exists(string path);
MessageQueue Create(string path);
}
The implementation would be something like this:
public MessageQueueImplementation : IQueue
{
public bool Exists(string path)
{
return MessageQueue.Exists(path);
}
public MessageQueue Create(string path)
{
return MessageQueue.Create(path);
}
}
Then for your class that depends on the MessageQueue something like this:
public class DependentOnQueue
{
private IQueue queue;
//inject dependency
public DependentOnQueue(IQueue queue)
{
this.queue = queue;
}
public MessageQueue CreateQueue(string path)
{
//implement method that you want to test here
}
}
Now you can inject an IQueue object using moq into this class that depends on the MessageQueue object and test the functionality.