I would like to change each property on a record in turn and verify the equality function works properly. Instead of writing a test for each property I was hoping to use reflection and xunit theories and the record 'with' syntax to do something like this, like in this post:
[Theory]
[InlineData("Tag", "fake tag")]
[InlineData("Name", "fake name")]
[InlineData("Age", "fake age")]
public void Equality_PropertyChanged(string propertyName, string value)
{
Type myType = typeof(MyRecordType);
PropertyInfo myPropInfo = myType.GetProperty(propertyName);
var different = myRecord with { myPropInfo.SetValue(this, "a different tag", null) };
Assert.NotEqual(m_fake_params, different);
}
I something like this possible?
Aucun commentaire:
Enregistrer un commentaire