title: Xunit - unit test with list or object as parameter
body: <p>I am currently working at the unit tests of my REST API. I have a problem when I have a list or custom object as a parameter.</p>
  
  <p>The first controller method has several parameters including a string List. I don't  know how to add the values in the inline data for the List.</p>
  
  <pre><code>private static List&lt;string&gt; TestData()
  {
      var testcase = new List&lt;string&gt;();
      testcase.Add("DEV");
      testcase.Add("IT");
      return testcase;
  }
  
  [Theory]
  [InlineData(0, 10, TestData, "", 3)]
  public async Task TestGetPersonItems(int pageNumber, int pageSize, List&lt;string&gt; departments, string filterText, int resultCount)
  {
      using (API_DB_Context context = new API_DB_Context(_options))
      {
          // Arrange
          //List&lt;string&gt; departments = new List&lt;string&gt;();
          //departments.Add("DEV");
          List&lt;string&gt; locations = new List&lt;string&gt;();
  
          PersonenController controller = new PersonenController(context, _mapper);
  
          // Act
          var controllerResponse = await controller.Get(pageNumber, pageSize, departments, locations, filterText);
  
          // Assert
          if (resultCount &gt; 0)
          {
              var objectResult = Assert.IsAssignableFrom&lt;ObjectResult&gt;(controllerResponse);
              ICollection&lt;PersonDTO&gt; model = Assert.IsAssignableFrom&lt;ICollection&lt;PersonDTO&gt;&gt;(objectResult.Value);
              Assert.Equal(resultCount, model.Count);
          }
          else
          {
              Assert.IsType&lt;NotFoundObjectResult&gt;(controllerResponse);
              var objectResponse = controllerResponse as ObjectResult;
              Assert.Equal(404, objectResponse.StatusCode);
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <p>For the second controller method I have an custom object and an integer as parameters. When I start test second test, i get the error "Could not find public static member (property, field, or method) named 'SearchData'"</p>
  
  <pre><code>public static IEnumerable&lt;object[]&gt; SearchData()
  {
      yield return new object[] {
          new SearchDTO
          {
            searchText = "",
            page = 0,
            pageSize = 10
          }
      };
  }
  
  [Theory]
  [MemberData(nameof(SearchData), 3)]
  public async Task TestSearchPersonItems(SearchDTO searchDTO, int resultCount)
  {
      using (API_DB_Context context = new API_DB_Context(_options))
      {
          // Arrange
          PersonenController controller = new PersonenController(context, _mapper);
  
          // Act
          var controllerResponse = await controller.SearchPersons(searchDTO);
  
          // Assert
          if (resultCount &gt; 0)
          {
              var objectResult = Assert.IsAssignableFrom&lt;ObjectResult&gt;(controllerResponse);
              ICollection&lt;PersonDTO&gt; model = Assert.IsAssignableFrom&lt;ICollection&lt;PersonDTO&gt;&gt;(objectResult.Value);
              Assert.Equal(resultCount, model.Count);
          }
          else
          {
              Assert.IsType&lt;NotFoundObjectResult&gt;(controllerResponse);
              var objectResponse = controllerResponse as ObjectResult;
              Assert.Equal(404, objectResponse.StatusCode);
          }
      }
  }
  </code></pre>
  
  <p>What do I have to do differently or what can I do better?</p>
  
  <p>Thank you in advance!</p>