I am working in a solution that has a large number of tests that follow an Arrange/Act/Assert pattern. All of the test data is arranged as object initializers, similar to the following:
var animal = new Animal
{
Id = 10,
Name = "Skippy",
BirthDate = new DateTime(2020, 01, 05),
};
// Assertions (fluent assertions)
animal.Name.Should().....
Per the client's request, I need to take these tests and manipulate the data (e.g., change all the Animal names and Birth Dates). Some options I thought up:
- Use regex to modify the data in place (the data is not always well formed, so pattern matching will be hard)
- Read the data into memory, modify the data in memory, and serialize the data back out to replace the original C# test file data (not sure how to do this replacement)
- Similar to option 2, except redirect the serialized data to a file/etc and then modify the test to read that serialized data file.
Due to the complex nature of the data, I am thinking that option 3 is the most straight forward option. However, I am also trying to keep the data relatively easy to modify going forward. The object initializers that are used now offer great flexibility and ease of use, and are familiar to the development team, so I would like to keep those if possible.
Does anyone know of a library/etc that will read C# formatted object initializers back into an object of a given type? So the usage would be something like:
var animal = _objectReader.Read<Animal>("path_to_test_data");
Aucun commentaire:
Enregistrer un commentaire