title: Arranging Unit Test using Moq
body: <p>I've created a method called <code>ListOfPeople</code> and trying to write a <strong>Unit Test</strong> for it. Currently, I am having trouble setting up the <code>Arrange</code> section of my <strong>Unit Test</strong>. I can't run it right now because my <code>PeopleId</code> and <code>PersonGroupJobId</code> states <code>Cannot resolve symbol</code>. </p>
  
  <blockquote>
    <p><strong>Question:</strong> <em>How can I test this method successfully?</em></p>
  </blockquote>
  
  <p><strong>My Method:</strong></p>
  
  <pre><code>public IEnumerable&lt;Person&gt; ListOfPeople(int personId, int? jobId)
          {
              var people = _unitOfWork.GetRepository&lt;DB.Person&gt;().GetAll()
                .Where(p =&gt; p.PeopleGroups.Any(m =&gt; m.PeopleId == personId 
                                &amp;&amp; m.PersonGroupdJobId == jobId));
  
              if (!people.Any())
                  return new List&lt;Person&gt;();
  
              var personData = people.Select(p =&gt; new Person
              {
                  Id = p.PersonId,
                  Name = p.PersonName,
                  WorkTypeId = p.WorkTypeId,
                  PrimaryLanguage = p.PrimaryLanguage,
                  PeopleGroups = p.PeopleGroups.ToList()
                    .Select(pp =&gt; new PeopleGroup
                    {
                        Id = pp.ProjectPartyId,
                        PeopleId = pp.PeopleId,
                        JobId = pp.PersonGroupJobId ?? 0,
                        AddressId = pp.AddressId
                    })
              }).ToList();
  
              return personData;
          }
  </code></pre>
  
  <p><strong>Unit Test:</strong></p>
  
  <pre><code>[TestMethod]
      public void ListOfPeople_peopleExist_returnsList()
      {
          // Arrange
          var people = new List&lt;DB.Person&gt;
          {    
              PeopleId = It.IsAny&lt;int&gt;(),
              PersonGroupdJobId = It.IsAny&lt;int&gt;()
          }; 
  
          _uowMock
              .Setup(mock =&gt; mock.GetRepository&lt;DB.Person&gt;().GetAll())
              .Returns(people.AsQueryable());
  
          // Act
          var result = _repository.ListOfPeople(It.IsAny&lt;int&gt;(), It.IsAny&lt;int&gt;());
  
          // Assert
          Assert.IsNotNull(result);
          Assert.AreEqual(2, result.Count());
  
          _unitOfWork.Verify(mock =&gt; mock.Commit(), Times.Never());
          _unitOfWork.Verify(mock =&gt; mock.GetRepository&lt;DB.Person&gt;().GetAll(), Times.Once());
      }
  </code></pre>