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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I have a test where I need to mock all instances of a classe being created in the tested code.

How can I do this?
asked by paulo.morgado (11k points)

2 Answers

0 votes
Paulo hi,

You can use the MockAll method in order to mock all instances created from a given type.

Mock mock = MockManager.MockAll(typeof(SomeType));


:idea: a lot of cool stuff can be found in our cheat sheets: https://www.typemock.com/Docs/CheatSheets.html
answered by lior (13.2k points)
0 votes
Hi lior,

I was probably missing a good night sleep or some coffe, because now it works.

Even better, I can now do this:

using (RecordExpectations recorder = RecorderManager.StartRecording())
{
  global::Esi.FlexView.PL.Web.Security.Principal.RolePrincipal user = new global::Esi.FlexView.PL.Web.Security.Principal.RolePrincipal(flexViewIdentity);
  recorder.CheckArguments();
  recorder.ExpectAndReturn(user.Identity, flexViewIdentity).RepeatAlways();
}
answered by paulo.morgado (11k points)
...