开发者

How do I create an instance of Oracle.DataAccess.Client.OracleException to use with NMock

I'm using the Oracle.DataAccess.Client data provider client. I am having trouble constructing a new instance of an OracleException object, but it keeps telling me that there are no public constructors. I saw other having the same problem and tried their solu开发者_如何学编程tions, but they don't seem to work. Here's my test code:

object[] args = { 1, "Test Message" };
ConstructorInfo ci = typeof(OracleException).GetConstructor(BindingFlags.NonPublic 
     | BindingFlags.Instance, null, System.Type.GetTypeArray(args), null);
var e = (OracleException)ci.Invoke(args);

When debugging the test code, I always get a NULL value for 'ci'.

Has Oracle changed the library to not allow this? What am I doing wrong and what do I need to do to instantiate an OracleException object to use with NMock?

By the way, I'm using the Client library for version 10g.

Thanks,

Charlie


OracleException in ODP.NET not the same as OracleException in Microsoft client. OracleException have 5 constructors information of which you can obtain by GetConstructors().

In the obtained list of the constructors you will see that there are no constructor with parameters (int, string). That why you getting NULL in ci.

If you give a proper list of the parameters you will have proper ConstructorInfo and will be able to call a constructor by Invoke(param);

However, OracleException constructor not designed to be called like this - not all the fields will have a proper information.

2All: I need following OracleException: ORA-00001 unique constraint (string.string) violated ORA-03113 end-of-file on communication channel ORA-03135: connection lost contact ORA-12170: TNS: Connect timeout occurred for testing. How do I create them?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜