c# - How to modify an invocation parameter of a mocked method with Moq? -


Is it possible to modify an implantation parameter of a simulated method? Specifically I want to convert buffer to the prefixed byte array in the following example.

Example:
int MockedClass.Read (byte [] buffer, int offset, int count)

explanation:
calling Read load count bytes off by buffer in the byte array supplied.

Now I should have a buffer to call after calling read has been done in my application code, is this possible?

If so, how do I make frequent calls to read ?

Edit:

By using the setup command like this:

MockedClass.Setup (x = & gt; x.Read (this.This is another lieutenant; byte []> gt; (), this. Any of these & lt; int & gt; (), this. Lt; int & gt; ()). (Byte [] buffer, int offset, int calculation) => Buffer [0] = 0xAA);

When giving the unit test, I give a strange problem: Code> Read is created and the representative code ( buffer [0] = 0xAA ) The debugger shows that the buffer actually null and the unit test execution closes after executing this command. Is my syntax buffets or bugs?

You can use the callback method. Something like this (from memory):

  var buffer = new byte [64]; // mock.Setup (m = & gt; m .Read (buffer, offset, count)). Callback ((buffer, offset, count) = & gt; / * fill buffer here * /);  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -