Domanda

foreach (BeamCluster cluster in executionContext.RevitModel.Beams
                                .Where(b => b.Walls.Values
                                                   .Contains(executionContext.Frame.Wall)))
        {

Given the piece of code above how would I go about feeding information into the IEnumerable using type mock so that I am able to use fakes for the beams, frames, and walls as well?

Beams is a dictionary.

executionContext is of type TooLongContext

TooLongContext context = Isolate.Fake.Instance<TooLongContext>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => context.RevitModel.Beams).ReturnRecursiveFake();

After this I am confused (maybe I am confused before this :))

È stato utile?

Soluzione

You need to create an IEnumerable of beams and walls, etc. on your own first. Typemock (and other mock frameworks) don't autogenerate useful data. When you have them return recursive fakes, all it will do is attempt to make sure nothing is ever returned with null (usually by returning default values for everything). That only prevents null references exceptions, and it's not that useful for a lot of test cases.

So all you need to do is change what your context returns.

var myFakeBeams = new List<Beam>();
//Add a bunch of fake beams
Isolate.WhenCalled(() => context.RevitModel.Beams).WillReturn(myFakeBeams);

And so on for the other types.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top