I seem now to be managing to mock the indexed properties :)
I'm now having problems with expectations - it may just be my misunderstanding though. Here is the core code that creates the mocked object:
private FinancialInstrument MockedFI(String Name)
{
FinancialInstrument MockedFI = (FinancialInstrument)RecorderManager.CreateMockedObject(typeof(FinancialInstrument));
using (RecordExpectations recorder = new RecordExpectations())
{
string s = MockedFI.Name;
recorder.Return(Name).RepeatAlways();
Double x = MockedFI.Price[0];
recorder.Return(1.0).RepeatAlways();
bool b = MockedFI.HasMatured(0);
recorder.Return(true).RepeatAlways();
}
return MockedFI;
}
I create 9 mocked objects, 3 in 3 arrays then as a test, I run over each one to see if it returns 1.0;
[Test]
[VerifyMocks]
public void TestAppropriateRebalancerCreated()
{
foreach(AssetCollection c in this.TestScheme.AssetPortfoliosModel)
{
for(int i=1; i < c.assetHoldings.Length; i++)
{
Assert.AreEqual(c.assets[i].Price[0], 1.0);
//Double x = c.assetHoldings[i] / c.assets[i].Price[0];
}
}
}
This gives:
TypeMock.VerifyException:
TypeMock Verification: Method Models.FinancialInstrument.get_Price() has 1 more expected calls
Method Models.FinancialInstrument.get_Price() has 1 more expected calls
Method Models.FinancialInstrument.get_Price() has 1 more expected calls
at TypeMock.MockManager.Verify()
When I uncomment the Double x - .../... I get:
TypeMock.VerifyException:
TypeMock Verification: Unexpected Call to Models.FinancialInstrument.get_Price()
at TypeMock.Mock.a(String A_0, Object[] A_1, Object A_2, Object A_3, Int32 A_4, Boolean& A_5, String A_6)
I don't understand why. I'm using Return(...).RepeatAlways so why in the first case is TypeMock expecting more calls when it has no idea how many there will be? The second case is similar - why does it think that more calls are unexpected?
Is there a long explanation of how expectations work? (I've looked at the code examples, the tutorial examples and the help reference but I am guessing at how it works and I need a proper explanation - I may be wrong in my guess.)