I'm creating unit tests, and I'm wanting to create parameterized tests using custom types (like a dto).
I'm wanting to do something like this:
[TestMethod]
[DataRow(new StudentDto { FirstName = "Leo", Age = 22 })]
[DataRow(new StudentDto { FirstName = "John" })]
public void AddStudent_WithMissingFields_ShouldThrowException(StudentDto studentDto) {
// logic to call service and do an assertion
}
- Is this something that you can do? I'm getting an error that says "An Attribute argument must be a constant expression..." I think I saw somewhere that attributes can only take primitive types as arguments?
- Is this the wrong approach? Should I just pass in the properties and create the dto within the test?