title: How to unit test a class using moq that has dependencies within a method?
body: <p>I want to unit test a class <code>AuthClient</code> (using <code>Moq</code>) which authenticates a user. </p>
  
  <p>Problem is that my <code>AuthenticationService</code> dependency is not injected in the class. And I am a bit confused at how I would test the flow without injecting the dependencies.</p>
  
  <pre><code>[TestClass] 
  public class AuthClient 
  {
      string Dictionary&lt;string, IList&lt;UserPermissions&gt; _userPermissions;
  
      User Login(string username, string password)
      {
          IAuthenticationService authenticationService = new AuthenticationService();
          User user = authService.Login(username, password);
  
          IAuthorizationService authorizationService = new AuthorizationService();
          var permissions = authorizationService.GetPermissions(user);
          _userPermissions.Add(user.Username, permissions);
  
          return user;
      }
  }
  </code></pre>
  
  <p>My current unit testing code looks like:</p>
  
  <pre><code>public class UnitTestClass
  {
      public string UserName {get;set;}
      public string Password {get;set;}
  
      [TestInitialize]
      public void Setup() 
      {
          UserName = "test";
          Password = "test123";
      }
  
      [TestMethod]
      public void When_ValidUserCredentials_Expect_UserIsNotNull()
      {
          var mockAuthenticationService = new Mock&lt;IAuthenticateService&gt;();
          mockAuthenticationService.Setup(m =&gt; m.Login(ValidUserName, ValidPassword)).Returns(ValidUserDto);
  
          var mockAuthorizationService = new Mock&lt;IAuthorizeService&gt;();
          mockAuthorizationService.Setup(m =&gt; m.GetAllPermissions(ValidUserId)).Returns(ValidPermissionList);
  
          var authClient = new Mock&lt;AuthClient&gt;();
          // I want to use mock dependencies here to test flow against mock data
          User user = authClient.Login(UserName, Password); 
  
          Assert.IsNotNull(user);
      }
  }
  </code></pre>
  
  <p>Any ideas where everything went wrong?</p>