Xunit 2.3.0 Unable to pass dates as inline params

You can make it explicit with MemberDataAttribute :-

public static readonly object[][] CorrectData =
{
  new object[] { "title 1", "testing 1", 1, "Educational", 
                  new DateTime(2017,3,1), new DateTime(2018,12,31)},
  new object[] { "title 2", "testing 2", 2, "Self Employment", 
                  new DateTime(2017, 2, 1), new DateTime(2018, 2, 28)}
};
      
[Theory, MemberData(nameof(CorrectData))]
public async Task WhenPassingCorrectData_SuccessfullyCreate(string title, 
                                             string description, 
                                             int categoryId, 
                                             string category, 
                                             DateTime startDate, 
                                             DateTime endDate)
{

}

(You can also make the property return IEnumerable<object[]>, which you’d typically do with yield return enumerator syntax, but I believe the above is the most legible syntax C# has to offer for it at present)

Leave a Comment