Skip to content

Commit

Permalink
adding override for GetData issue #32
Browse files Browse the repository at this point in the history
  • Loading branch information
ipjohnson committed Apr 5, 2018
1 parent 2c4b856 commit 8f4c72f
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/SimpleFixture/Attributes/AttributeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static IEnumerable<T> GetAttributes<T>(ParameterInfo parameterInfo) where
/// <param name="parameterInfo"></param>
/// <returns></returns>
public static object[] GetData(ParameterInfo parameterInfo)
{
{
var fixture = CreateFixture(parameterInfo);

var value = GetValueForParameter(parameterInfo.Member as MethodInfo, parameterInfo, fixture,
Expand All @@ -123,6 +123,18 @@ public static object[] GetData(ParameterInfo parameterInfo)
public static object[] GetData(MethodInfo testMethod, object[] parameters)
{
var fixture = CreateFixture(testMethod);

return GetData(fixture, testMethod, parameters);
}

/// <summary>Returns the data to be used to test the theory.</summary>
/// <param name="fixture"></param>
/// <param name="testMethod">The method that is being tested</param>
/// <param name="parameters"></param>
/// <returns>One or more sets of theory data. Each invocation of the test method
/// is represented by a single object array.</returns>
public static object[] GetData(Fixture fixture, MethodInfo testMethod, object[] parameters)
{
var returnParameters = new List<object>();
var externalParameters = new List<object>(parameters);

Expand All @@ -144,7 +156,7 @@ public static object[] GetData(MethodInfo testMethod, object[] parameters)
/// <param name="fixture"></param>
/// <param name="externalParameters"></param>
/// <returns></returns>
private static object GetValueForParameter(MethodInfo testMethod, ParameterInfo parameter,
private static object GetValueForParameter(MethodInfo testMethod, ParameterInfo parameter,
Fixture fixture, List<object> externalParameters)
{
if (parameter.ParameterType == typeof(Fixture))
Expand Down Expand Up @@ -180,14 +192,14 @@ private static object GetValueForParameter(MethodInfo testMethod, ParameterInfo
}
else if (attribute is LocateAttribute)
{
var locateAttribute = (LocateAttribute) attribute;
var locateAttribute = (LocateAttribute)attribute;

parameterValue = LocateValue(fixture, parameter, locateAttribute);
found = true;
}
else if (attribute is GenerateAttribute)
{
var generateAttribute = (GenerateAttribute) attribute;
var generateAttribute = (GenerateAttribute)attribute;

parameterValue = GenerateValue(fixture, parameter, generateAttribute);
found = true;
Expand Down Expand Up @@ -215,7 +227,7 @@ private static object GetValueForParameter(MethodInfo testMethod, ParameterInfo
else if (externalParameters[0] is Type &&
parameter.ParameterType.GetTypeInfo().IsAssignableFrom(((Type)externalParameters[0]).GetTypeInfo()))
{
var locateType = (Type) externalParameters[0];
var locateType = (Type)externalParameters[0];
externalParameters.RemoveAt(0);
found = true;
parameterValue =
Expand All @@ -234,7 +246,7 @@ private static object GetValueForParameter(MethodInfo testMethod, ParameterInfo

return parameterValue;
}


/// <summary>
/// Generate value for parameter
Expand Down

0 comments on commit 8f4c72f

Please sign in to comment.