I am trying to test the following method for the case where 'the 
dataRequestCommand' is executed twice. 

/// <summary> 
/// Gets the peripheral data. 
/// </summary> 
/// <param name="dataRequestCommand">The data request command.</param> 
/// <returns>The data received from the peripheral.</returns> 
public virtual IList<byte> 
GetPeripheralData(PeripheralDataRequestCommanddataRequestCommand) 
{ 
int status; 
byte *dataLength*; 
IList<byte> data; 
dataRequestCommand.Invoke(out status, out *dataLength*, out data); 
if (*dataLength* == 0) 
{ 
Thread.Sleep(this.PeripheralDataRetrievalWaitTime); 
dataRequestCommand.Invoke(out status, out *dataLength*, out data); 
} 

return data; 
} 

Currently my unit test looks as follows: 

/// <summary> 
/// Tests GetPeripheralData() with no data on first call. 
/// </summary> 
[Test] 
public void 
TestGetPeripheraldataWithNoDataOnFirstCallExpectCalledTwiceAndDataReturn() 
{ 
// arrange 
var firstGet = MockRepository.GenerateStub<FirmwareCommandProcessor.
PeripheralDataRequestCommand>(); 
var secondGet = MockRepository.GenerateStub<FirmwareCommandProcessor.
PeripheralDataRequestCommand>(); 
IList<byte> *data*; 
byte *length*; 
int *callStatus*; 
firstGet 
.Expect(g => g.Invoke(out *callStatus*, out *length*, out *data*)) 
.OutRef(0, (byte)0, new List<byte>()) 
.Repeat.Once(); 
int *secondStatus*; 
byte *secondLength*; 
IList<byte> *secondData*; 
secondGet 
.Expect(g => g.Invoke(out *secondStatus*, out *secondLength*, out *
secondData*)) 
.OutRef(0, (byte)2, new List<byte> { 1, 2 }) 
.Repeat.Once(); 

// act 
var result = this.commandProcessor.GetPeripheralData(firstGet); 

// assert 
firstGet.VerifyAllExpectations(); 
secondGet.VerifyAllExpectations(); 
//// NOTE: need to determine how to capture the output on the second call. 
//// Rhino mocks returns first call values as the test is currently written. 
////Assert.IsNotNull(result); 
////Assert.IsInstanceOf<IList<byte>>(result); 
////var output = result as IList<byte>; 
////Assert.AreEqual(2, output.Count); 
////Assert.AreEqual(1, output[0]); 
////Assert.AreEqual(2, output[1]); 
} 

Ideally I would like accomplish this with a single mock object for 
FirmwareCommandProcessor.peripheralDataRequestCommand. I have not been able 
to figure out how to change the OutRef parameters of 0, (byte)0, and new 
List<byte> used for the first call to 0, (byte)2, new List<byte> { 1, 2 } 
in the second call. So I'm asking, first, if this is even possible. If it 
is, how would I do it? 

Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rhinomocks.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to