Skip to content

Commit

Permalink
Merge b3a5812 into 3300981
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstebo committed Oct 13, 2018
2 parents 3300981 + b3a5812 commit add1125
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/FakerDotNet/Fakers/FakeFaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ public string F(string format)

private PropertyInfo GetFaker(string name)
{
var propertyInfo = _fakerContainer.GetType().GetProperty(name);
var propertyInfo = _fakerContainer.GetType()
.GetProperty(name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);

return propertyInfo ?? throw new FormatException($"Invalid module: {name}");
}

private string GetValue(PropertyInfo propertyInfo, string methodName)
{
var method = propertyInfo.PropertyType.GetMethod(methodName);
var method = propertyInfo.PropertyType
.GetMethod(methodName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);

if (method == null) throw new FormatException($"Invalid method: {propertyInfo.Name}.{methodName}");

Expand All @@ -60,4 +62,4 @@ private static (string faker, string method) ExtractMatchDataFrom(Match match)
return (className, methodName);
}
}
}
}
13 changes: 12 additions & 1 deletion tests/FakerDotNet.Tests/Fakers/FakeFakerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ public void F_returns_filled_in_string()
Assert.AreEqual("John Smith", _fakeFaker.F(format));
}

[Test]
public void F_is_not_case_sensitive()
{
const string format = "{Name.firstName} {name.lastname}";

A.CallTo(() => _fakerContainer.Name.FirstName()).Returns("John");
A.CallTo(() => _fakerContainer.Name.LastName()).Returns("Smith");

Assert.AreEqual("John Smith", _fakeFaker.F(format));
}

[Test]
public void F_with_empty_string_throws_FormatException()
{
Expand Down Expand Up @@ -78,4 +89,4 @@ public void F_with_null_throws_FormatException()
Assert.AreEqual("A string must be specified", ex.Message);
}
}
}
}

0 comments on commit add1125

Please sign in to comment.