title: C# WebApi Unit Testing and Mocking Controllers
body: <p>I am working on this WebAPI project and I need to create unit tests for it. The base of the project was created using VS 2010 , and then an WebApi Module was added.</p>
  
  <p>The workings of the controller are kinda getting in the way of testing/mocking. I am using xUnit and Moq , but there is absolutely no need to stick with those two.</p>
  
  <p>The application uses specific objects to deal with database access, so I have the
  controllerObject and its contructor requires the DataAccessObject</p>
  
  <p>I am having problem with mocking the controller / dataaccess pair. The first test i´m trying to run is a GetAllFromDataBase, but i dont really have a clue on how to do it.</p>
  
  <p>EDIT:</p>
  
  <p>I did what Cuong Le told me and the whole is moving now, i really apreciate it. But i stumped into another problem. To access the API, there is a username/password pair and my controller uses Thread.CurrentPrincipal.Identity.Name; right now i would need to set this value for it to fully work I guess.</p>
  
  <p>Also the valueServiceMock.Setup(service => service.GetValues())
              .Returns(new[] { "value1", "value2" }); </p>
  
  <p>does not seem to be working. as the code tries to reach for the database, and gets nothing since it cant get a valid username to look for</p>