How do i unit test a class that uses IoC container classes

Viewed 4604

I am using Autofac in my project,but i am unable to do a unit test on one particular class.

Consider the following Scenario :

//Class to be tested
public Class A
{
  private SomeAutoFacClass B;

  public void DoSomething()
  {
    B = scope.Resolve<ClassName>();// Resolve the object needed 
    // Do something with instance B
  }
}

// Test class
public Class ATest
{
  private A a;

  [test]
  public void TestMethod()
  {
    a.DoSomething();//*This method causes a null reference exception as it tries to resolve the objects*
  }
}

In the code above,i am not able to unit test case due to the dependency injection which is only specific to that particular class. how do i solve this? I also tried creating a autofaccontainer using Moq. But that too fails.

2 Answers
Related