title: How to mock MQ-Series object MQQueueManager with MOQ for .NET?
body: <p>I am trying to unit test the MQ-Series implementation of my project, and need to mock the connection to the MQ-Series server to test my implementation isolated and avoid sending messages/retrieving messages from the actual queue.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>using IBM.WMQ;
  using Microsoft.VisualStudio.TestTools.UnitTesting;
  using Moq;
  
  namespace Test
  {
      [TestClass]
      public class MQTest
      {
          [TestMethod]
          public void SendMessage_MoqUnitTest()
          {
              //create a mock MQ manager
              var mqManMock = new Mock&lt;MQQueueManager&gt;();
  
              //test by calling the send method
              MyMQhandler.MQSender mqsender = new MyMQhandler.MQSender();
              //error happens when trying to access the moq object here
              mqsender.Send("test message", mqManMock.Object); 
          }
      }
  }
  </code></pre>
  
  <p>I am aware that I am not doing any setup on the moq yet, but the problem appears before any code is actually run against it.</p>
  
  <p>The problem is that when I do this I get an exception.
  Stack trace from the inner exception with message "I/O error occurred":</p>
  
  <p><em>at IBM.WMQ.MQChannelTable.CreateChannelEntryLists(MQChannelListEntry nameList)
     at IBM.WMQ.Nmqi.ManagedNmqiMQ.CreateNameListEntryFromCCDT(String qMgrName, String ccdtFile)
     at IBM.WMQ.Nmqi.ManagedNmqiMQ.CreateNameListEntryFromCCDT(String qMgrName)
     at IBM.WMQ.Nmqi.ManagedNmqiMQ.GetNameList(String qMgrName)
     at IBM.WMQ.Nmqi.ManagedNmqiMQ.DoConn(String qMgrName, MQConnectOptions cno, ManagedHconn manHconn, Int32&amp; hConn, Int32&amp; compCode, Int32&amp; reason)
     at IBM.WMQ.Nmqi.ManagedNmqiMQ.MQCONNX(String pQMgrName, MQConnectOptions pConnectOpts, Phconn phconn, Int32&amp; pCompCode, Int32&amp; pReason)
     at IBM.WMQ.MQQueueManager.Connect(String queueManagerName)
     at IBM.WMQ.MQQueueManager..ctor()
     at Castle.Proxies.MQQueueManagerProxy..ctor(IInterceptor[] )</em></p>
  
  <p>Most of the time I run it though I just get "Function evaluation timed out" og the MQManMock.Object.</p>
  
  <p>Does this mean that I can't mock the MQ??</p>