Bla*_*asp 4 .net c# tdd rhino-mocks exception
我在RhinoMocks中使用模拟对象来表示调用MessageQueue.GetPublicQueues的类.我想模拟消息队列在工作组模式下运行时引发的异常,这是一个MessageQueueException,以确保我正确捕获异常
MessageQueueException没有公共构造函数,只有异常的标准受保护构造函数.是否有适当的方法从mock对象/ Expect.Call语句中抛出此异常?
反思可以破坏可访问性规则.您将使保修失效,.NET更新可能会轻易破坏您的代码.试试这个:
using System.Reflection;
using System.Messaging;
...
Type t = typeof(MessageQueueException);
ConstructorInfo ci = t.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance,
null, new Type[] { typeof(int) }, null);
MessageQueueException ex = (MessageQueueException)ci.Invoke(new object[] { 911 });
throw ex;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
812 次 |
| 最近记录: |