You could do something like this with Rhino Mocks: Encapsulate the Assembly.GetEntryAssembly() call into a class with interface IAssemblyLoader and inject it into the class your are testing. This is not tested but something along the lines of this:
[Test] public void TestSomething() {
// arrange
var stubbedAssemblyLoader = MockRepository.GenerateStub<IAssemblyLoader>();
stubbedAssemblyLoader.Stub(x => x.GetEntryAssembly()).Return(Assembly.LoadFrom("assemblyFile"));
// act
var myClassUnderTest = new MyClassUnderTest(stubbedAssemblyLoader);
var result = myClassUnderTest.MethodToTest();
// assert
Assert.AreEqual("expected result", result);
}
public interface IAssemblyLoader {
Assembly GetEntryAssembly();
}
public class AssemblyLoader : IAssemblyLoader {
public Assembly GetEntryAssembly() {
return Assembly.GetEntryAssembly();
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…