title: How to Write xUnit Test for .net core 2.0 Service that uses AutoMapper and Dependency Injection?
body: <p>I'm new to .net core/C# programming (coming over from Java)</p>
  <p>I have the following Service class the that uses dependency injection to get an AutoMapper object and a data repository object for use in creating a collection of SubmissionCategoryViewModel objects:</p>
  <pre><code>public class SubmissionCategoryService : ISubmissionCategoryService
  {
  
      private readonly IMapper _mapper;
  
      private readonly ISubmissionCategoryRepository _submissionCategoryRepository;
  
      public SubmissionCategoryService(IMapper mapper, ISubmissionCategoryRepository submissionCategoryRepository)
      {
  
          _mapper = mapper;
  
          _submissionCategoryRepository = submissionCategoryRepository;
  
      }
  
      public List&lt;SubmissionCategoryViewModel&gt; GetSubmissionCategories(int ConferenceId)
      {
  
  
          List&lt;SubmissionCategoryViewModel&gt; submissionCategoriesViewModelList = 
              _mapper.Map&lt;IEnumerable&lt;SubmissionCategory&gt;, List&lt;SubmissionCategoryViewModel&gt;&gt;(_submissionCategoryRepository.GetSubmissionCategories(ConferenceId) );
  
          return submissionCategoriesViewModelList;
  
  
      }
  }
  </code></pre>
  <p>I'm writing my unit tests using Xunit.  I cannot figure out how to write a unit test for method GetSubmissionCategories and have my test class supply an IMapper implementation and a ISubmissionCategoryRepository implementation.</p>
  <p>My research so far indicates that I could either create a test implementation of the dependent objects (e.g. SubmissionCategoryRepositoryForTesting) or I can use a mocking library to create a mock of the dependency interface.</p>
  <p>But I don't know how I would create a test instance of AutoMapper or a mock of AutoMapper.</p>