title: .NET Core how to unit test service?
body: <p>I have build a WebAPI and want to create a unit test project to have my services tested automatically.</p>
  
  <p>The flow of my WebAPI is simple:</p>
  
  <p>Controller (DI Service) -> Service (DI Repository) -> _repo CRUD</p>
  
  <p>Suppose I have a service like:</p>
  
  <pre><code>public int Cancel(string id) //change status filed to 'n'
  {
      var item = _repo.Find(id);
      item.status = "n";
      _repo.Update(item);
      return _repo.SaveChanges();
  }
  </code></pre>
  
  <p>And I want to build a unit test, which just use InMemoryDatabase.</p>
  
  <pre><code>public void Cancel_StatusShouldBeN() //Testing Cancel() method of a service
  {
      _service.Insert(item); 
  
      int rs = _service.Cancel(item.Id);
      Assert.Equal(1, rs);
  
      item = _service.GetByid(item.Id);
      Assert.Equal("n", item.status);
  }
  </code></pre>
  
  <p>I've searched other related question, found that </p>
  
  <blockquote>
    <p>You can't use dependency injections on test classes.</p>
  </blockquote>
  
  <p>I just want to know if there is any other solution to achive my unit test idea?</p>