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 ShimAssembly
like 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 it seems to be an unnecessary workaround. I'd prefer the official solution.
If it only worked like this:
var shimAsm = System.Reflection.Fakes.ShimAssembly.LoadFile = (fileName) =>
{
return ???
};
var types = shimAsm.GetTypes = () =>
{
return new Type[] { new object() };
};
Why does it work for System.IO.File
and not for System.Reflection.Assembly
. Is this because Assembly
is an abstract class?
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.