Faking Files - baileydauterman/Faker.NET GitHub Wiki
CsvMapAttribute
Properties:
- DisplayName - This will be the header of the field when generating the csv
- Property - This is the interface type that the
Field
value will come from - Field - This is the field on the
Faker.{Property}
that will be called through reflection.
public IEnumerable<string> GenerateTypeCsv()
{
var csvFaker = new CsvFaker().Iterations(100);
return csvFaker.Generate<FakeClass>(); // this will return 1 header row and 100 data rows
}
public class FakeClass
{
[FakerPersonFirstName]
public string Name { get; set; } = string.Empty;
[FakerPersonLastName]
public string Last { get; set; } = string.Empty;
[FakerInternetIPv4]
public string IPAddress { get; set; } = string.Empty;
}
Json file faking takes in a type of <T>
and Fun<T>
that will create the fake data that will be output to the json.
new JsonFaker()
.AddField<KeyValuePair<string, object>>(() => CreateNameNode("name", Faker.Person.FirstName()))
.AddField<SomeValue>(SomeValue.SetTestValues)
.AddField<AnotherValue>(AnotherValue.SetTestValues)
.AddField<DoubleNested>(DoubleNested.SetTestValues);