Question

I’m trying to implement on a very big and bloating system a framework to use unit testing, the main problem is that 70% of the system is implemented with static methods. Is how I’ve reached Moles, and I’m very confident that I will reach my goal (I’m quite near).

The problem I have right now is that I’m trying to mole a static method with a Generic Parameter:

public static T ExecScalar<T>(IDbConnection cx, string commandText, IDbTransaction tx, IEnumerable<IDbDataParameter> parameters)

googling on the web I’ve found this forum message:

http://social.msdn.microsoft.com/Forums/uk/pex/thread/3faadca2-a26f-449c-942e-d800a6079e02

that is exactly my problem, and there is suggested to read the manual at page 10.

I’ve read the manual at page 10, but it’s talking about stubbing and not molling. I ‘ve tried to apply the described solution but if I put:

Ktcar.Cs.Dal.DB.Moles.MDALDB.ExecScalarIDbConnectionStringIDbTransactionIEnumerableOfIDbDataParameter<int> = delegate(IDbConnection conn, String command, IDbTransaction trx, IEnumerable<IDbDataParameter> parameters)

I get:

“Only assignment, call, increment, decrement, and new object expressions can be used as a statement”

I have also tried:

Ktcar.Cs.Dal.DB.Moles.MDALDB.ExecScalarIDbConnectionStringIDbTransactionIEnumerableOfIDbDataParameter<T> = delegate(IDbConnection conn, String command, IDbTransaction trx, IEnumerable<IDbDataParameter> parameters)

And I get the same error

Or:

Ktcar.Cs.Dal.DB.Moles.MDALDB.ExecScalarIDbConnectionStringIDbTransactionIEnumerableOfIDbDataParameter = null;

And then I get:

“Cannot assign to 'ExecScalarIDbConnectionStringIDbTransactionIEnumerableOfIDbDataParameter' because it is a 'method group'”

please, can anyone helpme on how to mock a static method with Generic Type output?

Was it helpful?

Solution

Try this one:

Ktcar.Cs.Dal.DB.Moles.MDALDB.ExecScalarIDbConnectionStringIDbTransactionIEnumera‌​bleOfIDbDataParameter<int>((IDbConnection conn, String command, IDbTransaction trx, IEnumerable<IDbDataParameter> parameters) => { return 5; }); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top