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
Hi - a method I am trying to test uses AppDomain.CurrentDomain.GetAssemblies().

Is it possible to mock the return value from this call - so I can affect the execution of the method I am testing, which performs different actions depending on the Assembly information it receives.

Thanks, Peter
asked by xdzgor (3.3k points)

1 Answer

0 votes

AppDomain class belongs to mscorlib and not all types from the assembly are fakeable. As a solution you can use a static wrapper which will be faked in the tests.

For example:
public class AppDomainWrapper
    public static IEnumerable<Assembly> GetAssemblies()
       return AppDomain.CurrentDomain.GetAssemblies();

In the production code you can call this method without any functionality change and in the tests fake the static wrapper method.

Typemock Support
answered by Elisha (12k points)