chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
I'm getting a nullreferenceexception when I call Assembly.GetEntryAssembly().Location in my SUT. Is there a way to avoid the exception and to set the Environment.CurrentDirectory = "C:\\temp"? Note that Environment.CurrentDirectory, Path.GetDirectoryName are statics. Assembly.GetEntryAssembly() is a static method.

public class A 
{
  public void method_1() 
  { 
    this.method_2();
  }
  
  public void method_2() 
  {
     Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
  }
}

[TestClass]
public class MyTestClass
{

  [Isolated]
  [TestMethod]
  public void MyTestMethod()
  {
    // ????? <some code here to avoid calling: Assembly.GetEntryAssembly() because it returns null>

    new A().method_1();
  } 
asked by paul.connor (6.1k points)

2 Answers

0 votes
  [TestMethod,Isolated]
  public void MyTestMethod()
  {
   var sut = new A();
   Isolate.WhenCalled(()=>sut.MethodB()).IgnoreCall();

   sut.MethodA();
  }
 
answered by itaf (180 points)
0 votes
  [TestMethod,Isolated]
  public void MyTestMethod()
  {
   var sut = new A();
   Isolate.WhenCalled(()=>sut.MethodB()).IgnoreCall();

   sut.MethodA();
  }
 
answered by itaf (180 points)
...