Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks all for your answers and help. Learned plenty of things.</p> <p>Here's what I've ended up doing. I've used reflection to get all the string properties, and then set to a value, check value is set, set to null, check to see it returns an empty string (logic in property's getter).</p> <pre><code>[Test] public void Test_AllStringProperties() { // Linq query to get a list containing all string properties var string_props= (from prop in bkvm.GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance) where prop.PropertyType == typeof(string) &amp;&amp; prop.CanWrite &amp;&amp; prop.CanRead select prop).ToList(); string_props.ForEach(p =&gt;{ // Set value of property to a different string string set_val = string.Format("Setting [{0}] to: \"Testing string\".", p.Name); p.SetValue(bkvm, "Testing string", null); Debug.WriteLine(set_val); // Assert it was set correctly Assert.AreEqual("Testing string", p.GetValue(bkvm, null)); // Set property to null p.SetValue(bkvm,null,null); set_val = string.Format("Setting [{0}] to null. Should yield an empty string.", p.Name); Debug.WriteLine(set_val); // Assert it returns an empty string. Assert.AreEqual(string.Empty,p.GetValue(bkvm, null)); } ); } </code></pre> <p>This way I don't need to be concerned if someone adds a property, since it'll be checked automatically, without me needing to update the test code (as you might guess, not everybody updates nor writes tests :)</p> <p>Any comments on this solution will be welcomed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload