Note that there are some explanatory texts on larger screens.

plurals
  1. POMolling static method with generic return type <T>
    primarykey
    data
    text
    <p>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).</p> <p>The problem I have right now is that I’m trying to mole a static method with a Generic Parameter:</p> <pre><code>public static T ExecScalar&lt;T&gt;(IDbConnection cx, string commandText, IDbTransaction tx, IEnumerable&lt;IDbDataParameter&gt; parameters) </code></pre> <p>googling on the web I’ve found this forum message:</p> <p><a href="http://social.msdn.microsoft.com/Forums/uk/pex/thread/3faadca2-a26f-449c-942e-d800a6079e02" rel="nofollow">http://social.msdn.microsoft.com/Forums/uk/pex/thread/3faadca2-a26f-449c-942e-d800a6079e02</a></p> <p>that is exactly my problem, and there is suggested to read the manual at page 10.</p> <p>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:</p> <pre><code>Ktcar.Cs.Dal.DB.Moles.MDALDB.ExecScalarIDbConnectionStringIDbTransactionIEnumerableOfIDbDataParameter&lt;int&gt; = delegate(IDbConnection conn, String command, IDbTransaction trx, IEnumerable&lt;IDbDataParameter&gt; parameters) </code></pre> <p>I get:</p> <p>“Only assignment, call, increment, decrement, and new object expressions can be used as a statement”</p> <p>I have also tried:</p> <pre><code>Ktcar.Cs.Dal.DB.Moles.MDALDB.ExecScalarIDbConnectionStringIDbTransactionIEnumerableOfIDbDataParameter&lt;T&gt; = delegate(IDbConnection conn, String command, IDbTransaction trx, IEnumerable&lt;IDbDataParameter&gt; parameters) </code></pre> <p>And I get the same error </p> <p>Or:</p> <pre><code>Ktcar.Cs.Dal.DB.Moles.MDALDB.ExecScalarIDbConnectionStringIDbTransactionIEnumerableOfIDbDataParameter = null; </code></pre> <p>And then I get:</p> <p>“Cannot assign to 'ExecScalarIDbConnectionStringIDbTransactionIEnumerableOfIDbDataParameter' because it is a 'method group'”</p> <p>please, can anyone helpme on how to mock a static method with Generic Type output?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload