vendredi 20 février 2015

How can I fake Assembly.LoadFile and Assembly.GetTypes?

I'm struggling to fake these two lines of code:



Assembly asm = Assembly.LoadFile(fileName);
Type[] asmTypes = loggerAssembly.GetTypes();


When I type System.Reflection.ShimAssembly there is no such type as similar for example in the case of System.IO.ShimFile but only a StubAssembly.


I could refactor the code and do it with a static helper method like LoadAssemblyAndGetTypes but I don't like this solution.


Why does it work for System.IO.File and not for System.Reflection.Assembly. Is this because Assembly is an abstract class?


I also didn't have luck with this:



System.Reflection.Fakes.StubAssembly.LoadFile(string.Empty) = (fileName) => { };


so I don't know what else I could try.




In my unit test I want to check if my assembly loader correctly checks if the loaded assembly contains types that implement some interfaces so that I can instantiate them later later.


Aucun commentaire:

Enregistrer un commentaire