chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Which enterprise feature am I trying to use here:
TacticalLayer _tlDummy = (TacticalLayer)m_tld.MockedInstance.Layers[0];
recorder.Return(tl);
//tl is created as a regular object.


I presume it is the natural mocks chaining.

How do I work around this?

I need to get a fake object from the iterator for the Layers. Unfortunately I only have a pro license...

Regards
Laro
asked by Larovia (3.8k points)

3 Answers

0 votes
Hi
It is indeed the chaining.
The work around is simple. Just break the chain into separate statements

SomeObject obj = m_tld.MockedInstance as SomeObject;
recorder.Return(someReturnValue);
TacticalLayer _tlDummy = (TacticalLayer)obj.Layers[0];
recorder.Return(tl);


I don't know what should be the type conversion of m_tld.MockedInstance so just replace the conversion to the correct type in your code.
answered by ohad (35.4k points)
0 votes
The problem is a bit more complex...

foreach (TacticalLayer currentLayer in situation.TacticalLayersDictionary.Layers)
            {


situation and all inside is to be mocked, I just need an object (of my creation) to be returned as the first item, so that the currentLayer is the object I have created before starting the expectation recording.

/Laro
answered by Larovia (3.8k points)
0 votes
Hi,

how about just mocking the call to Layers and returning from it a fake collection containing only one elemnt that you initialize at the start of the test?

something like:
List<TacticalLayer> fakeList = new List<TacticalLayer>();
fakeList.Add(dummyLayer);
...
...
answered by lior (13.2k points)
...