I'm developing some test methods in C# that validate database records are updated correctly after UI changes are made to various records.
In doing so, I've developed a method that returns a SQL query string that I then serialize into a JSON string. With this string, I am writing it to a temporary file and then comparing it to a baseline expected file to then validate that the update is correct.
The issue is that the tables that I pull from are very extensive and have many columns, some of which will diff every time due to values like date created, last date updated, or anything similar.
Question:
Given a simple JSON string like so (my actual strings are far larger):
[
{
"id": 1,
"name": "A green door",
"price": 12.50,
"home": "Penn"
"date": "April 4, 2015"
}
]
Is there any simple way to mask all "date" values with any specified value that would then cause the return to look like:
[
{
"id": 1,
"name": "A green door",
"price": 12.50,
"home": "Penn"
"date": "MASKEDVALUE"
}
]
If any more information is needed for clarification please let me know.
Serialization code:
public string ReturnQueryAsJson(string statement)
{
var dataTable = new DataTable();
var configManager = new ConfigurationManager();
var connectionString = configManager.AppSettings["DatabaseConnectionString"];
string query = statement;
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(query, connection);
connection.Open();
SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
dataAdapter.Fill(dataTable);
connection.Close();
dataAdapter.Dispose();
JsonConvert.SerializeObject(dataTable);
string JsonResult;
JsonResult = JsonConvert.SerializeObject(dataTable, Formatting.Indented);
return JsonResult;
}