c# - unit testing a method that uses Assembly -


i need unit xunit test method uses assembly, called parameter assembly.getentryassembly().

but unfortunately in unit test project, entry assembly appears testhost not test project. way i'll not able search test project.does mean won't able test method? or way go?

not code should tested. extract code use assembly.getentryassembly() separate component, this:

public interface iassemblyprovider {       assembly getentryassembly(); }  public class assemlbyprovider : iassemblyprovider {       public assembly getentryassembly()       {            return assembly.getentryassembly();       } } 

and use abstraction in code. no need test single method - know works, part of .net framework. code you'd test should consume iassemblyprovider, can substitute stub:

// should visible in test project internal class stubassemlbyprovider : iassemblyprovider {       public assembly getentryassembly()       {            return typeof(myclassinentryassembly).assembly;       } } 

this way code tested, not testing .net framework code.


Comments