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

Sometimes I know that the legacy code I'm using (and mocking) instantiates an object that I need to mock, but I don't know the class of this object, just the interface. For example, there might be some FooFactory:
IFoo FooFactory.CreateFoo(someparams) {...};

Actually, it can create some FooImpl object (where FooImpl is a well-hidden internal class), or create different objects depending on someparams. There are also cases when you have some abstract or even concrete class instead of IFoo here, but the object created is a descendant of this class, so TypeMock refuses to mock it. In any case, would be great to have it mocked.

By the way, can we mock objects created via Activator.CreateInstance?

Thanks for the great product!

asked by ulu (1.7k points)

1 Answer

0 votes
Ulu hi,

One strategy to bypass such a problem is to mock the call to FooFactory.CreateFoo itself, returning a prepared mocked interface. However, we will add this request to our list and see if this can be implemented as well.

TypeMock should be able to mock instances created using Activator.CreateInstance.
answered by lior (13.2k points)