I am trying to write a unit test (NUnit) that will:
- Create an instance of some Form.
- Hook up the relevant AssemblyLoad event of the AppDomain to开发者_开发技巧 build a List of loaded assembly names.
- If the same assembly is loaded twice, fail.
- Otherwise - pass.
I cannot seem to get the logic for this... The test always passes.
Can this be done ?
It is hard to make your unit test fail. The CLR already makes sure that an assembly only gets loaded once. Pretty important, getting the same assembly loaded more than once produces very hard to diagnose casting errors at runtime.
You'd have to use the horrid Assembly.LoadFile() to trip a fail. Avoid testing things you should never do to begin with.
Once you load an assembly in the AppDomain, you cannot load it again and there doesn't appear to be an Assembly.Unload method either. Well, technically you can unload the assembly if you unload all of the AppDomains that loaded it.
精彩评论