Permalink
Browse files

Adding support for externally supplied resource files

- added method to configure data
- added file-reading method in `ResourceLoader`
- added test and test data file
  • Loading branch information...
MisterJames committed Nov 27, 2015
1 parent 85a7c38 commit e44ac82e03a1f1c6640471794f1b4de7959c21cd
View
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
@@ -62,7 +62,19 @@ public GenFuConfigurator Fill<T>(string propertyName, Func<T> filler)
_fillerManager.RegisterFiller(customFiller);
return this;
}
/// <summary>
/// Replaces the well-known property with a user-supplied list of values loaded from the specified file
/// </summary>
/// <param name="propertyType">The property for which you wish to supply values</typeparam>
/// <param name="filename">A value-per-line file with values for the property</typeparam>
/// <returns>A configurator for the target object type</returns>
public GenFuConfigurator Data(Properties propertyType, string filename)
{
ResourceLoader.ReplacePropertyData(propertyType, filename);
return this;
}
public GenFu GenFu
{
get { return _genfu; }
@@ -91,5 +91,13 @@ private static List<string> LoadStrings(string resourceName)
}
public static void ReplacePropertyData(Properties propertyType, string filename)
{
if (File.Exists(filename))
{
var values = File.ReadLines(filename).ToList();
_data[propertyType] = values;
}
}
}
}
@@ -93,5 +93,13 @@ public void UsaStatesResourceTest()
Assert.NotEqual(string.Empty, city);
}
[Fact]
public void UseSuppliedResourceDataTest()
{
GenFu.Configure().Data(Properties.FirstNames, @"testdata\singlename.txt");
var people = A.ListOf<Person>(25);
Assert.Equal(25, people.Where(p=>p.FirstName == "Angela").Count());
}
}
}
@@ -0,0 +1 @@
Angela

0 comments on commit e44ac82

Please sign in to comment.