I have a class which has a large number of properties each of which returns a double, and a method under test which takes a string, and an instance of the class, and calls one of these properties based on the value of the string (effectively, it calls the property whose name is the string). I am using NUnit, which provides for parameterised testing. I would like to test the method with a set strings, but this means arranging for the specific property call. I am quite close, but I can't quite get it to work.
So far I have the following. A set of test parameters, defined as a Dictionary:
public static Dictionary<string, System.Linq.Expressions.Expression<Func<IMyClass, double>>> SpecialProperties = new Dictionary<string, System.Linq.Expressions.Expression<Func<IMyClass, double>>>()
{
{"InlineLength", x=>x.InLineLength},
{"BranchLength", x=>x.BranchLength},
{"TotalLength", x=>x.TotalLength},
{"CentreLineLength", x=>x.CentreLineLength},
{"SurfaceArea", x=>x.SurfaceArea},
}
Then I have the test method:
[Test]
[TestCaseSource("SpecialProperties")]
public void SpecialProperties_Test(string specialPropertyName, System.Linq.Expressions.Expression<Func<IMyClass, double>> specialProperty)
{
IMyClass mockMyClass = Mock.Create<IMyClass>(Behavior.Strict);
mockMyClass.Arrange(specialProperty).Returns(9.99);
double result = _concreteInstanceOnTest.MethodOnTest(specialPropertyName, mockMyClass);
Assert.AreEqual(9.99, result);
}
This very nearly works, but I get an Inconsistent Accessibility error - Expression<Func<IMyclass, double>> is less accessible than SpecialProperties_Test(). I'm obviously not doing it quite right. Can anybody help?