Q:

Is there any way of testing similar properties?

Let's assume I have a class with some similar properties:
public string First { get; set; }
public string Second { get; set; }
public string Third { get; set; }

I want to test them in the same way in my tests... So I write:
[Test]
public void TestFirst()
{
    // Asserting strings here
}

Is there a way to avoid creating three Tests (one for First, one for Second and one for Third)?
I'm looking for something like [Values(First, Second, Third)], so i can then write one test that will iterate through the properties.
Cheers, and thanks in advance :)

A:

Thanks all for your answers and help. Learned plenty of things.
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).
[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) &&
                        prop.CanWrite && prop.CanRead
                      select prop).ToList();

    string_props.ForEach(p =>{
                                 // 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));
                             }
        );
}

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 :)
Any comments on this solution will be welcomed.

