public void SetValue(Type type, string name, object obj, object value, object[] index, object expected)
{
PropertyInfo PropertyInfo = GetProperty(type, name);
object originalValue;
if (index == null)
{
// Use SetValue(object, object)
originalValue = PropertyInfo.GetValue(obj);
try
{
PropertyInfo.SetValue(obj, value);
Assert.Equal(expected, PropertyInfo.GetValue(obj));
}
finally
{
PropertyInfo.SetValue(obj, originalValue);
}
}
// Use SetValue(object, object, object[])
originalValue = PropertyInfo.GetValue(obj, index);
try
{
PropertyInfo.SetValue(obj, value, index);
Assert.Equal(expected, PropertyInfo.GetValue(obj, index));
}
finally
{
PropertyInfo.SetValue(obj, originalValue, index);
}
}